lichene_325

This commit is contained in:
dengbw
2022-03-28 13:41:01 +08:00
parent efa4154a13
commit 8847490cf7
8 changed files with 564 additions and 104 deletions
+2 -2
View File
@@ -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 {
+3 -1
View File
@@ -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
];
}
+13 -11
View File
@@ -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&timestamp=$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;
+133
View File
@@ -0,0 +1,133 @@
<?php
/**
* Created by Vim
* User: Lcc
* Date: 2020-12-25
* Time: 10:23
* Desc: 企业微信api
*/
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 $ci;
private $access_token;
private $log_file = 'wx_qyapi_agent.log';
private $env;
public function __construct($params = array())
{
//获取环境
if (false !== strpos($_SERVER['HTTP_HOST'], 'dev')) { //dev 测试
$this->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&timestamp=$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;
}
}
?>
+272 -11
View File
@@ -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 '<br><br>';
//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;
+140 -79
View File
@@ -13,6 +13,7 @@
<script type="text/javascript" src="https://qs.haodian.cn/web/javascript/qs.js"></script>
<script type="text/javascript" src="https://qs.haodian.cn/web/javascript/mDialog.js"></script>
<script src="https://res.wx.qq.com/open/js/jweixin-1.2.0.js"></script>
<script src="https://open.work.weixin.qq.com/wwopen/js/jwxwork-1.0.0.js"></script>
</head>
<body class="bg-f7">
@@ -21,28 +22,29 @@
<div class="inner30">
<div class="inner30 bg-fff ulib-r10">
<div class="relative">
<img class="block imgsize-90X90 ulib-r5" :src="userInfo.headimg" alt="#"/>
<img class="block imgsize-90X90 ulib-r5" :src="userInfo.avatar" alt="#"/>
<div class="absolute pl100 box-middle font-30">
<span class="text-middle">{{userInfo.nickname}}</span>
<i class="text-middle iconfont icon-nanxing color-2b78f5" v-if="userInfo.sex==1"></i>
<i class="text-middle iconfont icon-nvshangjia color-fb3aab" v-if="userInfo.sex==2"></i>
<span class="text-middle">{{userInfo.name}}</span>
<i class="text-middle iconfont icon-nanxing color-2b78f5" v-if="userInfo.gender==0"></i>
<i class="text-middle iconfont icon-nvshangjia color-fb3aab" v-if="userInfo.gender==1"></i>
<span class="text-middle color-36b229">{{userInfo.source}}</span>
</div>
<div class="absolute right-0 box-middle bg-3f91fd font-30 color-fff pt15 pb15 pl30 pr30 ulib-r10">
到店
</div>
<button :class="'absolute right-0 box-middle btn pt15 pb15 pl30 pr30 text-center font-30 color-fff ulib-r10 ' + [submitFlag?'bg-b5':'bg-3f91fd']"
:disabled="submitFlag" @click="postToBiz()">到店
</button>
</div>
<!-- <div class="bg-f7 mt30 pt20 pb20 pl30 pr30 font-30 color-2b78f5 ulib-r10">点击关联企业</div> -->
<div class="mt20 pl140 relative bbs-1-eee last-b-none">
<div class="absolute left-0 box-middle font-28 color-666">手机号</div>
<input class="wp100 pl20 pr20 pt30 pb30 font-28 bds-1-ddd bds-none text-right" type="tel"
<div v-if="userInfo.c_id" class="pt10 pb10 text-right font-28">{{userInfo.mobile}}</div>
<input v-else class="wp100 pl20 pr20 pt30 pb30 font-28 bds-1-ddd bds-none text-right" type="tel"
placeholder="请输入客户手机号" v-model="userInfo.mobile"/>
</div>
<div class="mt20 pl140 relative bbs-1-eee last-b-none">
<div class="absolute left-0 box-middle font-28 color-666">线索来源</div>
<div class="pt10 pb10 text-right">
<select :class="'bds-none font-28 bg-fff ' + [of_id == 0 ? 'color-ccc' : 'color-333']"
v-model="of_id" @change="changeOf1">
v-model="of_id" @change="changeOf1" id="id-of_id">
<option :value="0">请选择</option>
<option :value="item.id" v-for="item in sources">{{item.name}}</option>
</select>
@@ -53,7 +55,7 @@
<div class="absolute left-0 box-middle font-28 color-666">{{sources[of_id_index].name}}</div>
<div class="pt10 pb10 text-right">
<select :class="'bds-none font-28 bg-fff ' + [of2_id == 0 ? 'color-ccc' : 'color-333']"
v-model="of2_id">
v-model="of2_id" id="id-of2_id">
<option :value="0">请选择</option>
<option :value="item.id" v-for="item in sources[of_id_index].list">{{item.name}}</option>
</select>
@@ -85,7 +87,7 @@
<div class="pt50 pb50 pl60 pr60">
<button :class="'wp100 btn pt30 pb30 text-center font-32 color-fff ulib-r750 ' + [submitFlag?'bg-b5':'bg-3f91fd']"
:disabled="submitFlag" @click="postbaseinfo()">确认保存
:disabled="submitFlag" @click="postUser()">确认保存
</button>
</div>
@@ -94,18 +96,13 @@
</div>
<script>
var loading = mDialog.load({shade: false, text: "",});
let hostUrl = ''
var app = new Vue({
el: '#app',
data: {
submitFlag: false,
userInfo: {
headimg: "https://thirdwx.qlogo.cn/mmopen/vi_32/Q0j4TwGTfTL6WOjISfSibY4gSp9RTbkUOYsrxwyOClnExCvLzVEoFt6KWvadiabGTQd0ib5ttz43USVPQq20qiaNDQ/132",
mobile: "15359333658",
nickname: "老叶",
sex: 1,//1男、/2女
source: '@微信',
},
userInfo: {avatar: '/img/h5/avatar.png', c_id: 0},
taglList: [],
of_id_index: -1,
of_id: 0,
@@ -117,31 +114,8 @@
},
computed: {},
mounted() {
this.getUser();
},
methods: {
getUser() {
let that = this;
$.ajax({
url: '/h5/lichene/get_user',
type: 'post',
dataType: 'json',
data: {
id: 1
},
beforeSend: function () {
},
success: function (re) {
if (re.code == 200) {
that.taglList = re.data['tagList'];
that.sources = re.data['sources'];
}
},
complete: function () {
}
});
},
//选择一级线索来源
changeOf1() {
if (this.of_id > 0) {
@@ -155,34 +129,105 @@
this.of_id_index = -1;
}
},
//提交基础数据
postbaseinfo() {
let that = this
mDialog.load()
let params = {};
if (that.userInfo.mobile) {
params['mobile'] = that.userInfo.mobile;
//获取用户信息
getUser(external_userid) {
let that = this;
$.ajax({
url: '/h5/lichene/get_user',
type: 'get',
dataType: 'json',
data: {
external_userid: external_userid
},
beforeSend: function () {
},
success: function (re) {
if (re.code == 200) {
that.taglList = re.data['tagList'];
that.sources = re.data['sources'];
that.userInfo = re.data['userInfo'];
that.of_id = re.data['of_id'];
that.of2_id = re.data['of2_id'];
that.of_id_index = re.data['of_id_index'];
} else {
mDialog.msg({content: re.msg});
}
},
complete: function () {
loading && mDialog.close(loading); //关闭加载
}
});
},
//到店
postToBiz() {
let that = this;
if (!that.userInfo.mobile) {
mDialog.msg({content: "请输入手机号"});
return
}
if (that.of_id != 0) {
params['of_id'] = that.of_id;
if (!/^1[3456789]\d{9}$/.test(that.userInfo.mobile)) {
mDialog.msg({content: "请输入正确手机号"});
return
}
if (that.of2_id != 0) {
params['of2_id'] = that.of2_id;
$.ajax({
url: '/h5/lichene/post_to_biz',
type: 'post',
dataType: 'json',
data: {
userInfo: that.userInfo,
taglList: that.taglList,
of_id: that.of_id,
of2_id: that.of2_id,
},
beforeSend: function () {
loading = mDialog.load({
shade: false,
text: "",
});
that.submitFlag = true;
},
success: function (re) {
mDialog.msg({content: re.msg});
},
complete: function () {
loading && mDialog.close(loading); //关闭加载
that.submitFlag = false;
}
});
},
//保存
postUser() {
let that = this;
if (!that.userInfo.userid || !that.userInfo.external_userid) {
mDialog.msg({content: "保存失败"});
return
}
params['tag'] = that.taglList;
// axios({
// method: 'post',
// url: 'https://liche.cn/chechedai/api/kehulist.php',
// transformRequest: [function (data) {
// // 对 data 进行任意转换处理
// return Qs.stringify(data)
// }],
// responseType: 'json',
// data: params,
// }).then(function (res) {
// mDialog.closeAll()
// })
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/lichene/post_user',
type: 'post',
dataType: 'json',
data: {
userInfo: that.userInfo,
taglList: that.taglList,
of_id: that.of_id,
of2_id: that.of2_id,
of_title: of_title,
of2_title: of2_title,
},
beforeSend: function () {
loading = mDialog.load({shade: false, text: "",});
that.submitFlag = true;
},
success: function (re) {
mDialog.msg({content: re.msg, pause: 8000});
},
complete: function () {
loading && mDialog.close(loading); //关闭加载
that.submitFlag = false;
}
});
},
//单选
radioPicker(i, j) {
@@ -201,26 +246,42 @@
});
wx.config({
beta: true,// 必须这么写,否则wx.invoke调用形式的jsapi会有问题
debug: true, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
appId: "<?=$sign_package['appId']?>", // 必填,企业微信的corpID
timestamp:"<?=$sign_package['timestamp']?>", // 必填,生成签名的时间戳
timestamp: "<?=$sign_package['timestamp']?>", // 必填,生成签名的时间戳
nonceStr: "<?=$sign_package['nonceStr']?>", // 必填,生成签名的随机串
signature: "<?=$sign_package['signature']?>",// 必填,签名,见 附录-JS-SDK使用权限签名算法
jsApiList: ["invoke"] // 必填,需要使用的JS接口列表,凡是要调用的接口都需要传进来
jsApiList: ["agentConfig"] // 必填,需要使用的JS接口列表,凡是要调用的接口都需要传进来
});
wx.ready(function(){
wx.invoke('getContext', {}, function(res){
console.log(res);
if(res.err_msg == "getContext:ok"){
entry = res.entry ; //返回进入H5页面的入口类型,目前有normal、contact_profile、single_chat_tools、group_chat_tools、chat_attachment
shareTicket = res.shareTicket; //可用于调用getShareInfo接口
}else {
//错误处理
wx.ready(function () {
wx.agentConfig({
corpid: "<?=$sign_package2['appId']?>",
agentid: "<?=$sign_package2['agentid']?>",
timestamp: "<?=$sign_package2['timestamp']?>",
nonceStr: "<?=$sign_package2['nonceStr']?>",
signature: "<?=$sign_package2['signature']?>",
jsApiList: ['getCurExternalContact', "invoke"],
success: function (res) {
wx.invoke('getCurExternalContact', {}, function (res) {
if (res.err_msg == "getCurExternalContact:ok") {
app.getUser(res.userId);//返回当前外部联系人userId
//mDialog.msg({content: "userId=" + userId});
} else {
loading && mDialog.close(loading); //关闭加载
}
});
},
fail: function (res) {
loading && mDialog.close(loading); //关闭加载
//var json = JSON.stringify(res);
//mDialog.msg({content: "agentConfig_fail=" + json});
if (res.errMsg.indexOf('function not exist') > -1) {
mDialog.msg({content: "版本过低请升级"});
}
}
});
});
wx.error(function(res){
wx.error(function (res) {
});
</script>
</body>
+1
View File
@@ -0,0 +1 @@
R9RF2Dg5N4r5SCCc
Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB