diff --git a/common/libraries/Wx_qyapi_agent.php b/common/libraries/Wx_qyapi_agent.php
index 7789dce8..88ea1e86 100644
--- a/common/libraries/Wx_qyapi_agent.php
+++ b/common/libraries/Wx_qyapi_agent.php
@@ -9,14 +9,13 @@
*/
class Wx_qyapi_agent
{
-
const BASE_URL = 'https://qyapi.weixin.qq.com/';
const TOKEN_API = 'cgi-bin/gettoken?corpid=%s&corpsecret=%s'; //获取access_token
- const MOBILE_HASHCODE_API = 'cgi-bin/user/get_mobile_hashcode?access_token=%s'; //获取手机号随机串
private $redis;
private $corpid;
private $corpsecret;
+ private $agentid;
private $ci;
private $access_token;
private $log_file = 'wx_qyapi_agent.log';
@@ -46,17 +45,26 @@ class Wx_qyapi_agent
'lichene_1000005' => array(
'corpid' => 'wwff2d727ce47d6852',
'corpsecret' => 'QBkmK9hm1WgrWI9RUE5-Al10qVtHCM2eEoa8NQzTKkI',
- )
+ 'agentid' => 1000005
+ ),
+ //狸车_客户画像
+ 'liche_1000024' => array(
+ 'corpid' => 'wwc2caba960d202087',
+ 'corpsecret' => 'OD30gLu3BHTYnTPDre4z2tuPr3rocMcMpIBLZaZG_0c',
+ 'agentid' => 1000024
+ ),
);
$params['corpid'] && $this->corpid = $params['corpid'];
$params['corpsecret'] && $this->corpsecret = $params['corpsecret'];
+ $params['agentid'] && $this->agentid = $params['agentid'];
$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->agentid && $config['agentid'] && $this->agentid = $config['agentid'];
}
- $this->corpid && $this->log_file = "wx_qyapi_{$this->corpid}.log";
+ $this->corpid && $this->log_file = "wx_qyapi_agent_{$this->corpid}.log";
}
public function access_token()
@@ -94,7 +102,8 @@ class Wx_qyapi_agent
"signature" => $signature,
"rawString" => $string,
//"access_token" => $access_token,
- 'jsapi_ticket' => $jsapiTicket
+ 'jsapi_ticket' => $jsapiTicket,
+ "agentid" => $this->agentid
);
return $signPackage;
}
@@ -130,4 +139,4 @@ class Wx_qyapi_agent
}
}
-?>
+?>
\ No newline at end of file
diff --git a/common/models/receiver/Receiver_customers_model.php b/common/models/receiver/Receiver_customers_model.php
index 7e05b269..3a711f77 100644
--- a/common/models/receiver/Receiver_customers_model.php
+++ b/common/models/receiver/Receiver_customers_model.php
@@ -79,9 +79,10 @@ class Receiver_customers_model extends HD_Model
public function offlineSources($id = 0)
{
$arr[1] = ['name' => '自然到店', 'list' => []];
- $arr[2] = ['name' => '转介绍', 'list' => [20 => '其他4S店', 21 => '其他二网', 22 => '汽车美容', 23 => '二手车'
- , 24 => '修车厂', 25 => '驾校', 26 => '老车主', 27 => '亲朋好友']];
- $arr[3] = ['name' => '网络推广', 'list' => [30 => '抖音', 31 => '区域媒体', 32 => '懂车帝', 33 => '易车', 34 => '汽车之家', 35 => '网红']];
+ $arr[2] = ['name' => '转介绍', 'list' => [20 => '其他4S店', 21 => '其他二网', 22 => '汽车美容', 23 => '二手车',
+ 24 => '修车厂', 25 => '驾校', 26 => '老车主', 27 => '亲朋好友']];
+ $arr[3] = ['name' => '网络推广', 'list' => [30 => '抖音', 31 => '区域媒体', 32 => '懂车帝', 33 => '易车',
+ 34 => '汽车之家', 35 => '网红', 36 => '厂商分配']];
$arr[4] = ['name' => '外展外拓', 'list' => [40 => '巡展', 41 => '车展', 42 => '静展', 43 => '大客户']];
$arr[5] = ['name' => '自媒体', 'list' => [50 => '小红书号', 51 => '咸鱼号', 52 => '抖音号', 53 => '狸车素材', 54 => '知乎号']];
if ($id) {
diff --git a/home/controllers/h5/Persona.php b/home/controllers/h5/Persona.php
new file mode 100644
index 00000000..9da80c58
--- /dev/null
+++ b/home/controllers/h5/Persona.php
@@ -0,0 +1,386 @@
+load->library('wx_qyapi', ['app' => 'lichene']);
+ $sign_package = $this->wx_qyapi->getSignPackage();
+
+ $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');
+ $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) {
+ $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;
+ $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 (!mobile_valid($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);
+ }
+ }
+ if (!$re_cus) {//新增客户 更新企微信息
+ $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'];
+ }
+ //企微备注操作
+ $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'];
+ }
+ }
+ }
+ }
+ }
+ //企微标签操作
+ $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]);
+ }
+ $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;
+ $data['msg'] = $msg;
+ $data['data'] = $info;
+ die(json_encode($data, JSON_UNESCAPED_UNICODE));
+ }
+}