diff --git a/api/controllers/wechat/Lichene.php b/api/controllers/wechat/Lichene.php
index 08be8bf2..e4bda7fd 100644
--- a/api/controllers/wechat/Lichene.php
+++ b/api/controllers/wechat/Lichene.php
@@ -175,9 +175,9 @@ Class Lichene extends HD_Controller
$c_id = $re_cus['id'];
if ($param['mobile']) {
if (!$re_cus['mobile']) {//更新手机
- $re_cus2 = $this->mdCustomers->get(['biz_id' => $re_cus['biz_id'], 'mobile' => $param['mobile'], 'stats<>' => -1]);
+ $re_cus2 = $this->mdCustomers->get(['biz_id' => $re_cus['biz_id'], 'mobile' => $param['mobile'], 'status<>' => -1]);
if ($re_cus2) {//合并用户
- $this->mdCustomers->update(['stats' => -1], ['id' => $re_cus['id']]);//删除原有数据
+ $this->mdCustomers->update(['status' => -1], ['id' => $re_cus['id']]);//删除原有数据
$c_id = $re_cus2['id'];
$this->mdCustomers->update(['unionid' => $param['unionid']], ['id' => $re_cus2['id']]);//合并到现有手机
} else {
diff --git a/api/controllers/wxapp/licheb/Customers.php b/api/controllers/wxapp/licheb/Customers.php
index 9450d9bf..37c46d43 100644
--- a/api/controllers/wxapp/licheb/Customers.php
+++ b/api/controllers/wxapp/licheb/Customers.php
@@ -71,6 +71,7 @@ class Customers extends Wxapp
'is_top' => $row['is_top'],
'status' => $row['status'],
'other_data' => $other_data,
+ 'is_weChat' => $row['unionid'] ? true : false,
'tags' => $tags
];
return $data;
@@ -555,7 +556,7 @@ class Customers extends Wxapp
$lists = [];
if ($count) {
$fileds = 'id,name,admin_id,mobile,level,car_json,is_top,cf_title,brand_id,s_id,cont_time,c_time,defeat_time
- ,of_id,of2_id';
+ ,of_id,of2_id,unionid';
$rows = $this->customers_model->select($where, $orderby, $page, $size, $fileds);
//获取管理员
$admin_arr = array_unique(array_column($rows, 'admin_id'));
@@ -607,6 +608,7 @@ class Customers extends Wxapp
'tags' => $tags,
'defeat' => $defeat,
'group_id' => $group_id,
+ 'is_weChat' => $val['unionid'] ? true : false,
'allot' => $allot
];
}
diff --git a/common/libraries/Wx_qyapi.php b/common/libraries/Wx_qyapi.php
index 1b69c4bc..32244cd5 100644
--- a/common/libraries/Wx_qyapi.php
+++ b/common/libraries/Wx_qyapi.php
@@ -40,7 +40,7 @@ class Wx_qyapi
$this->init($params);
}
- function init($params)
+ public function init($params)
{
$configs = array(
//狸车新能源
@@ -155,22 +155,20 @@ class Wx_qyapi
} else if ($param['url'] == 'get_corp_tag_list') {//获取企业标签库 https://work.weixin.qq.com/api/doc/90001/90143/92696#获取企业标签库
$url = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/get_corp_tag_list?access_token={$access_token}";
$res = $this->ci->mycurl->httpPost($url, array('group_id' => $param['group_id']), 'is_json');
- } else if ($param['url'] == 'mark_tag') {//编辑客户企业标签 https://work.weixin.qq.com/api/doc/90001/90143/92697
- $url = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/mark_tag?access_token={$access_token}";
- $res = $this->ci->mycurl->httpPost($url, array('userid' => $param['userid'], 'external_userid' => $param['external_userid']
- , 'add_tag' => $param['add_tag']), 'is_json');
} else if ($param['url'] == 'add_corp_tag') {//添加企业客户标签 https://developer.work.weixin.qq.com/document/path/92117#
$url = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/add_corp_tag?access_token={$access_token}";
$res = $this->ci->mycurl->httpPost($url, array('group_id' => $param['group_id'], 'group_name' => $param['group_name'], 'order' => $param['order'],
'tag' => $param['tag']), 'is_json');
} else if ($param['url'] == 'mark_tag') {//编辑客户企业标签 https://developer.work.weixin.qq.com/document/path/92118
- $url = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/mark_tag?access_token={$access_token}";
- $res = $this->ci->mycurl->httpPost($url, array('userid' => $param['userid'], 'external_userid' => $param['external_userid'], 'add_tag' => $param['add_tag'],
- 'remove_tag' => $param['remove_tag']), 'is_json');
+ $url = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/mark_tag?access_token={$access_token}&debug=1";
+ $params = ['userid' => $param['userid'], 'external_userid' => $param['external_userid']];
+ $param['add_tag'] && $params['add_tag'] = $param['add_tag'];
+ $param['remove_tag'] && $params['remove_tag'] = $param['remove_tag'];
+ $res = $this->ci->mycurl->httpPost($url, $params, 'is_json');
} else if ($param['url'] == 'remark') {//修改客户备注信息 https://developer.work.weixin.qq.com/document/path/92115
$url = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/remark?access_token={$access_token}";
$res = $this->ci->mycurl->httpPost($url, array('userid' => $param['userid'], 'external_userid' => $param['external_userid']
- , 'remark_mobiles' => $param['remark_mobiles']), 'is_json');
+ , 'remark_mobiles' => $param['remark_mobiles'], 'description' => $param['description']), 'is_json');
}
$data = trim($res, chr(239) . chr(187) . chr(191));
$result = json_decode($data, true);
@@ -186,6 +184,7 @@ class Wx_qyapi
// 这里参数的顺序要按照 key 值 ASCII 码升序排序
$string = "jsapi_ticket=$jsapiTicket&noncestr=$nonceStr×tamp=$timestamp&url=$url";
$signature = sha1($string);
+ //$access_token = $this->access_token();
$signPackage = array(
"appId" => $this->corpid,
"nonceStr" => $nonceStr,
@@ -193,6 +192,7 @@ class Wx_qyapi
"url" => $url,
"signature" => $signature,
"rawString" => $string,
+ //"access_token" => $access_token,
'jsapi_ticket' => $jsapiTicket
);
return $signPackage;
@@ -200,9 +200,11 @@ class Wx_qyapi
public function getJsApiTicket()
{
- $jsapi_ticket = $this->redis->get('jsapi_ticket_' . $this->corpsecret);
+ $key = 'jsapi_ticket_' . $this->corpsecret;
+ $jsapi_ticket = $this->redis->get($key);
if (!$jsapi_ticket) {
//获取企业的jsapi_ticket https://developer.work.weixin.qq.com/document/path/90506#14924
+ //https://developer.work.weixin.qq.com/document/10029#%E8%8E%B7%E5%8F%96%E5%BA%94%E7%94%A8%E7%9A%84jsapi_ticket
$access_token = $this->access_token();
$url = "https://qyapi.weixin.qq.com/cgi-bin/get_jsapi_ticket?access_token={$access_token}";
$res = $this->ci->mycurl->httpGet($url);
@@ -211,7 +213,7 @@ class Wx_qyapi
debug_log('error:__FUNCTION__:' . $res, $this->log_file);
} else {
$jsapi_ticket = $result->ticket;
- $this->redis->save('jsapi_ticket_' . $this->corpsecret, $result->ticket, $result->expires_in);
+ $this->redis->save($key, $result->ticket, $result->expires_in);
}
}
return $jsapi_ticket;
diff --git a/common/libraries/Wx_qyapi_agent.php b/common/libraries/Wx_qyapi_agent.php
new file mode 100644
index 00000000..7789dce8
--- /dev/null
+++ b/common/libraries/Wx_qyapi_agent.php
@@ -0,0 +1,133 @@
+env = 'd';
+ } elseif (false !== strpos($_SERVER['HTTP_HOST'], 'test')) {//test 测试
+ $this->env = 't';
+ } else { // 正式
+ $this->env = 'p';
+ }
+ $this->redis = &load_cache('redis');
+ $this->ci = &get_instance();
+ $this->ci->load->library('mycurl');
+
+ $this->init($params);
+ }
+
+ public function init($params)
+ {
+ $configs = array(
+ //狸车新能源_客户画像
+ 'lichene_1000005' => array(
+ 'corpid' => 'wwff2d727ce47d6852',
+ 'corpsecret' => 'QBkmK9hm1WgrWI9RUE5-Al10qVtHCM2eEoa8NQzTKkI',
+ )
+ );
+ $params['corpid'] && $this->corpid = $params['corpid'];
+ $params['corpsecret'] && $this->corpsecret = $params['corpsecret'];
+ $app = $params['app'] ? $params['app'] : 'lichene_1000005';
+ if ($configs[$app]) {
+ $config = $configs[$app];
+ !$this->corpid && $config['corpid'] && $this->corpid = $config['corpid'];
+ !$this->corpsecret && $config['corpsecret'] && $this->corpsecret = $config['corpsecret'];
+ }
+ $this->corpid && $this->log_file = "wx_qyapi_{$this->corpid}.log";
+ }
+
+ public function access_token()
+ {
+ $access_token = $this->redis->get($this->corpsecret);
+ if (!$access_token) {
+ $url = self::BASE_URL . sprintf(self::TOKEN_API, $this->corpid, $this->corpsecret);
+ $res = $this->ci->mycurl->httpGet($url);
+ $result = json_decode($res);
+ if ($result->errcode) {
+ debug_log('error:__FUNCTION__:' . $res, $this->log_file);
+ } else {
+ $access_token = $result->access_token;
+ $this->redis->save($this->corpsecret, $result->access_token, $result->expires_in);
+ }
+ }
+ return $access_token;
+ }
+
+ public function getSignPackage()
+ {
+ $jsapiTicket = $this->getJsApiTicket();
+ $url = "https://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
+ $timestamp = time();
+ $nonceStr = $this->createNonceStr();
+ // 这里参数的顺序要按照 key 值 ASCII 码升序排序
+ $string = "jsapi_ticket=$jsapiTicket&noncestr=$nonceStr×tamp=$timestamp&url=$url";
+ $signature = sha1($string);
+ //$access_token = $this->access_token();
+ $signPackage = array(
+ "appId" => $this->corpid,
+ "nonceStr" => $nonceStr,
+ "timestamp" => $timestamp,
+ "url" => $url,
+ "signature" => $signature,
+ "rawString" => $string,
+ //"access_token" => $access_token,
+ 'jsapi_ticket' => $jsapiTicket
+ );
+ return $signPackage;
+ }
+
+ public function getJsApiTicket()
+ {
+ $key = 'jsapi_ticket_' . $this->corpsecret;
+ $jsapi_ticket = $this->redis->get($key);
+ if (!$jsapi_ticket) {
+ //https://developer.work.weixin.qq.com/document/10029#%E8%8E%B7%E5%8F%96%E5%BA%94%E7%94%A8%E7%9A%84jsapi_ticket
+ $access_token = $this->access_token();
+ $url = "https://qyapi.weixin.qq.com/cgi-bin/ticket/get?access_token={$access_token}&type=agent_config";
+ $res = $this->ci->mycurl->httpGet($url);
+ $result = json_decode($res);
+ if ($result->errcode) {
+ debug_log('error:__FUNCTION__:' . $res, $this->log_file);
+ } else {
+ $jsapi_ticket = $result->ticket;
+ $this->redis->save($key, $result->ticket, $result->expires_in);
+ }
+ }
+ return $jsapi_ticket;
+ }
+
+ private function createNonceStr($length = 16)
+ {
+ $chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
+ $str = "";
+ for ($i = 0; $i < $length; $i++) {
+ $str .= substr($chars, mt_rand(0, strlen($chars) - 1), 1);
+ }
+ return $str;
+ }
+}
+
+?>
diff --git a/home/controllers/h5/Lichene.php b/home/controllers/h5/Lichene.php
index 35949410..03cd14a1 100644
--- a/home/controllers/h5/Lichene.php
+++ b/home/controllers/h5/Lichene.php
@@ -19,37 +19,116 @@ class Lichene extends CI_Controller
{
$this->load->library('wx_qyapi', ['app' => 'lichene']);
$sign_package = $this->wx_qyapi->getSignPackage();
- echo json_encode($sign_package, JSON_UNESCAPED_UNICODE);
- $data = ['_title' => '客户画像', 'sign_package' => $sign_package];
+
+ $this->load->library('wx_qyapi_agent');
+ $sign_package2 = $this->wx_qyapi_agent->getSignPackage();
+ $sign_package2['agentid'] = '1000005';
+ //echo json_encode($sign_package, JSON_UNESCAPED_UNICODE);
+ //echo '
';
+ //echo json_encode($sign_package2, JSON_UNESCAPED_UNICODE);
+ $data = ['_title' => '客户画像', 'sign_package' => $sign_package, 'sign_package2' => $sign_package2];
$this->load->view('/h5/lichene/index', $data);
}
+ /**
+ * Notes:获取用户信息
+ * Created on: 2022/3/27 0:55
+ * Created by: dengbw
+ */
public function get_user()
{
+ $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');
- $id = 0;
- $tagList = $res_td = $sources = [];
+ $c_id = $of_id = $of2_id = 0;
+ $of_id_index = -1;
+ $tagList = $res_td = $sources = $userInfo = [];
+ $tag_data = $tags_name = $description = '';
+ if (!$params['external_userid']) {
+ $this->show_json(400, '加载失败请重试~');
+ }
+ if ($params['external_userid']) {
+ $this->load->library('wx_qyapi', ['app' => 'lichene']);
+ //外部联系人
+ $re = $this->wx_qyapi->get_external_contact(array('url' => 'get', 'external_userid' => $params['external_userid']));
+ if (!$re) {
+ $this->show_json(400, '加载失败请重试!');
+ }
+ $tags_ary = $re['follow_user'][0]['tags'];//客户画像
+ if ($tags_ary && $tags_ary != '[]' && is_array($tags_ary)) {
+ foreach ($tags_ary as $key => $val) {
+ if ($val['type'] == 1) {//企业标签
+ $tag_data[] = $val['tag_id'];
+ $tags_name[] = $val['tag_name'];
+ }
+ }
+ }
+ $userid = $re['follow_user'][0]['userid'] ? $re['follow_user'][0]['userid'] : '';
+ $avatar = $mobile = $name = $unionid = '';
+ $gender = $biz_id = 0;
+ $remark_mobiles = $re['follow_user'][0]['remark_mobiles'];//用户手机
+ $description = $re['follow_user'][0]['description'];//描述
+ if ($remark_mobiles && $remark_mobiles != '[]' && is_array($remark_mobiles)) {
+ $mobile = $remark_mobiles[0];//取第一个手机号
+ }
+ $external_contact = $re['external_contact'] ? $re['external_contact'] : '';//用户信息
+ if ($external_contact) {
+ $external_contact['avatar'] && $avatar = $external_contact['avatar'];
+ $external_contact['name'] && $name = $external_contact['name'];
+ $gender = intval($external_contact['gender']);
+ $external_contact['unionid'] && $unionid = $external_contact['unionid'];
+ }
+ $userInfo = [
+ 'avatar' => $avatar, 'mobile' => $mobile, 'name' => $name, 'gender' => $gender, 'source' => '@微信'
+ , 'unionid' => $unionid, 'external_userid' => $params['external_userid'], 'userid' => $userid, 'tags_name' => $tags_name
+ ];
+ //企业成员
+ $re_wx = $this->wx_qyapi->get_external_contact(array('url' => 'user_get', 'userid' => $userid));
+ if ($re_wx['errcode'] == 0 && $re_wx['mobile']) {
+ $admin_id = 0;
+ $admin_name = '';
+ $this->load->model('app/licheb/App_licheb_users_model', 'mdUsers');
+ $re_u = $this->mdUsers->get(array('mobile' => $re_wx['mobile']));
+ if ($re_u) {
+ $biz_id = intval($re_u['biz_id']);
+ $admin_id = $re_u['id'];
+ $admin_name = $re_u['uname'];
+ }
+ $userInfo['biz_id'] = $biz_id;
+ $userInfo['admin_id'] = $admin_id;
+ $userInfo['admin_name'] = $admin_name;
+ }
+ if ($biz_id && $mobile) {//查找已存在客户
+ $re_cus = $this->mdCustomers->get(['biz_id' => $biz_id, 'mobile' => $mobile, 'status<>' => -1]);
+ if ($re_cus) {
+ $c_id = $re_cus['id'];
+ $of_id = $re_cus['of_id'];
+ $of2_id = $re_cus['of2_id'];
+ $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')) : '';
+ }
+ }
+ }
+ $userInfo['c_id'] = $c_id;
//标签
$res = $this->mdCustomerTag->select(['status' => 1, 'pid' => 0], 'sort desc,id desc', 0, 0, 'id,name,type');
if ($res) {
- $id && $res_td = $this->mdCustomerTagdata->select(['c_id' => $id], 'id desc', 0, 0, 't_id');//查找用户选择
- $tag_data = $res_td ? array_unique(array_column($res_td, 't_id')) : '';
+ $key_tag_id = $c_id ? 'id' : 'qy_id';//比对key值
foreach ($res as $key => $val) {
$list = [];
$value = '';
- $res2 = $this->mdCustomerTag->select(['status' => 1, 'pid' => $val['id']], 'sort desc,id desc', 0, 0, 'id,name');
+ $res2 = $this->mdCustomerTag->select(['status' => 1, 'pid' => $val['id']], 'sort desc,id desc', 0, 0, 'id,name,qy_id');
foreach ($res2 as $key2 => $val2) {
//检查是否选中标签
- $setValue = ['id' => $val2['id'], 'name' => $val2['name']];
+ $setValue = ['id' => $val2['id'], 'name' => $val2['name'], 'qy_id' => $val2['qy_id']];
if ($val['type'] == 'checkbox') {
- $setValue['checked'] = $tag_data && in_array($val2['id'], $tag_data) ? true : false;
+ $setValue['checked'] = $tag_data && in_array($val2[$key_tag_id], $tag_data) ? true : false;
} else {
$checked = false;
- if ($tag_data && in_array($val2['id'], $tag_data)) {
+ if ($tag_data && in_array($val2[$key_tag_id], $tag_data)) {
!$value && $checked = true;
- $value = $val2['id'];
+ $value = $val2['qy_id'];
}
$setValue['checked'] = $checked;
}
@@ -64,18 +143,200 @@ class Lichene extends CI_Controller
if (strlen($status) && $status == 0) {//未见客户
unset($offline_sources[1]);
}
+ $ii = 0;
+ $description_arr = $description ? explode('-', $description) : [];
foreach ($offline_sources as $key => $val) {
$list = [];
+ if (!$c_id) {
+ if ($description_arr[0] == $val['name']) {
+ $of_id = $key;
+ $of_id_index = $ii;
+ }
+ } else {
+ $of_id == $key && $of_id_index = $ii;
+ }
foreach ($val['list'] as $key2 => $val2) {
+ if (!$c_id) {
+ $description_arr[1] == $val2 && $of2_id = $key2;
+ }
$list[] = ['id' => $key2, 'name' => $val2];
}
$sources[] = ['id' => $key, 'name' => $val['name'], 'list' => $list];
+ $ii++;
}
$data['tagList'] = $tagList;
$data['sources'] = $sources;
+ $data['userInfo'] = $userInfo;
+ $data['of_id'] = $of_id;
+ $data['of2_id'] = $of2_id;
+ $data['of_id_index'] = $of_id_index;
$this->show_json(200, '获取用户信息成功', $data);
}
+ /**
+ * Notes:到店
+ * Created on: 2022/3/27 0:57
+ * Created by: dengbw
+ */
+ public function post_to_biz()
+ {
+ $params = $this->input->post();
+ $userInfo = $params['userInfo'];
+ $mobile = $userInfo['mobile'];
+ $biz_id = intval($userInfo['biz_id']);
+ if (!$mobile) {
+ $this->show_json(400, '请输入手机号!');
+ }
+ if (!$biz_id) {
+ $this->show_json(400, '未绑定狸车宝门店!');
+ }
+ $this->load->model('receiver/receiver_customers_model', 'mdCustomers');
+ $this->load->model("biz/biz_model", 'mdBiz');
+ $re_biz = $this->mdBiz->get(['id' => $biz_id, 'status' => 1]);
+ if (!$re_biz) {
+ $this->show_json(400, '门店不存在!');
+ }
+ $re_cus = $this->mdCustomers->get(['biz_id' => $biz_id, 'mobile' => $mobile, 'status<>' => -1]);
+ $date = date('Y-m-d H:i:s');
+ if (!$re_cus) {//新增客户
+ $add_data = [
+ 'name' => $userInfo['name'],
+ 'mobile' => $mobile,
+ 'biz_id' => $biz_id,
+ 'city_id' => $re_biz['city_id'],
+ 'county_id' => $re_biz['county_id'],
+ 'unionid' => $userInfo['unionid'],
+ 'of_id' => $params['of_id'],
+ 'of2_id' => $params['of2_id'],
+ 'cf_title' => '自有资源',
+ 'admin_id' => $userInfo['admin_id'],
+ 'status' => 1,//到店
+ 'a_num' => 1,//到店次数
+ 'dt_time' => $date,//到店时间
+ 'cont_time' => $date,//最后联系时间
+ 'p_time' => $date,//分配时间
+ 'c_time' => time()
+ ];
+ $c_id = $this->mdCustomers->add($add_data);
+ $log = '创建客户';
+ } else {
+ $c_id = $re_cus['id'];
+ !$re_cus['unionid'] && $up_data['unionid'] = $userInfo['unionid'];
+ $re_cus['status'] == 0 && $up_data['status'] = 1;//改为到店
+ $up_data['a_num = a_num+1'] = null;//加到店次数
+ if ($re_cus['dt_time'] == '0000-00-00 00:00:00') {//首次到店时间
+ $up_data['dt_time'] = $date;
+ }
+ $up_data['cont_time'] = $date;
+ $this->mdCustomers->update($up_data, ['id' => $c_id]);
+ $log = '到店+1';
+ }
+ $this->load->library('receiver/customers_entity');
+ $this->customers_entity->add_log($c_id, $userInfo['admin_id'], $userInfo['admin_name'], $log);
+ //客户标签
+ if ($params['taglList']) {
+ $this->load->model('receiver/receiver_customer_tagdata_model', 'mdCustomerTagdata');
+ $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);
+ }
+ }
+ $this->show_json(200, '操作成功');
+ }
+
+ /**
+ * Notes:保存用户信息
+ * Created on: 2022/3/27 0:55
+ * Created by: dengbw
+ */
+ public function post_user()
+ {
+ $params = $this->input->post();
+ $userInfo = $params['userInfo'];
+ $this->load->library('wx_qyapi', ['app' => 'lichene']);
+ $remark_mobiles = $userInfo['mobile'] ? [$userInfo['mobile']] : '';
+ $description = $params['of_title'] ? $params['of_title'] : '';
+ if ($description && $params['of2_title']) {
+ $description .= '-' . $params['of2_title'];
+ }
+ //企微备注操作
+ $re_remark = $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'];
+ $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'];
+ }
+ } else {
+ if ($tags_name && in_array($val2['name'], $tags_name)) {//删除标签
+ $remove_tag[] = $val2['qy_id'];
+ }
+ }
+ }
+ }
+ }
+ //企微标签操作
+ $re_tag = $this->wx_qyapi->get_external_contact(['url' => 'mark_tag', 'userid' => $userInfo['userid'],
+ 'external_userid' => $userInfo['external_userid'], 'add_tag' => $add_tag, 'remove_tag' => $remove_tag]);
+ $c_id = $userInfo['c_id'];
+ if ($c_id) {//已存在客户,更新资料
+ $this->load->library('receiver/customers_entity');
+ $this->load->model('receiver/receiver_customers_model', 'mdCustomers');
+ $this->load->model('receiver/receiver_customer_tagdata_model', 'mdCustomerTagdata');
+ $up_data = [ 'of_id' => $params['of_id'], 'of2_id' => $params['of2_id']];
+ $this->mdCustomers->update($up_data, ['id' => $c_id]);
+ $this->customers_entity->add_log($c_id, $userInfo['admin_id'], $userInfo['admin_name'], '修改用户基本信息');
+ if ($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);
+ }
+ }
+ }
+ if ($re_remark || $re_tag['errcode'] == 0) {
+ $this->show_json(200, '操作成功');
+ } else {
+ $this->show_json(400, '操作失败');
+ }
+ }
+
private function show_json($code, $msg, $info = [])
{
$data['code'] = $code;
diff --git a/home/views/h5/lichene/index.php b/home/views/h5/lichene/index.php
index f063d0c7..e793d742 100644
--- a/home/views/h5/lichene/index.php
+++ b/home/views/h5/lichene/index.php
@@ -13,6 +13,7 @@
+