diff --git a/admin/controllers/app/licheb/Userslog.php b/admin/controllers/app/licheb/Userslog.php
index 770f7a83..fe9da23c 100644
--- a/admin/controllers/app/licheb/Userslog.php
+++ b/admin/controllers/app/licheb/Userslog.php
@@ -96,7 +96,7 @@ class Userslog extends HD_Controller
$map_biz[$v['biz_id']]['type'] && $biz_type = $typeAry[$map_biz[$v['biz_id']]['type']];
$temp = ['uname' => $uname, 'biz_type' => $biz_type, 'biz_name' => $biz_name, 'defeats' => $v['defeats']
, 'a_num' => $v['a_num'], 'orders' => $v['orders'], 'bills' => $v['bills'], 'follows' => $v['follows']
- , 'log_date' => $v['log_date']];
+ , 'qy_adds' => $v['qy_adds'], 'qy_dels' => $v['qy_dels'], 'log_date' => $v['log_date']];
$customer_json = $v['customer_json'] ? json_decode($v['customer_json'], true) : [];
foreach ($offlineSources as $key1 => $value1) {
$nums = intval($v['customer_' . $key1]);
@@ -174,6 +174,8 @@ class Userslog extends HD_Controller
$indexs['orders'] = '订单数';
$indexs['defeats'] = '战败数';
$indexs['bills'] = '开票数';
+ $indexs['qy_adds'] = '新增企微';
+ $indexs['qy_dels'] = '删除企微';
$indexs['log_date'] = '日期';
array_unshift($data, $indexs);
$this->load->library('excel');
diff --git a/admin/views/app/licheb/userslog/lists.php b/admin/views/app/licheb/userslog/lists.php
index df157566..ba29e71f 100644
--- a/admin/views/app/licheb/userslog/lists.php
+++ b/admin/views/app/licheb/userslog/lists.php
@@ -87,6 +87,8 @@
订单数 |
战败数 |
开票数 |
+ 新增企微 |
+ 删除企微 |
日期 |
@@ -102,6 +104,8 @@
= $v['orders'] ?> |
= $v['defeats'] ?> |
= $v['bills'] ?> |
+ = $v['qy_adds'] ?> |
+ = $v['qy_dels'] ?> |
= $v['log_date'] ?> |
}
diff --git a/api/controllers/plan/Licheb.php b/api/controllers/plan/Licheb.php
index 6bf4745b..364ede56 100644
--- a/api/controllers/plan/Licheb.php
+++ b/api/controllers/plan/Licheb.php
@@ -53,13 +53,14 @@ class Licheb extends HD_Controller
!$id && $id = 0;
$log = [];
$where = ['id >' => $id, 'group_id < 4' => null, 'status' => 1];
- $res = $this->mdUsers->select($where, 'id asc', 1, $size, 'id,biz_id');
+ $res = $this->mdUsers->select($where, 'id asc', 1, $size, 'id,biz_id,userid');
if (!$res) {
echo '执行到当前顾问id:' . $id . '暂无数据';
return;
}
$this->load->model('receiver/receiver_customer_oplogs_model', 'mdCustomerOpLogs');
$this->load->model('receiver/order/receiver_orders_v2_model', 'mdOrdersV2');
+ $this->load->model('app/app_lichene_qy_log_model', 'mdWechatqyLog');
$this->load->model("biz/biz_model", 'mdBiz');
$offlineSources = $this->mdCustomers->offlineSources();
$str_biz_ids = implode(',', array_unique(array_column($res, 'biz_id')));
@@ -89,8 +90,16 @@ class Licheb extends HD_Controller
$bills = $this->mdOrdersV2->count(['sale_id' => $sale_id, 'biz_id' => $biz_id, 'status>=' => 0,
'bill_time>=' => "{$log_date} 00:00:00", 'bill_time<=' => "{$log_date} 23:59:59"]
);
+ $qy_adds = $qy_dels = 0;
+ if ($value['userid']) {
+ $qy_adds = $this->mdWechatqyLog->count(['userid' => $value['userid'], 'change_type' => 'add_external_contact'
+ , 'c_time>=' => $s_time, 'c_time<=' => $e_time]);
+ $qy_dels = $this->mdWechatqyLog->count(['userid' => $value['userid'], "change_type in('del_external_contact','del_follow_user')" => null
+ , 'c_time>=' => $s_time, 'c_time<=' => $e_time]);
+ }
$add_item = ['sale_id' => $sale_id, 'biz_id' => $biz_id, 'type' => $type, 'city_id' => $city_id, 'a_num' => $a_num
- , 'orders' => $orders, 'bills' => $bills, 'follows' => $follows, 'defeats' => $defeats, 'log_date' => $log_date, 'c_time' => time()];
+ , 'orders' => $orders, 'bills' => $bills, 'follows' => $follows, 'defeats' => $defeats, 'log_date' => $log_date
+ , 'qy_adds' => $qy_adds, 'qy_dels' => $qy_dels, 'c_time' => time()];
$customer_json = '';
foreach ($offlineSources as $key1 => $value1) {
$customer_num1 = $this->mdCustomers->count(['of_id' => $key1, 'admin_id' => $sale_id
diff --git a/api/controllers/wechat/Lichene.php b/api/controllers/wechat/Lichene.php
index b464ef07..aee9082d 100644
--- a/api/controllers/wechat/Lichene.php
+++ b/api/controllers/wechat/Lichene.php
@@ -31,7 +31,8 @@ Class Lichene extends HD_Controller
public function temp()
{
$this->load->library('wx_qyapi', ['app' => 'lichene']);
- $re_wx = $this->wx_qyapi->getSignPackage();
+ // $re_wx = $this->wx_qyapi->getSignPackage();
+ $re_wx = $this->wx_qyapi->get_external_contact(array('url' => 'user_get', 'userid' => 'LiuXinXin_2'));
echo json_encode($re_wx, JSON_UNESCAPED_UNICODE);
}
@@ -44,6 +45,72 @@ Class Lichene extends HD_Controller
* Created by: dengbw
*/
public function get_qymsg()
+ {
+ $param = $this->input->get();
+ require_once(COMMPATH . '/third_party/WXqy/WXBizMsgCrypt.php');
+ $encodingAesKey = "CXUVlU9C7KsxzglxRiMlMsG2WSqM4EkFufDvgjkFciU";
+ $token = "CEoJkwUFP58KfZJ";
+ $corpId = "wwff2d727ce47d6852";
+ $sVerifyMsgSig = $param['msg_signature'];
+ $sVerifyTimeStamp = $param['timestamp'];
+ $sVerifyNonce = $param['nonce'];
+ $sVerifyEchoStr = $param['echostr'];
+ // 需要返回的明文
+ $sEchoStr = "";
+ $wxcpt = new WXBizMsgCrypt($token, $encodingAesKey, $corpId);
+ if ($sVerifyEchoStr) {//验证回调URL
+ $errCode = $wxcpt->VerifyURL($sVerifyMsgSig, $sVerifyTimeStamp, $sVerifyNonce, $sVerifyEchoStr, $sEchoStr);
+ debug_log('qymsg_errCode:' . $errCode, $this->log_file);
+ if ($errCode == 0) {
+ // 验证URL成功,将sEchoStr返回
+ echo urldecode($sEchoStr);
+ } else {
+ echo $errCode;
+ }
+ exit;
+ }
+ if ($_SERVER['REQUEST_METHOD'] == "POST") {
+ $sReqData = file_get_contents("php://input");
+ $sMsg = ""; // 解析之后的明文
+ $errCode = $wxcpt->DecryptMsg($sVerifyMsgSig, $sVerifyTimeStamp, $sVerifyNonce, $sReqData, $sMsg);
+ if ($errCode == 0) {
+ $this->load->model('app/app_lichene_qy_log_model', 'mdWechatqyLog');
+ $re_msg = (array)simplexml_load_string($sMsg, 'SimpleXMLElement', LIBXML_NOCDATA);//xml转json
+ if ($re_msg['ChangeType']) {
+ $change_type = $this->mdWechatqyLog->change_type($re_msg['ChangeType']);
+ $userid = $re_msg['UserID'];
+ if ($change_type && $userid) {//只记录现有的
+ $this->load->model('app/licheb/App_licheb_users_model', 'mdUsers');
+ $re_use = $this->mdUsers->get(['userid' => $userid]);
+ if (!$re_use) {//企业成员关连狸车宝用户
+ $this->load->library('wx_qyapi', ['app' => 'lichene']);
+ $re_wx = $this->wx_qyapi->get_external_contact(array('url' => 'user_get', 'userid' => $userid));
+ if ($re_wx['errcode'] == 0 && $re_wx['mobile']) {//获取企业成员手机
+ $re_use = $this->mdUsers->get(array('mobile' => $re_wx['mobile']));
+ if ($re_use) {//userid与手机绑定关连
+ $this->mdUsers->update(['userid' => $userid], ['id' => $re_use['id']]);
+ }
+ }
+ }
+ $re_msg['log_id'] = $this->mdWechatqyLog->add(['external_userid' => $re_msg['ExternalUserID'], 'userid' => $userid,
+ 'change_type' => $re_msg['ChangeType'], 'remark' => $change_type, 'c_time' => $re_msg['CreateTime']]);
+ }
+ }
+ debug_log('qymsg_sMsg:' . json_encode($re_msg, JSON_UNESCAPED_UNICODE), $this->log_file);
+ exit;
+ }
+ }
+ }
+
+ /**
+ * Notes:企业微信接收事件
+ * https://liche-api-dev.xiaoyu.com/wechat/lichene/get_qymsg
+ * https://api.liche.cn/wechat/lichene/get_qymsg
+ * https://open.work.weixin.qq.com/wwopen/devtool/interface?doc_id=14961 测试回调模式
+ * Created on: 2022/3/23 17:23
+ * Created by: dengbw
+ */
+ public function get_qymsg2()
{
$param = $this->input->get();
debug_log('
--->qymsg_param:' . json_encode($param), $this->log_file);
diff --git a/common/models/app/App_lichene_qy_log_model.php b/common/models/app/App_lichene_qy_log_model.php
new file mode 100644
index 00000000..8ee45b23
--- /dev/null
+++ b/common/models/app/App_lichene_qy_log_model.php
@@ -0,0 +1,31 @@
+table_name, 'default');
+ }
+
+ /**
+ * Notes:操作类型
+ * Created on: 2022/4/21 17:52
+ * Created by: dengbw
+ * @param string $type
+ * @return array|mixed
+ */
+ public function change_type($type = '')
+ {
+ $ary = ['add_external_contact' => '添加企业客户', 'edit_external_contact' => '编辑企业客户'
+ , 'del_external_contact' => '删除企业客户', 'del_follow_user' => '删除跟进成员'];
+ return $type ? $ary[$type] : $ary;
+ }
+}