different_628

This commit is contained in:
dengbw
2022-06-28 16:46:32 +08:00
parent 710b4fc73e
commit 0d90a41dd1
13 changed files with 511 additions and 115 deletions
+11 -2
View File
@@ -286,7 +286,14 @@ class Customer extends HD_Controller
$of_title = $of_ary['name'];
$row['of2_id'] && $of_title .= '-' . $of_ary['list'][$row['of2_id']];
}
$tag = $tag_group = [];
$biz_type = intval($row_biz['type']);
if ($biz_type == 5) {
$jsondata = $row['jsondata'] ? json_decode($row['jsondata'], true) : [];
$jsondata['tag_group'] && $tag_group = $jsondata['tag_group'];
} else {
$tag = $this->get_tag($row['id']);
}
$info = array(
'id' => $row['id'],
'name' => $row['name'],
@@ -296,7 +303,9 @@ class Customer extends HD_Controller
'cf_user' => $cf_user,
'c_time' => date('Y-m-d H:i:s', $row['c_time']),
'status' => $row['status'],
'tag' => $this->get_tag($row['id']),
'tag' => $tag,
'tag_group' => $tag_group,
'biz_type' => $biz_type,
);
//到店信息
+14 -2
View File
@@ -122,12 +122,24 @@
<span href="javascript:void(0)" style="font-size: 20px">
用户画像
</span>
<span style="float:right;margin-top:5px;">
<span style="float:right;margin-top:5px;" v-if="info.biz_type!=5">
<a href="javascript:" @click="editType(3)"><i class="fa fa-edit"></i></a>
</span>
</div>
<div class="am-panel-bd am-g">
<table width="100%" style="margin-left: 10px;margin-right: 10px;">
<table v-if="info.biz_type==5" width="100%" style="margin-left: 10px;margin-right: 10px;">
<tr template v-for="(v,i) in info.tag_group">
<td class="table-td" style="width: 80%">
{{v.name}}:
<template v-for="(v2,i2) in v.tag">
<button class="am-btn am-btn-sm am-btn-default ml5">
{{v2}}
</button>
</template>
</td>
</tr>
</table>
<table v-else width="100%" style="margin-left: 10px;margin-right: 10px;">
<template v-for="(v,i) in info.tag">
<tr>
<td class="table-td" style="width: 80%">
+9 -4
View File
@@ -218,6 +218,7 @@ class Licheb extends HD_Controller
$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('app/app_different_qy_log_model', 'mdDifferentQyLog');
$this->load->model("biz/biz_model", 'mdBiz');
$offlineSources = $this->mdCustomers->offlineSources();
$str_biz_ids = implode(',', array_unique(array_column($res, 'biz_id')));
@@ -256,10 +257,14 @@ class Licheb extends HD_Controller
);
$qy_adds = $qy_dels = $customers = 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]);
$qy_where = ['userid' => $value['userid'], 'c_time>=' => $s_time, 'c_time<=' => $e_time];
if ($type == 5) {
$qy_adds = $this->mdDifferentQyLog->count(array_merge($qy_where, ['change_type' => 'add_external_contact']));
$qy_dels = $this->mdDifferentQyLog->count(array_merge($qy_where, ["change_type in('del_external_contact','del_follow_user')" => null]));
} else {
$qy_adds = $this->mdWechatqyLog->count(array_merge($qy_where, ['change_type' => 'add_external_contact']));
$qy_dels = $this->mdWechatqyLog->count(array_merge($qy_where, ["change_type in('del_external_contact','del_follow_user')" => null]));
}
}
$add_item = ['sale_id' => $sale_id, 'biz_id' => $biz_id, 'type' => $type, 'city_id' => $city_id, 'c_num' => $c_num
, 'a_num' => $a_num, 't_num' => $t_num, 'orders' => $orders, 'bills' => $bills, 'follows' => $follows, 'defeats' => $defeats
+328
View File
@@ -0,0 +1,328 @@
<?php
ini_set('display_errors', 'on');
/**
* Notes:异业店企微
* Created on: 2022/6/28 16:56
* Created by: dengbw
*/
Class Different extends HD_Controller
{
private $bid;
public function __construct()
{
parent::__construct();
$bid = $this->input->get('bid') ? $this->input->get('bid') : $this->input->post('bid');
$this->bid = intval($bid);
if ($this->bid == 133) {
$this->load->library('wx_qyapi', ['app' => "diff_{$bid}"]);
} else {
echo '参数错误~';
exit;
}
$target_class = lcfirst(get_class($this));//调用类的名称,子类或者当前类名称
$this->log_file = "wechat_{$target_class}_{$this->bid}.log";
}
public function index()
{
echo 'index';
}
/**
* Notes:
* https://liche-api-dev.xiaoyu.com/wechat/different/temp?bid=133
* https://api.liche.cn/wechat/different/temp?bid=133
* Created on: 2022/3/25 17:37
* Created by: dengbw
*/
public function temp()
{
$param = $this->input->get();
// $re_wx = $this->wx_qyapi->getSignPackage();
if ($param) {
$re_wx = $this->wx_qyapi->get_external_contact($param);
echo json_encode($re_wx, JSON_UNESCAPED_UNICODE);
}
}
/**
* Notes:企业微信接收事件
* https://liche-api-dev.xiaoyu.com/wechat/different/get_qymsg?bid=133
* https://api.liche.cn/wechat/different/get_qymsg?bid=133
* 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_qymsg()
{
$param = $this->input->get();
require_once(COMMPATH . '/third_party/WXqy/WXBizMsgCrypt.php');
$config = $this->wx_qyapi->getConfig();
$sVerifyMsgSig = $param['msg_signature'];
$sVerifyTimeStamp = $param['timestamp'];
$sVerifyNonce = $param['nonce'];
$sVerifyEchoStr = $param['echostr'];
// 需要返回的明文
$sEchoStr = "";
$wxcpt = new WXBizMsgCrypt($config['token'], $config['encodingAesKey'], $config['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_different_qy_log_model', 'mdWechatqyLog');
$re_msg = (array)simplexml_load_string($sMsg, 'SimpleXMLElement', LIBXML_NOCDATA);//xml转json
$qy_user = [];
if ($re_msg['ChangeType']) {
$change_type = $this->mdWechatqyLog->change_type($re_msg['ChangeType']);
$userid = $re_msg['UserID'];
$external_userid = $re_msg['ExternalUserID'];
if ($change_type) {//只记录现有的
if ($userid) {//企业成员
$re_msg['log_id'] = $this->mdWechatqyLog->add(['brand_id' => $this->bid, 'external_userid' => $external_userid, 'userid' => $userid,
'change_type' => $re_msg['ChangeType'], 'remark' => $change_type, 'c_time' => $re_msg['CreateTime']]);
$wxqy = 0;
if ($re_msg['ChangeType'] == 'add_external_contact') {//新增
$wxqy = 1;
} else if ($re_msg['ChangeType'] == 'del_external_contact' || $re_msg['ChangeType'] == 'del_follow_user') {//删除
$wxqy = -1;
}
if ($wxqy && $external_userid) {//查找关连企微客户
$this->load->model('app/licheb/App_licheb_users_model', 'mdUsers');
$re_use = $this->mdUsers->get(['userid' => $userid]);
$biz_id = $re_use ? intval($re_use['biz_id']) : 0;
if ($biz_id) {
$re_wx = $this->wx_qyapi->get_external_contact(array('url' => 'get', 'external_userid' => $external_userid));
if ($re_wx['errcode'] == 0) {
$qy_user['external_contact'] = $re_wx['external_contact'];
$remark_mobiles = '';
foreach ($re_wx['follow_user'] as $key => $val) {
if ($val['userid'] == $userid) {//找出当前企业员工
$remark_mobiles = $val['remark_mobiles'];//用户手机
$qy_user['follow_info'] = $val;
break;
}
}
if ($remark_mobiles && $remark_mobiles != '[]' && is_array($remark_mobiles)) {
$mobile = $remark_mobiles[0];//取第一个手机号
if ($mobile) {//关连客户企微状态
$this->load->model('receiver/receiver_customers_model', 'mdCustomers');
$ret = $this->mdCustomers->update(['wxqy' => $wxqy], ['mobile' => $mobile, 'biz_id' => $biz_id]);
$ret && $re_msg['wxqy'] = $wxqy . '_' . $mobile . '_' . $biz_id;
}
}
}
}
}
}
}
if ($re_msg['ChangeType'] == 'add_external_contact') {//添加企业客户
if (!$qy_user) {
$re_wx = $this->wx_qyapi->get_external_contact(array('url' => 'get', 'external_userid' => $external_userid));
if ($re_wx['errcode'] == 0) {
$qy_user['external_contact'] = $re_wx['external_contact'];
foreach ($re_wx['follow_user'] as $key => $val) {
if ($val['userid'] == $userid) {//找出当前企业员工
$qy_user['follow_info'] = $val;
break;
}
}
}
}
if ($qy_user) {
$this->load->model('app/app_different_qy_model', 'mdWechatqy');
$this->set_wechatqy(['userid' => $userid, 'external_userid' => $external_userid], $qy_user);
}
}
}
debug_log('qymsg_sMsg:' . json_encode($re_msg, JSON_UNESCAPED_UNICODE), $this->log_file);
exit;
}
}
}
/**
* Notes:临时更新用户客户id
* Created on: 2021/03/01 17:02
* Created by: dengbw
* https://liche-api-dev.xiaoyu.com/wechat/different/tem_external_contact
* https://api.liche.cn/wechat/different/tem_external_contact
*/
public function tem_external_contact()
{
$this->load->model('app/app_different_qy_model', 'mdWechatqy');
$this->load->library('wx_qyapi', ['app' => 'different']);
echo 'access_token=' . $this->wx_qyapi->access_token() . '<br>';
$param = $this->input->get();
$param['page'] = intval($param['page']);
//获取配置了客户联系功能的成员列表
// $re = $this->wx_qyapi->get_external_contact(array('url' => 'get_follow_user_list'));
// echo json_encode($re, JSON_UNESCAPED_UNICODE);
// exit;
//读取成员
$re = $this->wx_qyapi->get_external_contact(array('url' => 'user_get', 'userid' => 'DengBingWen'));
echo json_encode($re, JSON_UNESCAPED_UNICODE);
exit;
//获取客户详情
// $re = $this->wx_qyapi->get_external_contact(array('url' => 'get', 'external_userid' => 'wm2x4YKwAAqdNIMj9eOt1LXroR6cn-NQ'));
// echo json_encode($re, JSON_UNESCAPED_UNICODE);
exit;
//用户分页分别获取避免超时
// $userid = "DianCheDaRenXiaoLi";
// if ($param['next_cursor'] || !$param['page']) {
// $next_cursor = $this->get_by_user($userid, $param['next_cursor']);
// header('refresh:3;url=/wechat/liche/tem_external_contact?next_cursor=' . $next_cursor . '&page=' . ($param['page'] + 1));
// } else {
// echo '跑数据结束=' . $userid;
// }
// exit;
ob_start(); //打开缓冲区
$follow_user = ["LiLiXiang", "ChenZongHui", "FangYanPing", "JiangYaLi", "DianCheDaRen", "LinFan", "ChenHuiCan01", "13507568055"
, "LiuXinXin_2", "caohui", "HuJianPing", "LiuChaHua", "GuoYangYang", "ZhengYongWei", "WangWei", "LiJianJie", "YuWei", "ChenYuYou"
, "ZengJiaMin", "ZengLingYan", "15859720661", "LiHuaiSong", "LaiDaoAi", "18605086929", "DuXiaoXia", "ChenHuiMin", "WuHaiLin"
, "LinGuoPu", "WeiJiaXing", "WangZhiJie", "ZhaoZhenRong", "SuYaQin", "LiTingTing", "LiFengCan", "ChenYingMing", "huanghong"
, "wangwenbin", "FuDeWang", "lxt", "DongPingPing", "LiJiaQunGongYongShouJi", "LiMeiJin", "lanpeifang", "linxiaolong", "hekaihong"
, "ZhangQingYuan", "LiJiaQun", "ChenLiXin", "ZhangShanBang", "WuHuanZheng", "XuHang", "HuangJian", "YuZhen", "18750080006"
, "13859842421", "YouYongHuang", "ShaoYunFei", "ChenYingQin", "LuoHuaiJie", "WengQiZhang", "LiuShengHua", "LiuHaiQuan"
, "DengBingWen", "DongKaiJie", "jimmy", "HuangJunQiang", "LaiLianYing", "ZhangWei", "WuDianZi", "XuGuangYi", "ZhouJinBin"
, "ShaoBinHua", "FuYangYi", "LiZhengHui", "YeJiaChen", "YangYaQi", "ChenMei", "DianCheLiKe", "ChenCuiYun", "YuTing", "ZhangTengFei"
, "no.39", "ZhengYun", "HuangChenChen"];
$count = count($follow_user);
if ($param['page'] >= $count) {
echo '<br>本次更新企业成员:';
echo '<br><br>成功更新 <span style="color: red;">' . $count . '</span> 人';
echo '<br><br><a href="/wechat/different/tem_external_contact">点击将再次更新企业成员>>></a>';
exit;
}
$userid = $follow_user[$param['page']];
$next_cursor = $this->get_by_user($userid, '');
if ($next_cursor) {
$ii = 0;
while ($next_cursor) {
$next_cursor = $this->get_by_user($userid, $next_cursor);
$ii++;
}
}
echo '<br>成功更新企业成员:' . $userid;
header('refresh:3;url=/wechat/different/tem_external_contact?page=' . ($param['page'] + 1));
ob_end_flush();//输出全部内容到浏览器
}
private function get_by_user($userid = '', $next_cursor = '')
{
$re = $this->wx_qyapi->get_external_contact(array('url' => 'get_by_user', 'userid' => $userid, 'next_cursor' => $next_cursor, 'limit' => '100'));
$next_cursor = '';
if ($re['errcode'] == 0) {
$next_cursor = $re['next_cursor'];
foreach ($re['external_contact_list'] as $key => $value) {
$external_userid = $value['external_contact']['external_userid'];
$this->set_wechatqy(['userid' => $userid, 'external_userid' => $external_userid], $value);
}
echo '<br>next_cursor=' . $next_cursor . '&external_contact_list=' . count($re['external_contact_list']);
}
return $next_cursor;
}
/**
* Notes:新增/更新企微用户
* Created on: 2022/5/31 9:54
* Created by: dengbw
* @param array $param
* @param array $user
*/
private function set_wechatqy($param = [], $user = [])
{
if (!$param['userid'] || !$param['external_userid'] || !$user) {
return;
}
$jsondata['external_contact'] = $user['external_contact'] ? $user['external_contact'] : '';
$jsondata['follow_info'] = $user['follow_info'] ? $user['follow_info'] : '';
$remark_mobiles = $user['follow_info']['remark_mobiles'];
$mobile = '';
if ($remark_mobiles && $remark_mobiles != '[]' && is_array($remark_mobiles)) {
$mobile = $remark_mobiles[0];//取第一个手机号
}
$addData = array(
'brand_id' => $this->bid,
'external_userid' => $user['external_contact']['external_userid'],
'userid' => $user['follow_info']['userid'] ? $user['follow_info']['userid'] : '',
'name' => $user['external_contact']['name'],
'avatar' => $user['external_contact']['avatar'],
'unionid' => $user['external_contact']['unionid'] ? $user['external_contact']['unionid'] : '',
'remark' => $user['follow_info']['remark'] ? $user['follow_info']['remark'] : '',
'mobile' => $mobile,
'c_time' => $user['follow_info']['createtime'] ? $user['follow_info']['createtime'] : time(),
'jsondata' => json_encode($jsondata, JSON_UNESCAPED_UNICODE),
'status' => 1,
);
$re_qy = $this->mdWechatqy->get(['brand_id' => $this->bid, 'userid' => $param['userid'], 'external_userid' => $param['external_userid']]);
if (!$re_qy) {
$this->mdWechatqy->add($addData);
} else {
$this->mdWechatqy->update($addData, ['id' => $re_qy['id']]);
}
}
/**
* Notes:添加企业客户事件
* https://liche-api-dev.xiaoyu.com/wechat/different/add_wechatqy?bid=133
* https://api.liche.cn/wechat/different/add_wechatqy?bid=133
* Created on: 2021/5/14 17:23
* Created by: dengbw
*/
public function add_wechatqy()
{
$param = $this->input->get();
$external_userid = $param['external_userid'];
if (!$external_userid) {
return false;
}
$this->load->model('app/app_different_qy_model', 'mdWechatqy');
$this->load->library('wx_qyapi', ['app' => 'different']);
$re = $this->wx_qyapi->get_external_contact(array('url' => 'get', 'external_userid' => $external_userid));
print_r('qymsg_external_errcode:' . $re['errcode'] . '=' . $re['external_contact']['external_userid']);
if ($re['errcode'] == 0) {
$external_userid = $re['external_contact']['external_userid'];
if ($external_userid) {
$re_qy = $this->mdWechatqy->get(array('external_userid' => $external_userid));
$jsondata['external_contact'] = $re['external_contact'] ? $re['external_contact'] : '';
$jsondata['follow_user'] = $re['follow_user'] ? $re['follow_user'] : '';
$addData = array(
'brand_id' => $this->bid,
'external_userid' => $re['external_contact']['external_userid'],
'name' => $re['external_contact']['name'],
'avatar' => $re['external_contact']['avatar'],
'unionid' => $re['external_contact']['unionid'] ? $re['external_contact']['unionid'] : '',
'userid' => $re['follow_user'][0]['userid'] ? $re['follow_user'][0]['userid'] : '',
'remark' => $re['follow_user'][0]['remark'] ? $re['follow_user'][0]['remark'] : '',
//'tags' => $re['follow_user'][0]['tags'] ? $re['follow_user'][0]['tags'] : '',
'c_time' => $re['follow_user'][0]['createtime'] ? $re['follow_user'][0]['createtime'] : time(),
'jsondata' => json_encode($jsondata, JSON_UNESCAPED_UNICODE),
'status' => 1,
);
if (!$re_qy) {
$this->mdWechatqy->add($addData);
} else {
$this->mdWechatqy->update($addData, array('external_userid' => $external_userid));
}
print_r('qymsg_addData:' . json_encode($addData, JSON_UNESCAPED_UNICODE));
}
}
print_r('qymsg_get:' . json_encode($re, JSON_UNESCAPED_UNICODE));
}
}
+20 -2
View File
@@ -106,9 +106,27 @@ class Customers extends Wxapp
protected function get_tag()
{
$id = intval($this->input_param('id'));
$type = $this->input_param('type');
$tags = $res_td = [];
$re_biz = $this->biz_model->get(['id' => $this->biz_id, 'status' => 1], 'type');
if ($re_biz['type'] != 5) {//异业店不显示客户标签
if ($re_biz['type'] == 5) {//异业店
if ($type == 'detail') {//详情显示标签
$re_cus = $this->customers_model->get(['id' => $id]);
if ($re_cus['cf_clues'] != '异业店') {
$this->customers_model->update(['cf_clues' => '异业店'], ['id' => $re_cus['id']]);
}
$jsondata = $re_cus['jsondata'] ? json_decode($re_cus['jsondata'], true) : [];
if ($jsondata['tag_group']) {
foreach ($jsondata['tag_group'] as $key => $val) {
$list = [];
foreach ($val['tag'] as $key2 => $val2) {
$list[] = ['name' => $val2, 'checked' => true];
}
$tags[] = ['name' => $val['name'], 'list' => $list];
}
}
}
} else {
$res = $this->mdCustomerTag->select(['status' => 1, 'pid' => 0, 'show<>' => 1], 'sort desc,id desc', 0, 0, 'id,name,type');
if ($res) {
if ($id) {
@@ -127,7 +145,7 @@ class Customers extends Wxapp
}
}
}
return $tags;
return ['tags' => $tags];
}
//修改基本信息
+9 -4
View File
@@ -21,6 +21,7 @@ class Wx_qyapi
private $access_token;
private $log_file = 'wx_qyapi.log';
private $env;
private $config;
public function __construct($params = array())
{
@@ -55,22 +56,26 @@ class Wx_qyapi
'diff_133' => array(
'corpid' => 'ww0fb634daed56031e',
'corpsecret' => 'ho5SeDUuoZ2TgkzJJt_mEtLaJW_eYXW_drLmibNmbZU',
'token' => 'y1U8zJBQWsHC',//接收事件使用
'encodingAesKey' => 'sA52I1PPw4ahdWrJjOKRlDtyyKUMBasTGdl5aCqszpi',//接收事件使用
),
);
$params['corpid'] && $this->corpid = $params['corpid'];
$params['corpsecret'] && $this->corpsecret = $params['corpsecret'];
$app = $params['app'] ? $params['app'] : 'liche';
if ($configs[$app]) {
$config = $configs[$app];
!$this->corpid && $config['corpid'] && $this->corpid = $config['corpid'];
!$this->corpsecret && $config['corpsecret'] && $this->corpsecret = $config['corpsecret'];
$this->config = $configs[$app];
!$this->corpid && $this->config['corpid'] && $this->corpid = $this->config['corpid'];
!$this->corpsecret && $this->config['corpsecret'] && $this->corpsecret = $this->config['corpsecret'];
}
$this->corpid && $this->log_file = "wx_qyapi_{$this->corpid}.log";
}
public function getConfig()
{
return ['corpid' => $this->corpid, 'corpsecret' => $this->corpsecret];
$config = ['corpid' => $this->corpid, 'corpsecret' => $this->corpsecret];
$this->config && $config = $this->config;
return $config;
}
public function access_token()
+1 -1
View File
@@ -114,7 +114,7 @@ class Wx_qyapi_agent
"url" => $url,
"signature" => $signature,
"rawString" => $string,
//"access_token" => $this->access_token(),
"access_token" => $this->access_token(),
'jsapi_ticket' => $jsapiTicket,
"agentid" => $this->agentid
);
@@ -44,7 +44,7 @@ class Customers_entity
/**
* Notes:添加日志
* Created on: 2022/4/13 11:57
* Created on: 2022/6/28 10:09
* Created by: dengbw
* @param $customer_id 客户id
* @param $uid 操作用户id
@@ -53,9 +53,10 @@ class Customers_entity
* @param string $type 操作类型 (0普通日志 1短信 2拨打电话)
* @param string $cf_platform 来源 (wxapp小程序 admin后台)
* @param array $imgs 日志图片
* @param string $c_time 创建日期
* @return string
*/
public function add_log($customer_id, $uid, $uname, $content, $type = '', $cf_platform = 'wxapp', $imgs = [])
public function add_log($customer_id, $uid, $uname, $content, $type = '', $cf_platform = 'wxapp', $imgs = [], $c_time = '')
{
$this->ci->load->model('receiver/receiver_customer_oplogs_model', 'customer_oplogs_model');
if ($type == 4 || $type == 5) {//到店或试驾,一天只记录一次
@@ -88,7 +89,7 @@ class Customers_entity
$add_data = [
'customer_id' => $customer_id,
'uid' => $uid,
'c_time' => time()
'c_time' => $c_time ? $c_time : time()
];
$content && $add_data['log'] = $content;
$uname && $add_data['uname'] = $uname;
@@ -0,0 +1,31 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Notes:异业店企微_日志
* Created on: 2022/6/27 14:52
* Created by: dengbw
*/
class App_different_qy_log_model extends HD_Model
{
private $table_name = 'lc_app_different_qy_log';
public function __construct()
{
parent::__construct($this->table_name, 'default');
}
/**
* Notes:操作类型
* Created on: 2022/7/27 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;
}
}
@@ -0,0 +1,17 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Notes:异业店企微用户表
* Created on: 2022/6/27 14:52
* Created by: dengbw
*/
class App_different_qy_model extends HD_Model
{
private $table_name = 'lc_app_different_qy';
public function __construct()
{
parent::__construct($this->table_name, 'default');
}
}
+58 -80
View File
@@ -13,16 +13,16 @@ class Different extends CI_Controller
private $userid = '';//企业成员userid
private $config_qyapi;
private $config_qyapi_agent;
private $aid;
private $bid;
public function __construct()
{
parent::__construct();
$aid = $this->input->get('aid') ? $this->input->get('aid') : $this->input->post('aid');
$this->aid = intval($aid);
if ($this->aid == 133) {
$this->config_qyapi = ['app' => "diff_{$this->aid}"];
$this->config_qyapi_agent = ['app' => "diff_{$this->aid}_1000004"];
$bid = $this->input->get('bid') ? $this->input->get('bid') : $this->input->post('bid');
$this->bid = intval($bid);
if ($this->bid == 133) {
$this->config_qyapi = ['app' => "diff_{$this->bid}"];
$this->config_qyapi_agent = ['app' => "diff_{$this->bid}_1000004"];
} else {
$this->show_json(400, '参数错误~');
}
@@ -54,17 +54,12 @@ class Different extends CI_Controller
{
$this->load->library('wx_qyapi_agent', $this->config_qyapi_agent);
$params = $this->input->get();
$url = http_host_com('home') . "/h5/different?aid={$params['aid']}";
$url = http_host_com('home') . "/h5/different?bid={$params['bid']}";
$this->set_auth($url, $params);
//print_r($this->session);
//echo '<br>';
$sign_package = $this->wx_qyapi->getSignPackage();
//print_r($sign_package);
//echo '<br>';
$sign_package_agent = $this->wx_qyapi_agent->getSignPackage();
print_r($sign_package_agent);
$data = ['_title' => '客户画像', 'sign_package' => $sign_package, 'sign_package_agent' => $sign_package_agent
, 'aid' => $this->aid];
, 'bid' => $this->bid];
$this->load->view('/h5/different/index', $data);
}
@@ -75,16 +70,13 @@ class Different extends CI_Controller
*/
public function get_user()
{
$this->show_json(400, '加载失败请重试~');
$params = $this->input->get();
$this->load->model('receiver/receiver_customers_model', 'mdCustomers');
$this->load->model('receiver/receiver_customer_tag_model', 'mdCustomerTag');
$this->load->model('receiver/receiver_customer_tagdata_model', 'mdCustomerTagdata');
$c_id = $of_id = $of2_id = $buddy_type = 0;
$of_id_index = -1;
$tagList = $res_td = $sources = $userInfo = [];
$tag_data = $tags_name = $description = '';
$userid = $this->session['userid'];
$userid = $this->userid;
if (!$userid) {
$this->show_json(400, '加载企业成员失败请重试~');
}
@@ -130,7 +122,7 @@ class Different extends CI_Controller
}
$userInfo = [
'avatar' => $avatar, 'mobile' => $mobile, 'remark_mobile' => $mobile, 'name' => $name, 'gender' => $gender, 'source' => '@微信'
, 'unionid' => $unionid, 'external_userid' => $params['external_userid'], 'userid' => $userid, 'tags_name' => $tags_name
, 'unionid' => $unionid, 'external_userid' => $params['external_userid'], 'userid' => $userid, 'tags_id' => $tag_data
];
if ($this->session['biz_id']) {
$biz_id = intval($this->session['biz_id']);
@@ -145,41 +137,27 @@ class Different extends CI_Controller
$of_id = $re_cus['of_id'];
$of2_id = $re_cus['of2_id'];
$buddy_type = $re_cus['buddy_type'];
$res_td = $this->mdCustomerTagdata->select(['c_id' => $re_cus['id']], 'id desc', 0, 0, 't_id');//查找用户选择
$tag_data = $res_td ? array_unique(array_column($res_td, 't_id')) : '';
}
}
if (!$c_id) {
$this->load->model('app/app_lichene_qy_model', 'mdWechatqy');
$this->load->model('app/app_different_qy_model', 'mdWechatqy');
$this->set_wechatqy(['userid' => $userid, 'external_userid' => $params['external_userid']], $qy_user);
$re_qy = $this->mdWechatqy->get(['userid' => $userid, 'external_userid' => $params['external_userid']]);
$re_qy = $this->mdWechatqy->get(['brand_id' => $this->bid, 'userid' => $userid, 'external_userid' => $params['external_userid']]);
$re_qy && $buddy_type = $re_qy['buddy_type'];
}
$userInfo['c_id'] = $c_id;
//标签
$res = $this->mdCustomerTag->select(['status' => 1, 'pid' => 0], 'sort desc,id desc', 0, 0, 'id,name,type');
if ($res) {
$key_tag_id = $c_id ? 'id' : 'qy_id';//比对key值
foreach ($res as $key => $val) {
$re = $this->wx_qyapi->get_external_contact(['url' => 'get_corp_tag_list']);
if ($re['errcode'] == 0 && $re['tag_group']) {
foreach ($re['tag_group'] as $key => $val) {
$list = [];
$value = '';
$res2 = $this->mdCustomerTag->select(['status' => 1, 'pid' => $val['id']], 'sort desc,id desc', 0, 0, 'id,name,qy_id');
foreach ($res2 as $key2 => $val2) {
foreach ($val['tag'] as $key2 => $val2) {
//检查是否选中标签
$setValue = ['id' => $val2['id'], 'name' => $val2['name'], 'qy_id' => $val2['qy_id']];
if ($val['type'] == 'checkbox') {
$setValue['checked'] = $tag_data && in_array($val2[$key_tag_id], $tag_data) ? true : false;
} else {
$checked = false;
if ($tag_data && in_array($val2[$key_tag_id], $tag_data)) {
!$value && $checked = true;
$value = $val2['qy_id'];
}
$setValue['checked'] = $checked;
}
$setValue = ['id' => $val2['id'], 'name' => $val2['name']];
$setValue['checked'] = $tag_data && in_array($val2['id'], $tag_data) ? true : false;
$list[] = $setValue;
}
$tagList[] = ['id' => $val['id'], 'name' => $val['name'], 'type' => $val['type'], 'list' => $list];
$tagList[] = ['id' => $val['group_id'], 'name' => $val['group_name'], 'list' => $list];
}
}
//线索来源
@@ -231,22 +209,40 @@ class Different extends CI_Controller
$userInfo = $params['userInfo'];
$mobile = $userInfo['mobile'];
$biz_id = intval($userInfo['biz_id']);
$this->load->library('receiver/customers_entity');
$this->load->model('receiver/receiver_customers_model', 'mdCustomers');
$this->load->model('receiver/receiver_customer_tagdata_model', 'mdCustomerTagdata');
$this->load->model('app/app_lichene_qy_model', 'mdWechatqy');
$this->load->library('receiver/customers_entity');
$this->load->model('app/app_different_qy_model', 'mdWechatqy');
$uid = $userInfo['uid'];
$uname = $userInfo['uname'];
$c_id = $userInfo['c_id'];
$result = $re_cus = '';
$tag_group = [];//客房画像
if ($params['taglList']) {
foreach ($params['taglList'] as $key => $val) {
$tag = [];
foreach ($val['list'] as $key2 => $val2) {
if ($val2['checked'] == 'true') {
$tag[$val2['id']] = $val2['name'];
}
}
if ($tag) {
$tag_group[$val['id']] = ['name' => $val['name'], 'tag' => $tag];
}
}
}
if ($c_id) {//已存在客户,更新资料
$up_data = ['of_id' => $params['of_id'], 'of2_id' => $params['of2_id'], 'buddy_type' => $params['buddy_type']];
$re_cus2 = $this->mdCustomers->get(['id' => $c_id, 'status<>' => -1]);
if (!$re_cus2) {
$this->show_json(200, '客户不存在');
}
$jsondata = $re_cus2['jsondata'] ? json_decode($re_cus2['jsondata'], true) : [];
$jsondata['tag_group'] = $tag_group;
$up_data['jsondata'] = json_encode($jsondata, JSON_UNESCAPED_UNICODE);
$re_cus2['wxqy'] != 1 && $up_data['wxqy'] = 1;
!$re_cus2['unionid'] && $up_data['unionid'] = $userInfo['unionid'];
if(!$re_cus2['unionid'] && $userInfo['unionid']){
$up_data['unionid'] = $userInfo['unionid'];
}
$result = $this->mdCustomers->update($up_data, ['id' => $c_id]);
$this->customers_entity->add_log($c_id, $uid, $uname, '修改用户基本信息');
} else {
@@ -254,6 +250,9 @@ class Different extends CI_Controller
$re_cus = $this->mdCustomers->get(['biz_id' => $biz_id, 'mobile' => $mobile, 'status<>' => -1]);
if ($re_cus) {//已存客户绑定操作,不带入现有标签中
$up_data = ['wxqy' => 1];
$jsondata = $re_cus['jsondata'] ? json_decode($re_cus['jsondata'], true) : [];
$jsondata['tag_group'] = $tag_group;
$up_data['jsondata'] = json_encode($jsondata, JSON_UNESCAPED_UNICODE);
$userInfo['unionid'] && $up_data['unionid'] = $userInfo['unionid'];
$result = $this->mdCustomers->update($up_data, ['id' => $re_cus['id']]);
} else {//创建新客户
@@ -274,21 +273,22 @@ class Different extends CI_Controller
'of2_id' => $params['of2_id'],
'buddy_type' => $params['buddy_type'],
'cf_title' => '自有资源',
'cf_clues' => '企微私域',
'cf_clues' => '异业店',
'admin_id' => $uid,
'status' => 0,//未见客户
'p_time' => $date,//分配时间
'jsondata' => json_encode(['tag_group' => $tag_group], JSON_UNESCAPED_UNICODE),
'c_time' => time()
];
$c_id = $this->mdCustomers->add($add_data);
if ($c_id) {//加日志
$result = true;
$this->load->model('app/app_lichene_qy_log_model', 'mdWechatqyLog');
$res_log = $this->mdWechatqyLog->select(['external_userid' => $userInfo['external_userid']
, 'userid' => $userInfo['userid']], 'c_time asc', 0, 0, 'remark');
$this->load->model('app/app_different_qy_log_model', 'mdWechatqyLog');
$res_log = $this->mdWechatqyLog->select(['brand_id' => $this->bid, 'external_userid' => $userInfo['external_userid']
, 'userid' => $userInfo['userid']], 'c_time asc', 0, 0, 'remark,c_time');
if ($res_log) {//企微跟进记录
foreach ($res_log as $key => $val) {
$this->customers_entity->add_log($c_id, $uid, $uname, $val['remark'], 8);
$this->customers_entity->add_log($c_id, $uid, $uname, $val['remark'], 8, 'wxapp', '', $val['c_time']);
}
}
$this->customers_entity->add_log($c_id, $uid, $uname, '创建客户档案', 3);
@@ -296,29 +296,6 @@ class Different extends CI_Controller
}
}
}
//客户标签操作
if ($c_id && $params['taglList']) {
$add_tag = [];
//查找已加入标签
$res_td = $this->mdCustomerTagdata->select(['c_id' => $c_id], 'id desc', 0, 0, 't_id');
$tag_data = $res_td ? array_unique(array_column($res_td, 't_id')) : '';
foreach ($params['taglList'] as $key => $val) {
foreach ($val['list'] as $key2 => $val2) {
if ($val2['checked'] == 'true') {
if (!$tag_data || !in_array($val2['id'], $tag_data)) {//未加标签,新增
$add_tag[] = ['c_id' => $c_id, 't_id' => $val2['id'], 'c_time' => time()];
}
} else {
if ($tag_data && in_array($val2['id'], $tag_data)) {//删除标签
$this->mdCustomerTagdata->delete(['c_id' => $c_id, 't_id' => $val2['id']]);
}
}
}
}
if ($add_tag && count($add_tag)) {
$this->mdCustomerTagdata->add_batch($add_tag);
}
}
//更新企微用户好友类型
$up_qy = $this->mdWechatqy->update(['buddy_type' => $params['buddy_type']], ['external_userid' => $userInfo['external_userid']
, 'userid' => $userInfo['userid']]);
@@ -333,18 +310,18 @@ class Different extends CI_Controller
$this->wx_qyapi->get_external_contact(['url' => 'remark', 'userid' => $userInfo['userid']
, 'external_userid' => $userInfo['external_userid'], 'remark_mobiles' => $remark_mobiles, 'description' => $description]);
//标签操作
$tags_name = $userInfo['tags_name'];
$tags_id = $userInfo['tags_id'];
$add_tag = $remove_tag = '';
if ($params['taglList']) {
foreach ($params['taglList'] as $key => $val) {
foreach ($val['list'] as $key2 => $val2) {
if ($val2['checked'] == 'true') {
if (!$tags_name || !in_array($val2['name'], $tags_name)) {//未加标签,新增
$add_tag[] = $val2['qy_id'];
if (!$tags_id || !in_array($val2['id'], $tags_id)) {//未加标签,新增
$add_tag[] = $val2['id'];
}
} else {
if ($tags_name && in_array($val2['name'], $tags_name)) {//删除标签
$remove_tag[] = $val2['qy_id'];
if ($tags_id && in_array($val2['id'], $tags_id)) {//删除标签
$remove_tag[] = $val2['id'];
}
}
}
@@ -385,6 +362,7 @@ class Different extends CI_Controller
$mobile = $remark_mobiles[0];//取第一个手机号
}
$addData = array(
'brand_id' => $this->bid,
'external_userid' => $user['external_contact']['external_userid'],
'userid' => $user['follow_info']['userid'] ? $user['follow_info']['userid'] : '',
'name' => $user['external_contact']['name'],
@@ -396,7 +374,7 @@ class Different extends CI_Controller
'jsondata' => json_encode($jsondata, JSON_UNESCAPED_UNICODE),
'status' => 1,
);
$re_qy = $this->mdWechatqy->get(['userid' => $param['userid'], 'external_userid' => $param['external_userid']]);
$re_qy = $this->mdWechatqy->get(['brand_id' => $this->bid, 'userid' => $param['userid'], 'external_userid' => $param['external_userid']]);
if (!$re_qy) {
$this->mdWechatqy->add($addData);
} else {
@@ -442,7 +420,7 @@ class Different extends CI_Controller
}
$session = ['userid' => $res_detail['userid'], 'uid' => $re_user['id'], "uname" => $re_user['uname']
, "mobile" => $re_user['mobile'], "biz_id" => intval($re_user['biz_id'])];
$expire = 86400 * 30;
$expire = 86400 * 7;
}
$ukey = liche_authcode(json_encode($session, JSON_UNESCAPED_UNICODE), 'ENCODE', $this->secret);
set_cookie("ukey", $ukey, $expire);
+1 -1
View File
@@ -283,7 +283,7 @@ class Persona extends CI_Controller
, 'userid' => $userInfo['userid']], 'c_time asc', 0, 0, 'remark');
if ($res_log) {//企微跟进记录
foreach ($res_log as $key => $val) {
$this->customers_entity->add_log($c_id, $uid, $uname, $val['remark'], 8);
$this->customers_entity->add_log($c_id, $uid, $uname, $val['remark'], 8, 'wxapp', '', $val['c_time']);
}
}
$this->customers_entity->add_log($c_id, $uid, $uname, '创建客户档案', 3);
+8 -16
View File
@@ -68,20 +68,12 @@
</div>
</div>
<div class="mt30 inner30 pb50 bg-fff ulib-r10">
<div class="mt20 font-36 text-center text-bold">客户画像_different</div>
<div class="mt20 font-36 text-center text-bold">客户画像</div>
<div class="relative mt40" v-for="(list,i) in taglList">
<div class="font-28">
<span class="text-middle">{{list.name}}</span>
<span class="text-middle font-24" v-if="list.type=='radio'">(单选)</span>
<span class="text-middle font-24" v-if="list.type=='checkbox'">(多选)</span>
</div>
<div class="fn-clear" v-if="list.type=='radio'">
<div v-for="(option,j) in list.list"
:class="'inline-block space-nowrap mt20 mr20 pt15 pb15 pl30 pr30 font-22 ulib-r10 ' + [option.checked ? 'bg-3f91fd color-fff' : 'bg-f6 color-666']"
@click="radioPicker(i,j)">{{option.name}}
</div>
</div>
<vdiv class="fn-clear" v-if="list.type=='checkbox'">
<vdiv class="fn-clear">
<div v-for="(option,j) in list.list"
:class="'inline-block space-nowrap mt20 mr20 pt15 pb15 pl30 pr30 font-22 ulib-r10 ' + [option.checked ? 'bg-3f91fd color-fff' : 'bg-f6 color-666']"
@click="checkPicker(i,j)">{{option.name}}
@@ -111,8 +103,8 @@
of_id: 0,
of2_id: 0,
sources: [],
aid: <?=$aid?>,
buddy_type:0,
bid: <?=$bid?>,
buddy_type: 0,
buddyTypeAry: [],
},
created() {
@@ -138,12 +130,12 @@
getUser(external_userid) {
let that = this;
$.ajax({
url: '/h5/persona/get_user',
url: '/h5/different/get_user',
type: 'get',
dataType: 'json',
data: {
external_userid: external_userid,
aid: that.aid,
bid: that.bid,
},
beforeSend: function () {
},
@@ -176,7 +168,7 @@
var of_title = that.of_id ? $("#id-of_id").find("option:selected").text() : '';
var of2_title = that.of2_id ? $("#id-of2_id").find("option:selected").text() : '';
$.ajax({
url: '/h5/persona/post_user',
url: '/h5/different/post_user',
type: 'post',
dataType: 'json',
data: {
@@ -186,7 +178,7 @@
of2_id: that.of2_id,
of_title: of_title,
of2_title: of2_title,
aid: that.aid,
bid: that.bid,
buddy_type: that.buddy_type,
},
beforeSend: function () {