customer_414

This commit is contained in:
dengbw
2022-04-14 14:08:34 +08:00
parent 3d274a8cff
commit 4db90d0a27
6 changed files with 156 additions and 59 deletions
+52
View File
@@ -16,6 +16,58 @@ class Temp extends HD_Controller
$this->log_file = 'temp.log';
}
/**
* Notes:更新战败客户信息
* Created on: 2022/3/09 11:58
* Created by: dengbw
* https://liche-api-dev.xiaoyu.com/plan/temp/receiver_customer_defeat
* https://api.liche.cn/plan/temp/receiver_customer_defeat
*/
public function receiver_customer_defeat()
{
$this->load->model('receiver/receiver_customers_model', 'mdCustomers');
$param = $this->input->get();
$param['page'] = intval($param['page']);
$param['size'] = intval($param['size']);
!$param['size'] && $param['size'] = 50;
!$param['page'] && $param['page'] = 1;
$counts = intval($param['counts']);
ob_start(); //打开缓冲区
$where = ["status=3 OR defeat_time<>0" => null];
$res = $this->mdCustomers->select($where, 'id ASC', $param['page'], $param['size'], 'id,jsondata,status,defeat_time');
if (!$res) {
echo '<br>本次更新战败客户信息完成了:';
echo '<br><br>成功更新 <span style="color: red;">' . $counts . '</span> 条';
echo '<br><br><a href="/plan/temp/receiver_customer_defeat">点击将再次更新战败客户信息>>></a>';
exit;
}
$log = array();
foreach ($res as $key => $value) {
$upDate = [];
if ($value['status'] == 3) {
$jsondata = $value['jsondata'] ? json_decode($value['jsondata'], true) : [];
if ($jsondata['defeat']['pass_time']) {
$upDate = ['def_time' => $jsondata['defeat']['pass_time']];//更新战败时间
}
} else if ($value['defeat_time'] > 0) {//申请中
$upDate = ['if_defeat' => 1];
} else if ($value['defeat_time'] == -1) {//再战
$upDate = ['if_defeat' => 2];
}
if ($upDate) {
$this->mdCustomers->update($upDate, ['id' => $value['id']]);
$log[] = ['id' => $value['id'], 'upDate' => $upDate];
$counts++;
}
}
echo '<br>成功更新:';
$log && print_r($log);
echo '<br><br>数据库获取:';
echo json_encode($res, JSON_UNESCAPED_UNICODE);
header('refresh:3;url=/plan/temp/receiver_customer_defeat?counts=' . $counts . '&size=' . $param['size'] . '&page=' . ($param['page'] + 1));
ob_end_flush();//输出全部内容到浏览器
}
/**
* Notes:更新车辆调拨状态
* Created on: 2022/2/28 17:15
+53 -36
View File
@@ -319,9 +319,9 @@ class Customers extends Wxapp
$uid = $this->session['uid'];
$uname = $this->session['uname'];
$this->load->library('receiver/customers_entity');
$this->customers_entity->add_log($id, $uid, $uname, "创建客户");
$this->customers_entity->add_log($id, $uid, $uname, "创建客户档案", 3);
if ($status == 1) {//到店客户加日志
$this->customers_entity->add_log($id, $uid, $uname, "到店+1");
$this->customers_entity->add_log($id, $uid, $uname, "客户到店", 4);
}
throw new Exception('创建成功', API_CODE_SUCCESS);
} else {
@@ -333,7 +333,7 @@ class Customers extends Wxapp
protected function put()
{
$uid = $this->session['uid'];
$uname = $this->session['uname'];
$id = $this->input_param('id');
$status = $this->input_param('status');
$t_num = $this->input_param('t_num');
@@ -345,7 +345,6 @@ class Customers extends Wxapp
if (!$row) {
throw new Exception('数据不存在', ERR_PARAMS_ERROR);
}
$log = '';
$up_data = [];
//变成到店
if (!$row['admin_id'] && $status == 1) {
@@ -354,22 +353,22 @@ class Customers extends Wxapp
if ($row['admin_id'] != $uid) {
throw new Exception('无法操作该客户', ERR_PARAMS_ERROR);
}
$d_log = $a_log = '';
if ($status == 3) {
if (!$defeat_reason) {
throw new Exception('请输入战败理由', ERR_PARAMS_ERROR);
}
$defeat_time = date("Y-m-d H:i:s");
$jsondata = $row['jsondata'] ? json_decode($row['jsondata'], true) : array();
$jsondata['defeat']['time'] = $defeat_time;
$jsondata['defeat']['time'] = date("Y-m-d H:i:s");
$jsondata['defeat']['reason'] = $defeat_reason;
$up_data['defeat_time'] = strtotime($defeat_time);
$up_data['if_defeat'] = 1;
$up_data['jsondata'] = json_encode($jsondata, JSON_UNESCAPED_UNICODE);
$log = '申请战败:' . $defeat_reason;
$d_log = '申请战败:' . $defeat_reason;
} else {
if (strlen($status)) { //变更状态
$up_data['status'] = $status;
$status_name = $this->customers_model->get_status();
$log = '状态变更为' . $status_name[$status];
//$status_name = $this->customers_model->get_status();
//$log = '状态变更为' . $status_name[$status];
}
}
strlen($is_top) && $up_data['is_top'] = $is_top;
@@ -377,23 +376,33 @@ class Customers extends Wxapp
$a_num && $up_data['a_num = a_num+1'] = null;
$result = true;
if ($up_data) {
$status == 1 && $up_data['cont_time'] = date('Y-m-d H:i:s'); //修改到店状态修改最后联系时间
if (($status == 1 || $a_num) && $row['dt_time'] == '0000-00-00 00:00:00') {//首次到店时间
$up_data['dt_time'] = date('Y-m-d H:i:s');
$a_log = '';//到店
if ($status == 1 || $a_num) {
$a_log = '客户到店';
$up_data['cont_time'] = date('Y-m-d H:i:s'); //修改到店状态修改最后联系时间
$status != $row['status'] && $a_log .= ',更改状态';
if ($row['dt_time'] == '0000-00-00 00:00:00') {//首次到店时间
$up_data['dt_time'] = date('Y-m-d H:i:s');
$a_log .= ',更新首次到店时间';
}
}
$result = $this->customers_model->update($up_data, ['id' => $id]);
if ($result) { //添加日志
$this->load->library('receiver/customers_entity');
if ($t_num) {
$msg = '试驾+1';
$log = $log ? $log . ',' . $msg : $msg;
if ($a_log) {//到店
$this->customers_entity->add_log($id, $uid, $uname, $a_log, 4);
}
if ($a_num) {
$msg = '到店+1';
$log = $log ? $log . ',' . $msg : $msg;
if ($t_num) {//试驾
$this->customers_entity->add_log($id, $uid, $uname, '客户试驾', 5);
}
if ($d_log) {//战败申请类型小记
$this->customers_entity->add_log($id, $uid, $uname, $d_log, 0);
}
if ($status == 2) {//变成订单客户
$this->customers_entity->add_log($id, $uid, $uname, '生成订单', 6);
//更新客户已回访
$this->customers_entity->add_log_visit($id, $uid, $uname, '', 0, 1);
}
$visit = $status == 2 ? 1 : 0;//变成订单客户,更新客户已回访
$this->customers_entity->add_log_visit($id, $uid, $this->session['uname'], $log, 0, $visit);
}
}
if ($result) {
@@ -560,7 +569,7 @@ class Customers extends Wxapp
$count = $this->customers_model->count($where);
$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
$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';
$rows = $this->customers_model->select($where, $orderby, $page, $size, $fileds);
//获取管理员
@@ -598,9 +607,9 @@ class Customers extends Wxapp
$val['cont_time'] != '0000-00-00 00:00:00' && $other_data['上次联系'] = date('Y-m-d', strtotime($val['cont_time']));
$tags = [$val['level'] . '级用户'];
$defeat = '';
if ($val['defeat_time'] > 0) {
if ($val['if_defeat'] == 1) {
$defeat = '战败申请中';
} else if ($val['defeat_time'] == -1) {
} else if ($val['if_defeat'] == 2) {
$defeat = '再战';
}
$lists[] = [
@@ -684,7 +693,7 @@ class Customers extends Wxapp
$lists = [];
if ($count) {
$fileds = 'a.id,a.name,a.admin_id,a.mobile,a.level,a.car_json,a.is_top,a.cf_title,a.brand_id,a.s_id
,a.cont_time,a.c_time,a.defeat_time';
,a.cont_time,a.c_time,a.if_defeat';
$rows = $this->mdCustomersVisit->select_visit($where, 'a.id desc', $page, $size, $fileds);
//获取管理员
$admin_arr = array_unique(array_column($rows, 'admin_id'));
@@ -715,9 +724,9 @@ class Customers extends Wxapp
$val['cont_time'] != '0000-00-00 00:00:00' && $other_data['上次联系'] = date('Y-m-d', strtotime($val['cont_time']));
$tags = [$val['level'] . '级用户'];
$defeat = '';
if ($val['defeat_time'] > 0) {
if ($val['if_defeat'] == 1) {
$defeat = '战败申请中';
} else if ($val['defeat_time'] == -1) {
} else if ($val['if_defeat'] == 2) {
$defeat = '再战';
}
$lists[] = [
@@ -758,7 +767,7 @@ class Customers extends Wxapp
!$page && $page = 1;
!$size && $size = 10;
$biz_id = $this->session['new_biz_id'] ? $this->session['new_biz_id'] : intval($this->session['biz_id']);
$where = array('biz_id' => $biz_id, 'defeat_time >' => 0, 'status>' => -1);
$where = array('biz_id' => $biz_id, 'if_defeat' => 1, 'status>' => -1);
$count = $this->customers_model->count($where);
$lists = [];
if ($count) {
@@ -804,25 +813,33 @@ class Customers extends Wxapp
if (!$row) {
throw new Exception('用户不存在', ERR_PARAMS_ERROR);
}
if (!$row['defeat_time']) {
if (!$row['if_defeat']) {
throw new Exception('未申请战败', ERR_PARAMS_ERROR);
}
$jsondata = $row['jsondata'] ? json_decode($row['jsondata'], true) : array();
if ($type == 1) {
$log = '拒绝战败申请';
$update['defeat_time'] = -1;//再战
$update['if_defeat'] = 2;//再战
} else {
$jsondata['defeat']['pass_time'] = date("Y-m-d H:i:s");
$def_time = date("Y-m-d H:i:s");
$jsondata['defeat']['pass_time'] = $def_time;
$update['status'] = 3;
$log = '通过战败申请';
$update['defeat_time'] = 0;
$update['if_defeat'] = 0;
$update['def_time'] = $def_time;
}
$update['jsondata'] = json_encode($jsondata, JSON_UNESCAPED_UNICODE);
$ret = $this->customers_model->update($update, ['id' => $id]);
if ($ret) {
$this->load->library('receiver/customers_entity');
$visit = $update['status'] == 3 ? 1 : 0;
$this->customers_entity->add_log_visit($id, $this->session['uid'], $this->session['uname'], $log, 0, $visit);
$uid = $this->session['uid'];
$uname = $this->session['uname'];
if ($type == 1) {
$this->customers_entity->add_log($id, $uid, $uname, '拒绝战败申请', 0);
} else {
//战败
$this->customers_entity->add_log($id, $uid, $uname, '客户战败', 7);
//更新客户已回访
$this->customers_entity->add_log_visit($id, $uid, $uname, '', 0, 1);
}
throw new Exception('操作成功', API_CODE_SUCCESS);
}
throw new Exception('操作失败', ERR_PARAMS_ERROR);
+1 -1
View File
@@ -315,7 +315,7 @@ class User extends Wxapp
$where['brand_id!='] = 3; //渠道经理过滤
}
$unuse_count = $this->customers_model->count($where);
$defeat_count = $this->customers_model->count(array('biz_id' => $biz_id, 'defeat_time >' => 0, 'status>' => -1));
$defeat_count = $this->customers_model->count(array('biz_id' => $biz_id, 'if_defeat' => 1, 'status>' => -1));
$customer_op_list = [
['title' => '待分配客户(人)', 'icon' => 'icon-daifenpei', 'total' => $unuse_count, 'page' => '/pages/customer/allot/index'],
['title' => '待回访客户(人)', 'icon' => 'icon-statistics-custom-4', 'total' => $visit_count, 'page' => '/pages/customer/filterList/index?visit=1&title=待回访客户'],
+22 -9
View File
@@ -31,10 +31,11 @@ class Customers_entity
*/
public function add_log_visit($customer_id, $uid, $uname, $content, $type = '', $visit = 0, $imgs = [], $cf_platform = 'wxapp')
{
if($content){
$result = '';
if ($content) {
$result = $this->add_log($customer_id, $uid, $uname, $content, $type, $cf_platform, $imgs);
}
if ($visit && $result) {//更新客户已回访
if ($visit && ($result || !$content)) {//更新客户已回访
$this->ci->load->model('receiver/receiver_customers_visit_model', 'mdCustomersVisit');
$result = $this->ci->mdCustomersVisit->update(array('contact' => 2, 'status' => 2)
, array('c_id' => $customer_id, 'contact' => 1, 'status' => 1));
@@ -43,17 +44,29 @@ class Customers_entity
}
/**
* 添加日志
* @param $customer_id int 客户id
* @param $uid int 操作用户id
* @param $uname int 操作用户名
* @param $content string 日志内容
* @param $type int 操作类型 (0普通日志 1短信 2拨打电话)
* @param $cf_platform string 来源 (wxapp小程序 admin后台)
* Notes:添加日志
* Created on: 2022/4/13 11:57
* Created by: dengbw
* @param $customer_id 客户id
* @param $uid 操作用户id
* @param $uname 操作用户名
* @param $content 日志内容
* @param string $type 操作类型 (0普通日志 1短信 2拨打电话)
* @param string $cf_platform 来源 (wxapp小程序 admin后台)
* @param array $imgs 日志图片
* @return string
*/
public function add_log($customer_id, $uid, $uname, $content, $type = '', $cf_platform = 'wxapp', $imgs = [])
{
$this->ci->load->model('receiver/receiver_customer_oplogs_model', 'customer_oplogs_model');
if ($type == 4 || $type == 5) {//到店或试驾,一天只记录一次
$day = date('Y-m-d');
$re = $this->ci->customer_oplogs_model->get(['customer_id' => $customer_id, 'type' => $type,
'c_time >=' => strtotime($day . ' 00:00:00'), 'c_time <=' => strtotime($day . ' 23:59:59')]);
if ($re) {
return '';
}
}
$add_data = [
'customer_id' => $customer_id,
'uid' => $uid,
@@ -19,13 +19,19 @@ class Receiver_customer_oplogs_model extends HD_Model
/**
* Notes:类型
* Created on: 2021/7/27 10:31
* Created on: 2022/4/12 16:51
* Created by: dengbw
* @return array
* @param int $id
* @return array|mixed
*/
public function typeAry()
public function typeAry($id = 0)
{
return array(0 => '小记', 1 => '发短信', 2 => '拨打号码');
$arr = [0 => '小记', 1 => '发短信', 2 => '拨打号码', 3 => '创建', 4 => '到店', 5 => '试驾', 6 => '订单', 7 => '战败'];
if ($id) {
return $arr[$id];
} else {
return $arr;
}
}
}
+17 -8
View File
@@ -228,6 +228,9 @@ class Persona extends CI_Controller
}
$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'],
@@ -239,7 +242,7 @@ class Persona extends CI_Controller
'of_id' => $params['of_id'],
'of2_id' => $params['of2_id'],
'cf_title' => '自有资源',
'admin_id' => $userInfo['admin_id'],
'admin_id' => $admin_id,
'status' => 1,//到店
'a_num' => 1,//到店次数
'dt_time' => $date,//到店时间
@@ -248,21 +251,27 @@ class Persona extends CI_Controller
'c_time' => time()
];
$c_id = $this->mdCustomers->add($add_data);
$log = '创建客户';
$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'];
$re_cus['status'] == 0 && $up_data['status'] = 1;//改为到店
$up_data['a_num = a_num+1'] = null;//加到店次数
$log = '客户到店';
if ($re_cus['status'] == 0) {//改为到店
$up_data['status'] = 1;
$log .= ',更改状态';
}
if ($re_cus['dt_time'] == '0000-00-00 00:00:00') {//首次到店时间
$up_data['dt_time'] = $date;
$log .= ',更新首次到店时间';
}
$up_data['a_num = a_num+1'] = null;//加到店次数
$up_data['cont_time'] = $date;
$this->mdCustomers->update($up_data, ['id' => $c_id]);
$log = '到店+1';
$ret = $this->mdCustomers->update($up_data, ['id' => $c_id]);
if ($ret) {
$this->customers_entity->add_log($c_id, $admin_id, $admin_name, $log, 4);
}
}
$this->load->library('receiver/customers_entity');
$this->customers_entity->add_log($c_id, $userInfo['admin_id'], $userInfo['admin_name'], $log);
$up_customer_tag = 1;//1更新客户标签
if (!$re_cus || !$userInfo['remark_mobile']) {//新增客户/首次绑定手机 更新企微信息
$up_customer_tag = 0;