diff --git a/api/controllers/plan/Licheb.php b/api/controllers/plan/Licheb.php index 125dcf76..857ccbcd 100644 --- a/api/controllers/plan/Licheb.php +++ b/api/controllers/plan/Licheb.php @@ -18,6 +18,116 @@ class Licheb extends HD_Controller $this->load->model('receiver/receiver_customers_visit_model', 'mdCustomersVisit'); } + /** + * Notes:顾问_日志 + * Created on: 2021/10/19 17:15 + * Created by: dengbw + * https://liche-api-dev.xiaoyu.com/plan/licheb/users_log?sd=1 + * https://api.liche.cn/plan/licheb/users_log + */ + public function users_log() + { + $params = $this->input->get(); + $time = strtotime("-1 day");//昨天此时的时间戳 + $hour = date('H.i'); + if (($hour > 00.00 && $hour < 03.00) || $params['sd']) { + if ($params['sd']) { + echo "开始执行库顾问日志[{$hour}]"; + } + } else { + echo '[00.00-03.00]执行顾问日志[' . $hour . ']'; + return; + } + $this->load->model('app/licheb/app_licheb_users_model', 'mdUsers'); + $this->load->model('app/licheb/app_licheb_users_log_model', 'mdUsersLog'); + $size = 2;//每次最多处理多少条 + $rds = intval($this->input->get('rds')); + $redis = &load_cache('redis'); + $redisKey = 'app_licheb_users_log_id'; + $log_date = date('Y-m-d', $time); + $re_v = $this->mdUsersLog->get(array('log_date' => $log_date));//查找当天是否有数据 + if (!$re_v || $rds) { + $redis->delete($redisKey); + } + $id = $redis->get($redisKey); + $id = 19; + !$id && $id = 0; + $log = []; + $where = ['id >' => $id, 'group_id < 4' => null, 'status' => 1]; + $res = $this->mdUsers->select($where, 'id asc', 1, $size, 'id,biz_id'); + if (!$res) { + echo '执行到当前顾问id:' . $id . '暂无数据'; + return; + } + $this->load->model('receiver/receiver_customer_oplogs_model', 'mdCustomerOpLogs'); + $this->load->model('receiver/order/receiver_orders_v2_model', 'mdOrdersV2'); + $this->load->model("biz/biz_model", 'mdBiz'); + $offlineSources = $this->mdCustomers->offlineSources(); + $addDate = []; + $str_biz_ids = implode(',', array_unique(array_column($res, 'biz_id'))); + $map_biz = $this->mdBiz->map('id', 'city_id', ["id in({$str_biz_ids})" => null]); + foreach ($res as $key => $value) { + $sale_id = $value['id']; + $biz_id = intval($value['biz_id']); + $re_log = $this->mdUsersLog->get(['log_date' => $log_date, 'sale_id' => $sale_id]); + if (!$re_log) {//判断当天是否已加入 + $s_time = strtotime($log_date . ' 00:00:00'); + $e_time = strtotime($log_date . ' 23:59:59'); + $city_id = intval($map_biz[$value['biz_id']]); + $a_num = $this->mdCustomerOpLogs->count(['type' => 4, 'c_time>=' => $s_time, 'c_time<=' => $e_time, + "customer_id in(select id from lc_receiver_customers where admin_id={$sale_id} and biz_id={$biz_id})" => null] + ); + $follows = $this->mdCustomerOpLogs->count(['type<>' => 3, 'c_time>=' => $s_time, 'c_time<=' => $e_time, + "customer_id in(select id from lc_receiver_customers where admin_id={$sale_id} and biz_id={$biz_id})" => null], 'distinct(customer_id)' + ); + $orders = $this->mdOrdersV2->count(['order_time<>' => '0000-00-00 00:00:00', 'status>=' => 0, + 'c_time>=' => $s_time, 'c_time<=' => $e_time] + ); + $bills = $this->mdOrdersV2->count(['bill_time<>' => '0000-00-00 00:00:00', 'status>=' => 0, + 'c_time>=' => $s_time, 'c_time<=' => $e_time] + ); + $add_item = ['sale_id' => $sale_id, 'biz_id' => $value['biz_id'], 'city_id' => $city_id, 'a_num' => $a_num + , 'orders' => $orders, 'bills' => $bills, 'follows' => $follows, 'log_date' => $log_date, 'c_time' => time()]; + $customer_json = ''; + foreach ($offlineSources as $key1 => $value1) { + $customer_num1 = $this->mdCustomers->count(['of_id' => $key1, 'admin_id' => $sale_id + , 'status>=' => 0, 'c_time>=' => $s_time, 'c_time<=' => $e_time]); + if ($customer_num1) {//一级 + $add_item["customer_{$key1}"] = $customer_num1; + $list = ''; + foreach ($value1['list'] as $key2 => $value2) { + $customer_num2 = $this->mdCustomers->count(['of_id' => $key1, 'of2_id' => $key2, 'admin_id' => $sale_id + , 'status>=' => 0, 'c_time>=' => $s_time, 'c_time<=' => $e_time]); + if ($customer_num2) {//二级 + $list[$key2] = ['name' => $value2, 'num' => $customer_num2]; + } + } + $customer_json[$key1] = ['name' => $value1['name'], 'num' => $customer_num1, 'list' => $list]; + } + } + $customer_json && $add_item['customer_json'] = $customer_json; + //$customer_json && $add_item['customer_json'] = json_encode($customer_json, JSON_UNESCAPED_UNICODE); + $addDate[] = $add_item; + $log[] = array('id' => $sale_id, 'addDate' => $add_item); + } + } + if ($addDate && count($addDate)) { + //$this->mdUsersLog->add_batch($addDate); + } + $redis->save($redisKey, $id, 24 * 3600);//保存最后id + if ($params['sd']) { + echo '
执行到当前顾问id:' . $redis->get($redisKey); + echo '日期:' . json_encode(array('log_date' => $log_date), JSON_UNESCAPED_UNICODE); + echo '
成功新增:
'; + if ($log) { + echo json_encode($log, JSON_UNESCAPED_UNICODE); + echo '
'; + } + echo '数据库获取:
'; + echo json_encode($res, JSON_UNESCAPED_UNICODE); + } + } + /** * Notes:给销售发送待回访短信 * Created on: 2021/10/19 17:15 diff --git a/api/controllers/wxapp/licheb/Cusorder.php b/api/controllers/wxapp/licheb/Cusorder.php index 03a6e4d7..414c9d45 100644 --- a/api/controllers/wxapp/licheb/Cusorder.php +++ b/api/controllers/wxapp/licheb/Cusorder.php @@ -225,7 +225,7 @@ class Cusorder extends Wxapp{ //更新客户下单时间 $this->customers_model->update(array('order_time' => date('Y-m-d H:i:s')),['id'=>$cus_id]); - $this->customers_entity->add_log($cus_id, $this->session['uid'], $this->session['uname'], "新增订单"); + $this->customers_entity->add_log($cus_id, $this->session['uid'], $this->session['uname'], '生成订单', 6); return ['id'=>$o_id,'admin_img' => $orders_entity::API_ADMIN_IMG,'pay_img'=>$orders_entity::API_CREATE_PAY_IMG]; }else{ diff --git a/api/controllers/wxapp/licheb/Cusorder2.php b/api/controllers/wxapp/licheb/Cusorder2.php index 2fad71ec..7f72f7d5 100644 --- a/api/controllers/wxapp/licheb/Cusorder2.php +++ b/api/controllers/wxapp/licheb/Cusorder2.php @@ -108,7 +108,7 @@ class Cusorder2 extends Wxapp{ //更新客户下单时间 $this->customers_model->update(array('order_time' => date('Y-m-d H:i:s')),['id'=>$cus_id]); - $this->customers_entity->add_log($cus_id, $this->session['uid'], $this->session['uname'], "新增订单"); + $this->customers_entity->add_log($cus_id, $this->session['uid'], $this->session['uname'], '生成订单', 6); //意向金订单 $orders_entity = new Orders_entity(); diff --git a/api/controllers/wxapp/licheb/CusorderV2.php b/api/controllers/wxapp/licheb/CusorderV2.php index fc410156..02359564 100644 --- a/api/controllers/wxapp/licheb/CusorderV2.php +++ b/api/controllers/wxapp/licheb/CusorderV2.php @@ -221,7 +221,7 @@ class CusorderV2 extends Wxapp{ } //更新客户下单时间 $this->customers_model->update(array('order_time' => date('Y-m-d H:i:s')),['id'=>$cus_id]); - $this->customers_entity->add_log($cus_id, $this->session['uid'], $this->session['uname'], "新增订单"); + $this->customers_entity->add_log($cus_id, $this->session['uid'], $this->session['uname'], '生成订单', 6); return ['id'=>$o_id,'pay_img'=>$orders_entity->pay_img($o_id)]; }else{ @@ -289,7 +289,7 @@ class CusorderV2 extends Wxapp{ //更新客户下单时间 $this->customers_model->update(array('order_time' => date('Y-m-d H:i:s')),['id'=>$cus_id]); - $this->customers_entity->add_log($cus_id, $this->session['uid'], $this->session['uname'], "新增订单"); + $this->customers_entity->add_log($cus_id, $this->session['uid'], $this->session['uname'], '生成订单', 6); //意向金订单 $orders_entity = new orders_v2_entity(); diff --git a/api/controllers/wxapp/licheb/Customers.php b/api/controllers/wxapp/licheb/Customers.php index 94804b72..5ef8f018 100644 --- a/api/controllers/wxapp/licheb/Customers.php +++ b/api/controllers/wxapp/licheb/Customers.php @@ -353,7 +353,7 @@ class Customers extends Wxapp if ($row['admin_id'] != $uid) { throw new Exception('无法操作该客户', ERR_PARAMS_ERROR); } - $d_log = $a_log = ''; + $log = $a_log = ''; if ($status == 3) { if (!$defeat_reason) { throw new Exception('请输入战败理由', ERR_PARAMS_ERROR); @@ -363,12 +363,12 @@ class Customers extends Wxapp $jsondata['defeat']['reason'] = $defeat_reason; $up_data['if_defeat'] = 1; $up_data['jsondata'] = json_encode($jsondata, JSON_UNESCAPED_UNICODE); - $d_log = '申请战败:' . $defeat_reason; + $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; @@ -380,10 +380,8 @@ class Customers extends Wxapp 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]); @@ -395,12 +393,10 @@ class Customers extends Wxapp 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 ($log) {//小记 + $this->customers_entity->add_log($id, $uid, $uname, $log, 0); } - if ($status == 2) {//变成订单客户 - $this->customers_entity->add_log($id, $uid, $uname, '生成订单', 6); - //更新客户已回访 + if ($status == 2) {//变成订单客户 更新客户已回访 $this->customers_entity->add_log_visit($id, $uid, $uname, '', 0, 1); } } diff --git a/common/models/app/licheb/App_licheb_users_log_model.php b/common/models/app/licheb/App_licheb_users_log_model.php new file mode 100644 index 00000000..da4fcc80 --- /dev/null +++ b/common/models/app/licheb/App_licheb_users_log_model.php @@ -0,0 +1,17 @@ +table_name, 'default'); + } +} \ No newline at end of file diff --git a/home/controllers/h5/Persona.php b/home/controllers/h5/Persona.php index ac6e5e7b..93ed1d91 100644 --- a/home/controllers/h5/Persona.php +++ b/home/controllers/h5/Persona.php @@ -259,11 +259,9 @@ class Persona extends CI_Controller $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;