From 4e9dd64115f6ab0ba11c5778abeceff678e75d21 Mon Sep 17 00:00:00 2001 From: dengbw Date: Mon, 6 Jun 2022 16:16:22 +0800 Subject: [PATCH] customers_606 --- api/controllers/plan/Licheb.php | 5 +- api/controllers/wxapp/licheb/Customers.php | 80 ++++++++++++++++++---- 2 files changed, 68 insertions(+), 17 deletions(-) diff --git a/api/controllers/plan/Licheb.php b/api/controllers/plan/Licheb.php index 55f5c87b..1b235132 100644 --- a/api/controllers/plan/Licheb.php +++ b/api/controllers/plan/Licheb.php @@ -50,7 +50,7 @@ class Licheb extends HD_Controller !$id && $id = 0; $log = []; $where = ['id >' => $id, 'status<>' => 2, 't_day' => $t_day]; - $res = $this->mdCustomerVisitData->select($where, 'id asc', 1, $size, 'id,c_id,biz_id,sales_id,level'); + $res = $this->mdCustomerVisitData->select($where, 'id asc', 1, $size, 'id,c_id,biz_id,sales_id,level,pid'); if (!$res) { echo '执行到当前客户回访id:' . $id . '暂无数据'; return; @@ -59,7 +59,7 @@ class Licheb extends HD_Controller $this->load->model('receiver/receiver_customer_oplogs_model', 'mdCustomerOpLogs'); $s_time = strtotime($t_day . ' 00:00:00'); $e_time = strtotime($t_day . ' 23:59:59'); - $today = date('Y-m-d');//明天 + $today = date('Y-m-d');//今天 foreach ($res as $key => $value) { $id = $value['id']; $re_opl = $this->mdCustomerOpLogs->get(['customer_id' => $value['c_id'], 'uid' => $value['sales_id'] @@ -77,6 +77,7 @@ class Licheb extends HD_Controller $where_vis = ['c_id' => $value['c_id'], 'sales_id' => $value['sales_id'], 't_day' => $today]; $re_vis = $this->mdCustomerVisitData->get($where_vis); if (!$re_vis) {//新增明天延期数据 + $where_vis['pid'] = $value['pid'] ? $value['pid'] : $value['id'];//逾期id $where_vis['biz_id'] = $value['biz_id']; $where_vis['status'] = 3; $where_vis['level'] = $value['level']; diff --git a/api/controllers/wxapp/licheb/Customers.php b/api/controllers/wxapp/licheb/Customers.php index b831fcc9..8bfc4cc7 100644 --- a/api/controllers/wxapp/licheb/Customers.php +++ b/api/controllers/wxapp/licheb/Customers.php @@ -11,6 +11,7 @@ require_once APPPATH . 'controllers/wxapp/Wxapp.php'; class Customers extends Wxapp { + private $biz_id; function __construct($inputs, $app_key) { @@ -25,11 +26,13 @@ class Customers extends Wxapp $this->load->model('receiver/receiver_customer_oplogs_model', 'customer_oplogs_model'); $this->load->model('receiver/receiver_customer_tag_model', 'mdCustomerTag'); $this->load->model('receiver/receiver_customer_tagdata_model', 'mdCustomerTagdata'); + $this->load->model('receiver/receiver_customers_visit_data_model', 'mdCustomerVisitData'); $this->load->model('receiver/order/receiver_orders_v2_model', 'mdOrders'); $this->load->model('auto/auto_series_model'); $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']); } protected function get() @@ -53,7 +56,13 @@ class Customers extends Wxapp '建卡时间' => date('Y-m-d', $row['c_time']), ]; $row['cont_time'] != '0000-00-00 00:00:00' && $other_data['最近联系'] = date('Y-m-d', strtotime($row['cont_time'])); - $row['visit_time'] != '0000-00-00' && $other_data['计划回访时间'] = $row['visit_time']; + if ($this->session['group_id'] == 1) { + $where_visit = ['c_id' => $id, 'biz_id' => $this->biz_id, 'sales_id' => $this->session['uid']]; + } else { + $where_visit = ['c_id' => $id, 'biz_id' => $row['biz_id'], 'sales_id' => $row['admin_id']]; + } + $visit_time = $this->get_visit_time($where_visit); + $visit_time && $other_data['计划回访时间'] = $visit_time; $other_data['销售顾问'] = isset($admin) ? $admin['uname'] : ''; $data = [ 'id' => $row['id'], @@ -123,7 +132,7 @@ class Customers extends Wxapp //修改基本信息 protected function put_data() { - $biz_id = $this->session['new_biz_id'] ? $this->session['new_biz_id'] : intval($this->session['biz_id']); + $biz_id = $this->biz_id; $id = $this->input_param('cus_id'); $name = $this->input_param('name'); $mobile = $this->input_param('mobile'); @@ -219,7 +228,7 @@ class Customers extends Wxapp //创建客户 protected function post() { - $biz_id = $this->session['new_biz_id'] ? $this->session['new_biz_id'] : intval($this->session['biz_id']); + $biz_id = $this->biz_id; $name = $this->input_param('name'); $mobile = $this->input_param('mobile'); //$car_id = $this->input_param('car_id'); //品牌车型id @@ -321,7 +330,7 @@ class Customers extends Wxapp //客户跟进 protected function put() { - $biz_id = $this->session['new_biz_id'] ? $this->session['new_biz_id'] : intval($this->session['biz_id']); + $biz_id = $this->biz_id; $uid = $this->session['uid']; $uname = $this->session['uname']; $id = $this->input_param('id'); @@ -430,7 +439,6 @@ class Customers extends Wxapp if ($visit_time) { $content .= '。计划回访时间:' . $visit_time; $where_vis = ['c_id' => $id, 'biz_id' => $biz_id, 'sales_id' => $uid, 't_day' => $visit_time, 'level' => $level]; - $this->load->model('receiver/receiver_customers_visit_data_model', 'mdCustomerVisitData'); $re_vis = $this->mdCustomerVisitData->get($where_vis); if (!$re_vis) { $where_vis['c_time'] = time(); @@ -517,7 +525,7 @@ class Customers extends Wxapp } $uid = $this->session['uid']; $group_id = $this->session['group_id']; - $biz_id = $this->session['new_biz_id'] ? $this->session['new_biz_id'] : intval($this->session['biz_id']); + $biz_id = $this->biz_id; $s_time = $this->input_param('s_time'); $e_time = $this->input_param('e_time'); @@ -615,7 +623,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,visit_time,status'; + ,of_id,of2_id,unionid,status,biz_id'; $rows = $this->customers_model->select($where, $orderby, $page, $size, $fileds); //获取管理员 $admin_arr = array_unique(array_column($rows, 'admin_id')); @@ -635,7 +643,13 @@ class Customers extends Wxapp '建卡时间' => date('Y-m-d', $val['c_time']), ]; $val['cont_time'] != '0000-00-00 00:00:00' && $other_data['最近联系'] = date('Y-m-d', strtotime($val['cont_time'])); - $val['visit_time'] != '0000-00-00' && $other_data['计划回访时间'] = $val['visit_time']; + if ($group_id == 1) { + $where_visit = ['c_id' => $val['id'], 'biz_id' => $this->biz_id, 'sales_id' => $this->session['uid']]; + } else { + $where_visit = ['c_id' => $val['id'], 'biz_id' => $val['biz_id'], 'sales_id' => $val['admin_id']]; + } + $visit_time = $this->get_visit_time($where_visit); + $visit_time && $other_data['计划回访时间'] = $visit_time; $other_data['销售顾问'] = isset($admins[$val['admin_id']]) ? $admins[$val['admin_id']][0]['uname'] : ''; $tags = [$val['level'] . '级用户']; $defeat = $orders_pay = ''; @@ -736,9 +750,7 @@ class Customers extends Wxapp */ private function visit_lists($params = []) { - $biz_id = $this->session['new_biz_id'] ? $this->session['new_biz_id'] : intval($this->session['biz_id']); $group_id = $this->session['group_id']; - $this->load->model('receiver/receiver_customers_visit_data_model', 'mdCustomerVisitData'); $page = intval($params['page']); $size = intval($params['size']); $status = intval($params['status']); @@ -746,7 +758,7 @@ class Customers extends Wxapp !$page && $page = 1; !$size && $size = 10; $t_day = date('Y-m-d'); - $where = array('a.biz_id' => $biz_id, 'a.status in(0,1)' => null, 'b.t_day' => $t_day); + $where = array('a.biz_id' => $this->biz_id, 'a.status in(0,1)' => null, 'b.t_day' => $t_day); $params['level'] && $where['a.level'] = $params['level'];//等级 if ($status == 2) {//已跟进 $where['b.status'] = 2; @@ -762,7 +774,7 @@ class Customers extends Wxapp $lists = []; if ($count) { $fileds = 'a.id,a.name,a.admin_id,a.mobile,a.level,a.is_top,a.cont_time,a.c_time,a.if_defeat,a.cf_title - ,a.of_id,a.of2_id,a.status,a.visit_time'; + ,a.of_id,a.of2_id,a.status,a.biz_id'; $rows = $this->mdCustomerVisitData->select_visit($where, 'a.id desc', $page, $size, $fileds); //获取管理员 $admin_arr = array_unique(array_column($rows, 'admin_id')); @@ -778,7 +790,13 @@ class Customers extends Wxapp '建卡时间' => date('Y-m-d', $val['c_time']), ]; $val['cont_time'] != '0000-00-00 00:00:00' && $other_data['上次联系'] = date('Y-m-d', strtotime($val['cont_time'])); - $val['visit_time'] != '0000-00-00' && $other_data['计划回访时间'] = $val['visit_time']; + if ($group_id == 1) { + $where_visit = ['c_id' => $val['id'], 'biz_id' => $this->biz_id, 'sales_id' => $this->session['uid']]; + } else { + $where_visit = ['c_id' => $val['id'], 'biz_id' => $val['biz_id'], 'sales_id' => $val['admin_id']]; + } + $visit_time = $this->get_visit_time($where_visit); + $visit_time && $other_data['计划回访时间'] = $visit_time; $other_data['销售顾问'] = isset($admins[$val['admin_id']]) ? $admins[$val['admin_id']][0]['uname'] : ''; $tags = [$val['level'] . '级用户']; $defeat = ''; @@ -817,7 +835,7 @@ class Customers extends Wxapp */ private function visit_lists_temp($params = array()) { - $biz_id = $this->session['new_biz_id'] ? $this->session['new_biz_id'] : intval($this->session['biz_id']); + $biz_id = $this->biz_id; $group_id = $this->session['group_id']; $this->load->model('receiver/receiver_customers_visit_model', 'mdCustomersVisit'); $page = $params['page']; @@ -890,7 +908,7 @@ class Customers extends Wxapp $size = $params['size']; !$page && $page = 1; !$size && $size = 10; - $biz_id = $this->session['new_biz_id'] ? $this->session['new_biz_id'] : intval($this->session['biz_id']); + $biz_id = $this->biz_id; $where = array('biz_id' => $biz_id, 'if_defeat' => 1, 'status>' => -1); $count = $this->customers_model->count($where); $lists = []; @@ -1032,4 +1050,36 @@ class Customers extends Wxapp return $allot; } + /** + * Notes:计划回访时间 + * Created on: 2022/6/6 14:13 + * Created by: dengbw + * @param $params + * @return string + */ + private function get_visit_time($params) + { + $today = date('Y-m-d');//今天 + $re = $this->mdCustomerVisitData->get(['c_id' => $params['c_id'], 'biz_id' => $params['biz_id'] + , 'sales_id' => $params['sales_id'], 't_day' => $today]); + $visit_time = ''; + if ($re) { + if ($re['pid']) {//有逾期id 找最初回访日期并统计次数 + $re_pid = $this->mdCustomerVisitData->get(['id' => $re['pid']]); + if ($re_pid) { + $visit_time = $re_pid['t_day']; + $count = $this->mdCustomerVisitData->count(['pid' => $re['pid']]); + $count && $visit_time = $visit_time . "(逾期{$count}次)"; + } + } else { + $visit_time = $re['t_day']; + } + } else { + $re = $this->mdCustomerVisitData->get(['c_id' => $params['c_id'], 'biz_id' => $params['biz_id'], + 'sales_id' => $params['sales_id'], 't_day>' => $today]); + $re && $visit_time = $re['t_day']; + } + return $visit_time; + } + }