584 lines
27 KiB
PHP
584 lines
27 KiB
PHP
<?php
|
|
defined('BASEPATH') OR exit('No direct script access allowed');
|
|
|
|
/**
|
|
* Notes:客户画像
|
|
* Created on: 2022/3/28 11:19
|
|
* Created by: dengbw
|
|
*/
|
|
class Persona extends CI_Controller
|
|
{
|
|
private $config_qyapi;
|
|
private $config_qyapi_agent;
|
|
private $aid;
|
|
|
|
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 == 1) {
|
|
$this->config_qyapi = ['app' => 'liche'];
|
|
$this->config_qyapi_agent = ['app' => 'liche_1000024'];
|
|
} else {
|
|
$this->config_qyapi = ['app' => 'lichene'];
|
|
$this->config_qyapi_agent = ['app' => 'lichene_1000005'];
|
|
}
|
|
$this->load->library('wx_qyapi', $this->config_qyapi);
|
|
}
|
|
|
|
/**
|
|
* Notes:客户画像
|
|
* https://liche-dev.xiaoyu.com/h5/persona
|
|
* https://www.liche.cn/h5/persona
|
|
* 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/persona?aid={$params['aid']}";
|
|
$result = $this->set_auth($url, $params);
|
|
$user_id = 0;
|
|
if ($result['errcode'] == 0 && $result['UserId']) {//获取企业员工userid
|
|
$user_id = $result['UserId'];
|
|
}
|
|
$sign_package = $this->wx_qyapi->getSignPackage();
|
|
$sign_package_agent = $this->wx_qyapi_agent->getSignPackage();
|
|
$data = ['_title' => '客户画像', 'sign_package' => $sign_package, 'sign_package_agent' => $sign_package_agent
|
|
, 'user_id' => $user_id, 'aid' => $this->aid];
|
|
$this->load->view('/h5/persona/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']) {
|
|
//外部联系人
|
|
$re = $this->wx_qyapi->get_external_contact(array('url' => 'get', 'external_userid' => $params['external_userid']));
|
|
if (!$re) {
|
|
$this->show_json(400, '加载失败请重试!');
|
|
}
|
|
$follow_user = [];
|
|
foreach ($re['follow_user'] as $key => $val) {
|
|
if ($val['userid'] == $params['user_id']) {//找出当前企业员工
|
|
$follow_user = $val;
|
|
break;
|
|
}
|
|
}
|
|
$tags_ary = $follow_user['tags'];//客户画像
|
|
$userid = $follow_user['userid'];
|
|
$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
|
|
];
|
|
//企业成员
|
|
$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/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');
|
|
$c_id = $userInfo['c_id'];
|
|
$result = '';
|
|
if ($c_id) {//已存在客户,更新资料
|
|
$up_data = ['of_id' => $params['of_id'], 'of2_id' => $params['of2_id']];
|
|
$result = $this->mdCustomers->update($up_data, ['id' => $c_id]);
|
|
$this->customers_entity->add_log($c_id, $userInfo['admin_id'], $userInfo['admin_name'], '修改用户基本信息');
|
|
} else {
|
|
if ($mobile && $biz_id) {//有手机号查找客户是否已存在
|
|
$re_cus = $this->mdCustomers->get(['biz_id' => $biz_id, 'mobile' => $mobile, 'status<>' => -1]);
|
|
if ($re_cus) {//已存客户绑定操作,不带入现有标签中
|
|
$result = $this->mdCustomers->update(['unionid' => $userInfo['unionid']], ['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');
|
|
$admin_id = $userInfo['admin_id'];
|
|
$admin_name = $userInfo['admin_name'];
|
|
$add_data = [
|
|
'name' => $userInfo['name'],
|
|
'mobile' => $mobile,
|
|
'biz_id' => $biz_id,
|
|
'city_id' => $city_id,
|
|
'county_id' => $county_id,
|
|
'unionid' => $userInfo['unionid'],
|
|
'of_id' => $params['of_id'],
|
|
'of2_id' => $params['of2_id'],
|
|
'cf_title' => '自有资源',
|
|
'admin_id' => $admin_id,
|
|
'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, $admin_id, $admin_name, $val['remark'], 8);
|
|
}
|
|
}
|
|
$this->customers_entity->add_log($c_id, $admin_id, $admin_name, '创建客户档案', 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);
|
|
}
|
|
}
|
|
//企微操作
|
|
$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) {
|
|
$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 ($result) {
|
|
$this->show_json(200, '保存成功');
|
|
} else {
|
|
$this->show_json(400, '保存失败');
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
* 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())
|
|
{
|
|
$config = $this->wx_qyapi_agent->getConfig();
|
|
$code = $params['code'];
|
|
if ($code) {//授权码获取微信信息
|
|
$this->load->library('mycurl');
|
|
$access_token = $this->wx_qyapi_agent->access_token();
|
|
$auth_url = "https://qyapi.weixin.qq.com/cgi-bin/user/getuserinfo?access_token={$access_token}&code={$code}";
|
|
$res = $this->mycurl->httpGet($auth_url);
|
|
return json_decode($res, true);
|
|
} else {//静默授权获取用户openid
|
|
$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";
|
|
redirect($auth_url);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Notes:到店(废弃22-4-27)
|
|
* 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');
|
|
$admin_id = $userInfo['admin_id'];
|
|
$admin_name = $userInfo['admin_name'];
|
|
$this->load->library('receiver/customers_entity');
|
|
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' => $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);
|
|
if ($c_id) {//加日志
|
|
$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, $admin_id, $admin_name, $val['remark'], 8);
|
|
}
|
|
}
|
|
$this->customers_entity->add_log($c_id, $admin_id, $admin_name, '创建客户档案', 3);
|
|
$this->customers_entity->add_log($c_id, $admin_id, $admin_name, "客户到店", 4);
|
|
}
|
|
} else {
|
|
$c_id = $re_cus['id'];
|
|
!$re_cus['unionid'] && $up_data['unionid'] = $userInfo['unionid'];
|
|
$log = '客户到店';
|
|
if ($re_cus['status'] == 0) {//改为到店
|
|
$up_data['status'] = 1;
|
|
}
|
|
if ($re_cus['dt_time'] == '0000-00-00 00:00:00') {//首次到店时间
|
|
$up_data['dt_time'] = $date;
|
|
}
|
|
$up_data['a_num = a_num+1'] = null;//加到店次数
|
|
$up_data['cont_time'] = $date;
|
|
$ret = $this->mdCustomers->update($up_data, ['id' => $c_id]);
|
|
if ($ret) {
|
|
$this->customers_entity->add_log($c_id, $admin_id, $admin_name, $log, 4);
|
|
}
|
|
}
|
|
$up_customer_tag = 1;//1更新客户标签
|
|
if (!$re_cus || !$userInfo['remark_mobile']) {//新增客户/首次绑定手机 更新企微信息
|
|
$up_customer_tag = 0;
|
|
$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') {
|
|
$up_customer_tag = 1;
|
|
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) {
|
|
$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 ($params['taglList'] && $up_customer_tag) {
|
|
$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:保存用户信息(废弃22-4-27)
|
|
* Created on: 2022/3/27 0:55
|
|
* Created by: dengbw
|
|
*/
|
|
public function post_user_backup()
|
|
{
|
|
$params = $this->input->post();
|
|
$userInfo = $params['userInfo'];
|
|
// $this->load->library('wx_qyapi', $this->config_qyapi);
|
|
$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'];
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
//企微标签操作
|
|
if ($add_tag || $remove_tag) {
|
|
$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));
|
|
}
|
|
}
|