different_627

This commit is contained in:
dengbw
2022-06-27 10:22:26 +08:00
parent 479a15f198
commit 428eebc00b
7 changed files with 799 additions and 48 deletions
+27 -22
View File
@@ -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'],
+10 -6
View File
@@ -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&timestamp=$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;
+7 -2
View File
@@ -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&timestamp=$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
);
+21 -18
View File
@@ -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;
}
+470
View File
@@ -0,0 +1,470 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Notes:客户画像_异业店
* Created on: 2022/3/28 11:19
* Created by: dengbw
*/
class Different extends CI_Controller
{
private $session;
private $secret;
private $userid = '';//企业成员userid
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 == 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 '<br>';
$sign_package = $this->wx_qyapi->getSignPackage();
//print_r($sign_package);
//echo '<br>';
$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));
}
}
+263
View File
@@ -0,0 +1,263 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title><?= $_title ?></title>
<link rel="stylesheet" href="/css/h5/persona/h5.css?v=2">
<script src="https://qs.haodian.cn/web/javascript/jquery.3.4.1.min.js"></script>
<script type="text/javascript" src="https://qs.haodian.cn/web/javascript/vue.2.6.10.min.js"></script>
<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">
<div id="app">
<div class="container">
<div class="inner30 pb220">
<div class="inner30 bg-fff ulib-r10">
<div class="relative">
<img class="block imgsize-90X90 ulib-r5" :src="userInfo.avatar" alt="#"/>
<div class="absolute pl100 box-middle font-30">
<span class="text-middle">{{userInfo.name}}</span>
<i class="text-middle iconfont icon-nanxing color-2b78f5" v-if="userInfo.gender==1"></i>
<i class="text-middle iconfont icon-nvshangjia color-fb3aab" v-if="userInfo.gender==2"></i>
<span class="text-middle color-36b229">{{userInfo.source}}</span>
</div>
</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 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" id="id-of_id">
<option :value="0">请选择</option>
<option :value="item.id" v-for="item in sources">{{item.name}}</option>
</select>
</div>
</div>
<div class="mt20 pl140 relative bbs-1-eee last-b-none"
v-if="of_id_index>-1&&sources[of_id_index].list.length>0">
<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" 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>
</div>
</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 ' + [buddy_type == 0 ? 'color-ccc' : 'color-333']"
v-model="buddy_type">
<option :value="0">请选择</option>
<option :value="i" v-for="(v,i) in buddyTypeAry">{{v}}</option>
</select>
</div>
</div>
</div>
<div class="mt30 inner30 pb50 bg-fff ulib-r10">
<div class="mt20 font-36 text-center text-bold">客户画像_different</div>
<div class="relative mt40" v-for="(list,i) in taglList">
<div class="font-28">
<span class="text-middle">{{list.name}}</span>
<span class="text-middle font-24" v-if="list.type=='radio'">(单选)</span>
<span class="text-middle font-24" v-if="list.type=='checkbox'">(多选)</span>
</div>
<div class="fn-clear" v-if="list.type=='radio'">
<div v-for="(option,j) in list.list"
:class="'inline-block space-nowrap mt20 mr20 pt15 pb15 pl30 pr30 font-22 ulib-r10 ' + [option.checked ? 'bg-3f91fd color-fff' : 'bg-f6 color-666']"
@click="radioPicker(i,j)">{{option.name}}
</div>
</div>
<vdiv class="fn-clear" v-if="list.type=='checkbox'">
<div v-for="(option,j) in list.list"
:class="'inline-block space-nowrap mt20 mr20 pt15 pb15 pl30 pr30 font-22 ulib-r10 ' + [option.checked ? 'bg-3f91fd color-fff' : 'bg-f6 color-666']"
@click="checkPicker(i,j)">{{option.name}}
</div>
</vdiv>
</div>
</div>
<div class="fixed left-0 bottom-0 right-0 bg-fff-op80 pt30 pb50 pl30 pr30">
<button :class="'wp100 btn pt30 pb30 text-center font-32 color-fff ulib-r750 ' + [submitFlag?'bg-b5':'bg-3f91fd']"
:disabled="submitFlag" @click="postUser()">确认保存
</button>
</div>
</div>
</div>
</div>
<script>
var loading = mDialog.load({shade: false, text: "",});
let hostUrl = ''
var app = new Vue({
el: '#app',
data: {
submitFlag: false,
userInfo: {avatar: '/img/h5/avatar.png', c_id: 0},
taglList: [],
of_id_index: -1,
of_id: 0,
of2_id: 0,
sources: [],
aid: <?=$aid?>,
buddy_type:0,
buddyTypeAry: [],
},
created() {
},
computed: {},
mounted() {
},
methods: {
//选择一级线索来源
changeOf1() {
if (this.of_id > 0) {
this.sources.forEach((item, index) => {
if (item.id == this.of_id) {
this.of_id_index = index;
this.of2_id = 0;
}
})
} else {
this.of_id_index = -1;
}
},
//获取用户信息
getUser(external_userid) {
let that = this;
$.ajax({
url: '/h5/persona/get_user',
type: 'get',
dataType: 'json',
data: {
external_userid: external_userid,
aid: that.aid,
},
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'];
that.buddy_type = re.data['buddy_type'];
that.buddyTypeAry = re.data['buddyTypeAry'];
} else {
mDialog.msg({content: re.msg});
}
},
complete: function () {
loading && mDialog.close(loading); //关闭加载
}
});
},
//保存
postUser() {
let that = this;
if (!that.userInfo.userid || !that.userInfo.external_userid) {
mDialog.msg({content: "保存失败"});
return
}
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/persona/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,
aid: that.aid,
buddy_type: that.buddy_type,
},
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;
}
});
},
//单选
radioPicker(i, j) {
let taglList = this.taglList
taglList[i].list.forEach(item => {
item.checked = false
})
taglList[i].list[j].checked = true
this.taglList = taglList
},
//多选
checkPicker(i, j) {
this.taglList[i].list[j].checked = !this.taglList[i].list[j].checked
},
}
});
wx.config({
beta: true,// 必须这么写,否则wx.invoke调用形式的jsapi会有问题
debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
appId: "<?=$sign_package['appId']?>", // 必填,企业微信的corpID
timestamp: "<?=$sign_package['timestamp']?>", // 必填,生成签名的时间戳
nonceStr: "<?=$sign_package['nonceStr']?>", // 必填,生成签名的随机串
signature: "<?=$sign_package['signature']?>",// 必填,签名,见 附录-JS-SDK使用权限签名算法
jsApiList: ["agentConfig"] // 必填,需要使用的JS接口列表,凡是要调用的接口都需要传进来
});
wx.ready(function () {
wx.agentConfig({
corpid: "<?=$sign_package_agent['appId']?>",
agentid: "<?=$sign_package_agent['agentid']?>",
timestamp: "<?=$sign_package_agent['timestamp']?>",
nonceStr: "<?=$sign_package_agent['nonceStr']?>",
signature: "<?=$sign_package_agent['signature']?>",
jsApiList: ['getCurExternalContact', 'getContext', 'invoke'],
success: function (res) {
wx.invoke('getCurExternalContact', {}, function (res) {
//var json = JSON.stringify(res);
//mDialog.msg({content: "getCurExternalContact=" + json});
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) {
});
</script>
</body>
</html>
+1
View File
@@ -0,0 +1 @@
defojxUZ6eNqi0h2