diff --git a/api/controllers/wxapp/licheb/Customers.php b/api/controllers/wxapp/licheb/Customers.php
index 0abee329..8b0a4f50 100644
--- a/api/controllers/wxapp/licheb/Customers.php
+++ b/api/controllers/wxapp/licheb/Customers.php
@@ -16,12 +16,10 @@ class Customers extends Wxapp
function __construct($inputs, $app_key)
{
parent::__construct($inputs, $app_key);
-
$this->login_white = array();//登录白名单
$this->check_status = array();//用户状态校验
$this->check_mobile = array();//需要手机号
$this->check_headimg = array();//授权微信信息
-
$this->load->model('receiver/receiver_customers_model', 'customers_model');
$this->load->model('receiver/receiver_customer_oplogs_model', 'customer_oplogs_model');
$this->load->model('receiver/receiver_customer_tag_model', 'mdCustomerTag');
@@ -32,7 +30,7 @@ class Customers extends Wxapp
$this->load->model('auto/auto_brand_model');
$this->load->model('auto/auto_attr_model');
$this->load->model("biz/biz_model");
- $this->biz_id = $this->session['new_biz_id'] ? $this->session['new_biz_id'] : intval($this->session['biz_id']);
+ $this->biz_id = $this->get_biz_id();
}
protected function get()
@@ -73,7 +71,7 @@ class Customers extends Wxapp
'is_top' => $row['is_top'],
'status' => $row['status'],
'other_data' => $other_data,
- 'is_weChat' => $row['unionid'] ? true : false,
+ 'is_weChat' => $row['wxqy'] == 1 ? true : false,
'generate_order' => $this->myuid == $row['admin_id'] ? true : false,
'level' => $row['level'],
'tags' => $tags
@@ -108,25 +106,28 @@ class Customers extends Wxapp
protected function get_tag()
{
$id = intval($this->input_param('id'));
- $show = $res_td = [];
- $res = $this->mdCustomerTag->select(['status' => 1, 'pid' => 0, 'show<>' => 1], 'sort desc,id desc', 0, 0, 'id,name,type');
- if ($res) {
- if ($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')) : '';
- foreach ($res as $key => $val) {
- $list = [];
- $res2 = $this->mdCustomerTag->select(['status' => 1, 'pid' => $val['id']], 'sort desc,id desc', 0, 0, 'id,name');
- foreach ($res2 as $key2 => $val2) {
- //检查是否选中标签
- $checked = $tag_data && in_array($val2['id'], $tag_data) ? true : false;
- $list[] = ['id' => $val2['id'], 'name' => $val2['name'], 'checked' => $checked];
+ $tags = $res_td = [];
+ $re_biz = $this->biz_model->get(['id' => $this->biz_id, 'status' => 1], 'type');
+ if ($re_biz['type'] != 5) {//异业店不显示客户标签
+ $res = $this->mdCustomerTag->select(['status' => 1, 'pid' => 0, 'show<>' => 1], 'sort desc,id desc', 0, 0, 'id,name,type');
+ if ($res) {
+ if ($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')) : '';
+ foreach ($res as $key => $val) {
+ $list = [];
+ $res2 = $this->mdCustomerTag->select(['status' => 1, 'pid' => $val['id']], 'sort desc,id desc', 0, 0, 'id,name');
+ foreach ($res2 as $key2 => $val2) {
+ //检查是否选中标签
+ $checked = $tag_data && in_array($val2['id'], $tag_data) ? true : false;
+ $list[] = ['id' => $val2['id'], 'name' => $val2['name'], 'checked' => $checked];
+ }
+ $tags[] = ['id' => $val['id'], 'name' => $val['name'], 'type' => $val['type'], 'list' => $list];
}
- $show[] = ['id' => $val['id'], 'name' => $val['name'], 'type' => $val['type'], 'list' => $list];
}
}
- return $show;
+ return $tags;
}
//修改基本信息
@@ -284,6 +285,10 @@ class Customers extends Wxapp
'status' => $status,
'c_time' => time()
];
+ $re_biz = $this->biz_model->get(['id' => $this->biz_id, 'status' => 1], 'type');
+ if ($re_biz['type'] == 5) {//异业店
+ $add_data['cf_clues'] = '异业店';
+ }
if ($status == 1) {//到店客户 到店次数默认1
$add_data['a_num'] = 1;
$add_data['dt_time'] = $time;
@@ -653,7 +658,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,if_defeat
- ,of_id,of2_id,unionid,status,biz_id';
+ ,of_id,of2_id,wxqy,status,biz_id';
$rows = $this->customers_model->select($where, $orderby, $page, $size, $fileds);
//获取管理员
$admin_arr = array_unique(array_column($rows, 'admin_id'));
@@ -705,7 +710,7 @@ class Customers extends Wxapp
'defeat' => $defeat,
'orders_pay' => $orders_pay,
'group_id' => $group_id,
- 'is_weChat' => $val['unionid'] ? true : false,
+ 'is_weChat' => $val['wxqy'] == 1 ? true : false,
'allot' => $allot,
'tip' => $tip,
'level' => $val['level'],
diff --git a/common/libraries/Wx_qyapi.php b/common/libraries/Wx_qyapi.php
index 9a82420b..b6453697 100644
--- a/common/libraries/Wx_qyapi.php
+++ b/common/libraries/Wx_qyapi.php
@@ -43,13 +43,18 @@ class Wx_qyapi
$configs = array(
//狸车新能源
'lichene' => array(
- 'corpid' => 'wwff2d727ce47d6852',
- 'corpsecret' => 'wXAdJr6WgMnN6myPC73gXyxyHWpqwiI7dDaN21OAWV0',
+ 'corpid' => 'wwff2d727ce47d6852',//企业ID
+ 'corpsecret' => 'wXAdJr6WgMnN6myPC73gXyxyHWpqwiI7dDaN21OAWV0',//企业密钥
),
//狸车
'liche' => array(
- 'corpid' => 'wwc2caba960d202087',//企业ID
- 'corpsecret' => 'aQ2yhOBTXZnM0iwFtBzYIWbtyq4wFaIXBYTKg3xFxas',//企业密钥
+ 'corpid' => 'wwc2caba960d202087',
+ 'corpsecret' => 'aQ2yhOBTXZnM0iwFtBzYIWbtyq4wFaIXBYTKg3xFxas',
+ ),
+ //异业店_凯利之星
+ 'diff_133' => array(
+ 'corpid' => 'ww0fb634daed56031e',
+ 'corpsecret' => 'ho5SeDUuoZ2TgkzJJt_mEtLaJW_eYXW_drLmibNmbZU',
),
);
$params['corpid'] && $this->corpid = $params['corpid'];
@@ -187,7 +192,6 @@ 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,
@@ -195,7 +199,7 @@ class Wx_qyapi
"url" => $url,
"signature" => $signature,
"rawString" => $string,
- //"access_token" => $access_token,
+ //"access_token" => $this->access_token(),
'jsapi_ticket' => $jsapiTicket
);
return $signPackage;
diff --git a/common/libraries/Wx_qyapi_agent.php b/common/libraries/Wx_qyapi_agent.php
index 42a25129..3094ff87 100644
--- a/common/libraries/Wx_qyapi_agent.php
+++ b/common/libraries/Wx_qyapi_agent.php
@@ -49,6 +49,12 @@ class Wx_qyapi_agent
'corpsecret' => 'OD30gLu3BHTYnTPDre4z2tuPr3rocMcMpIBLZaZG_0c',
'agentid' => 1000024
),
+ //异业店_凯利之星_客户画像
+ 'diff_133_1000004' => array(
+ 'corpid' => 'ww0fb634daed56031e',
+ 'corpsecret' => 'v-OCOKbBBd6FGiazrETTDO03Fz-2XF73aECYfOQpahc',
+ 'agentid' => 1000004
+ ),
);
$params['corpid'] && $this->corpid = $params['corpid'];
$params['corpsecret'] && $this->corpsecret = $params['corpsecret'];
@@ -101,7 +107,6 @@ class Wx_qyapi_agent
// 这里参数的顺序要按照 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,
@@ -109,7 +114,7 @@ class Wx_qyapi_agent
"url" => $url,
"signature" => $signature,
"rawString" => $string,
- //"access_token" => $access_token,
+ //"access_token" => $this->access_token(),
'jsapi_ticket' => $jsapiTicket,
"agentid" => $this->agentid
);
diff --git a/common/models/biz/Biz_model.php b/common/models/biz/Biz_model.php
index 319f614b..c2e3f382 100755
--- a/common/models/biz/Biz_model.php
+++ b/common/models/biz/Biz_model.php
@@ -21,50 +21,52 @@ class Biz_model extends HD_Model
* 根据id获取数据
* @param array() $ids
*/
- public function get_map_by_ids($ids,$fileds=''){
+ public function get_map_by_ids($ids, $fileds = '')
+ {
$rows = [];
$ids = array_filter($ids);
- if($ids){
- $cf_ids = implode(',',$ids);
+ if ($ids) {
+ $cf_ids = implode(',', $ids);
$where = [
"id in ($cf_ids)" => null
];
- $rows = $this->map('id','',$where,'','','',$fileds);
+ $rows = $this->map('id', '', $where, '', '', '', $fileds);
}
return $rows;
}
/**
* id数组获取门店
- * @param array() $ids
- * @param string $fileds
+ * @param array() $ids
+ * @param string $fileds
* @return array()
*/
- public function get_by_id_arr($ids_arr,$o_where,$fileds='id,biz_name'){
+ public function get_by_id_arr($ids_arr, $o_where, $fileds = 'id,biz_name')
+ {
$bizs = [];
- $ids = implode(',',$ids_arr);
- if($ids){
+ $ids = implode(',', $ids_arr);
+ if ($ids) {
$where = [
"id in ($ids)" => null,
"status" => 1
];
- is_array($o_where) && $where = array_merge($where,$o_where);
- $bizs = $this->biz_model->select($where,'',0,0,$fileds);
+ is_array($o_where) && $where = array_merge($where, $o_where);
+ $bizs = $this->biz_model->select($where, '', 0, 0, $fileds);
}
return $bizs;
}
+
/**
* 获取类型
* @param null $key
* @return mixed
*/
- function type_ary($key = null){
+ function type_ary($key = null)
+ {
$map = array('1' => '品牌店', '2' => '合伙店', '3' => '代理店', '4' => '合作店');
-
- if(!is_null($key)){
+ if (!is_null($key)) {
return $map[$key];
}
-
return $map;
}
@@ -75,12 +77,13 @@ class Biz_model extends HD_Model
* @param $page int 页码
* @param $size int 分页大小
*/
- public function nearby($lat,$lng,$page=1,$size=20,$filed='*' ){
+ public function nearby($lat, $lng, $page = 1, $size = 20, $filed = '*')
+ {
$lat = (float)$lat;
$lng = (float)$lng;
- $where = "status=1 and lat>0 and lng>0";
+ $where = "status=1 and lat>0 and lng>0";
- if($page){
+ if ($page) {
$offset = ($page - 1) * $size;
$limit = $size;
}
diff --git a/home/controllers/h5/Different.php b/home/controllers/h5/Different.php
new file mode 100644
index 00000000..27debe75
--- /dev/null
+++ b/home/controllers/h5/Different.php
@@ -0,0 +1,470 @@
+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"];
+ } else {
+ $this->show_json(400, '参数错误~');
+ }
+ $this->load->library('wx_qyapi', $this->config_qyapi);
+ $this->secret = "different_h5_" . $this->config_qyapi_agent['app'];
+ $this->load->helper('cookie');
+ $ukey = get_cookie('ukey');
+ if ($ukey) {
+ $this->session = json_decode(liche_authcode($ukey, 'DECODE', $this->secret), true);
+ $this->userid = $this->session['userid'];
+ }
+ //重置cookie
+ $reset = $this->input->get('reset');
+ if ($reset) {
+ set_cookie("ukey", "", 86400 * 1);
+ $this->session = [];
+ $this->userid = '';
+ }
+ }
+
+ /**
+ * Notes:客户画像
+ * https://liche-dev.xiaoyu.com/h5/different
+ * https://www.liche.cn/h5/different
+ * Created on: 2022/3/25 11:19
+ * Created by: dengbw
+ */
+ public function index()
+ {
+ $this->load->library('wx_qyapi_agent', $this->config_qyapi_agent);
+ $params = $this->input->get();
+ $url = http_host_com('home') . "/h5/different?aid={$params['aid']}";
+ $this->set_auth($url, $params);
+ //print_r($this->session);
+ //echo '
';
+ $sign_package = $this->wx_qyapi->getSignPackage();
+ //print_r($sign_package);
+ //echo '
';
+ $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];
+ $this->load->view('/h5/different/index', $data);
+ }
+
+ /**
+ * Notes:获取用户信息
+ * Created on: 2022/3/27 0:55
+ * Created by: dengbw
+ */
+ 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'];
+ if (!$userid) {
+ $this->show_json(400, '加载企业成员失败请重试~');
+ }
+ if (!$params['external_userid']) {
+ $this->show_json(400, '加载失败请重试~');
+ }
+ //外部联系人
+ $re = $this->wx_qyapi->get_external_contact(array('url' => 'get', 'external_userid' => $params['external_userid']));
+ if ($re['errcode'] != 0) {
+ $this->show_json(400, '加载失败请重试!');
+ }
+ $follow_user = $qy_user = [];
+ $qy_user['external_contact'] = $re['external_contact'];
+ foreach ($re['follow_user'] as $key => $val) {
+ if ($val['userid'] == $userid) {//找出当前企业员工
+ $follow_user = $val;
+ $qy_user['follow_info'] = $val;
+ break;
+ }
+ }
+ $tags_ary = $follow_user['tags'];//客户画像
+ $remark_mobiles = $follow_user['remark_mobiles'];//用户手机
+ $description = $follow_user['description'];//描述
+ 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'];
+ }
+ }
+ }
+ $avatar = $mobile = $name = $unionid = '';
+ $gender = $biz_id = 0;
+ 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, 'remark_mobile' => $mobile, 'name' => $name, 'gender' => $gender, 'source' => '@微信'
+ , 'unionid' => $unionid, 'external_userid' => $params['external_userid'], 'userid' => $userid, 'tags_name' => $tags_name
+ ];
+ if ($this->session['biz_id']) {
+ $biz_id = intval($this->session['biz_id']);
+ $userInfo['biz_id'] = $biz_id;
+ $userInfo['uid'] = $this->session['uid'];
+ $userInfo['uname'] = $this->session['uname'];
+ }
+ 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'];
+ $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->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 && $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) {
+ $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) {
+ //检查是否选中标签
+ $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;
+ }
+ $list[] = $setValue;
+ }
+ $tagList[] = ['id' => $val['id'], 'name' => $val['name'], 'type' => $val['type'], 'list' => $list];
+ }
+ }
+ //线索来源
+ $status = 0;
+ $offline_sources = $this->mdCustomers->offlineSources();
+ 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;
+ $data['buddy_type'] = $buddy_type;
+ $data['buddyTypeAry'] = $this->mdCustomers->buddyTypeAry();
+ $this->show_json(200, '获取用户信息成功', $data);
+ }
+
+ /**
+ * Notes:保存用户信息
+ * Created on: 2022/4/27 0:55
+ * Created by: dengbw
+ */
+ public function post_user()
+ {
+ $params = $this->input->post();
+ $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');
+ $uid = $userInfo['uid'];
+ $uname = $userInfo['uname'];
+ $c_id = $userInfo['c_id'];
+ $result = $re_cus = '';
+ 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, '客户不存在');
+ }
+ $re_cus2['wxqy'] != 1 && $up_data['wxqy'] = 1;
+ !$re_cus2['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 {
+ if ($mobile && $biz_id) {//有手机号查找客户是否已存在
+ $re_cus = $this->mdCustomers->get(['biz_id' => $biz_id, 'mobile' => $mobile, 'status<>' => -1]);
+ if ($re_cus) {//已存客户绑定操作,不带入现有标签中
+ $up_data = ['wxqy' => 1];
+ $userInfo['unionid'] && $up_data['unionid'] = $userInfo['unionid'];
+ $result = $this->mdCustomers->update($up_data, ['id' => $re_cus['id']]);
+ } else {//创建新客户
+ $this->load->model("biz/biz_model", 'mdBiz');
+ $re_biz = $this->mdBiz->get(['id' => $biz_id, 'status' => 1]);
+ $city_id = intval($re_biz['city_id']);
+ $county_id = intval($re_biz['county_id']);
+ $date = date('Y-m-d H:i:s');
+ $add_data = [
+ 'name' => $userInfo['name'],
+ 'mobile' => $mobile,
+ 'biz_id' => $biz_id,
+ 'city_id' => $city_id,
+ 'county_id' => $county_id,
+ 'unionid' => $userInfo['unionid'],
+ 'wxqy' => 1,
+ 'of_id' => $params['of_id'],
+ 'of2_id' => $params['of2_id'],
+ 'buddy_type' => $params['buddy_type'],
+ 'cf_title' => '自有资源',
+ 'cf_clues' => '企微私域',
+ 'admin_id' => $uid,
+ 'status' => 0,//未见客户
+ 'p_time' => $date,//分配时间
+ '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');
+ 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, '创建客户档案', 3);
+ }
+ }
+ }
+ }
+ //客户标签操作
+ 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']]);
+ $up_qy && $result = true;
+ //企微操作
+ $remark_mobiles = $userInfo['mobile'] ? [$userInfo['mobile']] : '';
+ $description = $params['of_title'] ? $params['of_title'] : '';
+ if ($description && $params['of2_title']) {
+ $description .= '-' . $params['of2_title'];
+ }
+ //企微备注操作
+ $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'];
+ }
+ }
+ }
+ }
+ }
+ if ($add_tag || $remove_tag) {
+ $result = true;
+ $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]);
+ }
+ if ($re_cus) {
+ $this->show_json(200, '已有同事在跟进该客户');
+ }
+ if ($result) {
+ $this->show_json(200, '保存成功');
+ } else {
+ $this->show_json(400, '保存失败');
+ }
+ }
+
+ /**
+ * 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(
+ '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(['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:授权获取企业员工UserId
+ * Created on: 2022/3/29 17:03
+ * Created by: dengbw
+ * @param string $url
+ * @param array $params
+ * @return mixed
+ */
+ private function set_auth($url = '', $params = array())
+ {
+ if ($this->userid) {
+ return;
+ }
+ $config = $this->wx_qyapi_agent->getConfig();
+ $code = $params['code'];
+ if ($code) {//授权码获取微信信息
+ $this->load->library('mycurl');
+ $access_token = $this->wx_qyapi_agent->access_token();
+ //获取访问用户身份 https://developer.work.weixin.qq.com/document/path/91023
+ $auth_url = "https://qyapi.weixin.qq.com/cgi-bin/user/getuserinfo?access_token={$access_token}&code={$code}";
+ $res = $this->mycurl->httpGet($auth_url);
+ $res = $res ? json_decode($res, true) : [];
+ if ($res && $res['errcode'] == 0 && $res['user_ticket']) {
+ //获取访问用户敏感信息 https://developer.work.weixin.qq.com/document/path/95833
+ $auth_url = "https://qyapi.weixin.qq.com/cgi-bin/user/getuserdetail?access_token={$access_token}";
+ $res_detail = $this->mycurl->httpPost($auth_url, ['user_ticket' => $res['user_ticket']], 'is_json');
+ $res_detail = $res_detail ? json_decode($res_detail, true) : [];
+ if ($res_detail && $res_detail['errcode'] == 0 && $res_detail['mobile']) {
+ $session = ['userid' => $res_detail['userid']];
+ $expire = 86400 * 1;
+ $this->load->model('app/licheb/App_licheb_users_model', 'mdUsers');
+ $re_user = $this->mdUsers->get(['mobile' => $res_detail['mobile']]);
+ if ($re_user) {
+ if (!$re_user['userid'] || $re_user['userid'] != $res_detail['userid']) {
+ $this->mdUsers->update(['userid' => $res_detail['userid']], ['id' => $re_user['id']]);
+ }
+ $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;
+ }
+ $ukey = liche_authcode(json_encode($session, JSON_UNESCAPED_UNICODE), 'ENCODE', $this->secret);
+ set_cookie("ukey", $ukey, $expire);
+ $this->session = $session;
+ }
+ }
+ } else {//构造网页授权链接 https://developer.work.weixin.qq.com/document/path/91022
+ $this->load->helper('url');
+ $redirect_uri = urlencode($url);
+ //静默授权
+ //$auth_url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid={$config['corpid']}&redirect_uri={$redirect_uri}&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect";
+ //手动授权
+ $auth_url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid={$config['corpid']}&redirect_uri={$redirect_uri}&response_type=code&scope=snsapi_privateinfo&state=STATE&agentid={$config['agentid']}#wechat_redirect";
+ redirect($auth_url);
+ }
+ }
+
+ private function show_json($code, $msg, $info = [])
+ {
+ $data['code'] = $code;
+ $data['msg'] = $msg;
+ $data['data'] = $info;
+ die(json_encode($data, JSON_UNESCAPED_UNICODE));
+ }
+}
diff --git a/home/views/h5/different/index.php b/home/views/h5/different/index.php
new file mode 100644
index 00000000..50e99424
--- /dev/null
+++ b/home/views/h5/different/index.php
@@ -0,0 +1,263 @@
+
+
+