diff --git a/admin/controllers/receiver/Customer.php b/admin/controllers/receiver/Customer.php index a49e1de3..527050b8 100644 --- a/admin/controllers/receiver/Customer.php +++ b/admin/controllers/receiver/Customer.php @@ -263,13 +263,21 @@ class Customer extends HD_Controller } else { $tag = $this->get_tag($row['id']); } + $to_send = ''; + if ($row['cs_biz_id'] == -1) { + $to_send = '已改派'; + } else if ($row['cs_biz_id'] > 0) { + $to_send = '接收线索'; + } $info = array( 'id' => $row['id'], 'name' => $row['name'], + 'level' => $row['level'], 'mobile' => $mobile_sub, 'of_title' => $of_title, 'wxqy_name' => $this->customers_model->wxqyAry($row['wxqy']), 'cf_user' => $cf_user, + 'to_send' => $to_send, 'c_time' => date('Y-m-d H:i:s', $row['c_time']), 'status' => $row['status'], 'tag' => $tag, diff --git a/admin/views/receiver/customer/get.php b/admin/views/receiver/customer/get.php index 03002abb..7fcdbd45 100644 --- a/admin/views/receiver/customer/get.php +++ b/admin/views/receiver/customer/get.php @@ -60,9 +60,13 @@ 客户来源:{{info.of_title}} 企微好友:{{info.wxqy_name}} - - - + 客户等级:{{info.level}} + + + 改派:{{info.to_send}} + 分销来源:{{info.cf_user}} + + diff --git a/api/controllers/plan/Liche.php b/api/controllers/plan/Liche.php index bc902d52..36d99816 100644 --- a/api/controllers/plan/Liche.php +++ b/api/controllers/plan/Liche.php @@ -12,126 +12,76 @@ class Liche extends HD_Controller parent::__construct(); } - /** - * Notes:更新异业店车主企业微信 - * Created on: 2022/6/21 16:00 - * Created by: dengbw - * https://liche-api-dev.xiaoyu.com/plan/liche/owners_wxqy_different?rds=1 - * https://api.liche.cn/plan/liche/owners_wxqy_different - */ - public function owners_wxqy_different() - { - $params = $this->input->get(); - $size = 100;//每次最多处理多少条 - $rds = intval($this->input->get('rds')); - $redis = &load_cache('redis'); - $redisKey = 'update_owners_different_wxqy_c_time'; - if ($rds) { - $redis->delete($redisKey); - } - $c_time = $redis->get($redisKey); - !$c_time && $c_time = strtotime(date('Y-m-d') . ' 00:00:00'); - $log = []; - $this->load->model('app/app_different_qy_log_model', 'mdWechatqyLog'); - $this->load->model('app/app_different_qy_model', 'mdWechatqy'); - $this->load->model('receiver/receiver_owners_model', 'mdOwners'); - $this->load->model('app/liche/app_liche_users_model', 'mdUsers'); - $res = $this->mdWechatqyLog->select(["c_time>=" => $c_time, "change_type in('add_external_contact','edit_external_contact')" => null] - , 'c_time asc', 1, $size, 'change_type,external_userid,c_time'); - if (!$res) { - if ($params['rds']) { - echo '1执行到当前c_time:' . date('Y-m-d H:i:s', $c_time) . '暂无数据'; - } - return; - } - foreach ($res as $key => $value) { - $c_time = $value['c_time']; - if ($value['external_userid']) { - $re_qy = $this->mdWechatqy->get(['external_userid' => $value['external_userid']]); - $mobile = $re_qy['mobile']; - if ($mobile) { - $re_own = $this->mdOwners->get(['mobile' => $mobile]); - if ($re_own) { - $this->mdOwners->update(['wxqy' => 1], ['id' => $re_own['id']]); - if ($params['rds']) { - $log[] = ['mobile' => $mobile]; - } - } - } - } - } - $redis->save($redisKey, $c_time); - if ($params['rds']) { - echo '
2执行到当前c_time:' . date('Y-m-d H:i:s', $c_time); - echo '
成功新增:
'; - if ($log) { - echo json_encode($log, JSON_UNESCAPED_UNICODE); - echo '
'; - } - echo '数据库获取:
'; - echo json_encode($res, JSON_UNESCAPED_UNICODE); - } - } - /** * Notes:更新车主企业微信 - * Created on: 2022/6/21 16:00 + * Created on: 2022/9/06 16:00 * Created by: dengbw - * https://liche-api-dev.xiaoyu.com/plan/liche/owners_wxqy?rds=1 + * https://liche-api-dev.xiaoyu.com/plan/liche/owners_wxqy?sd=1 * https://api.liche.cn/plan/liche/owners_wxqy */ public function owners_wxqy() { $params = $this->input->get(); - $size = 100;//每次最多处理多少条 + $hour = date('H.i'); + if (($hour > 22.00 && $hour < 23.55) || $params['sd']) { + if ($params['sd']) { + echo "开始执行车主[{$hour}]"; + } + } else { + echo '[22.00-23.55]执行车主[' . $hour . ']'; + return; + } + $size = 200;//每次最多处理多少条 $rds = intval($this->input->get('rds')); $redis = &load_cache('redis'); - $redisKey = 'update_owners_wxqy_c_time'; + $log_date = date('Y-m-d'); + $redisKey = 'lc_receiver_owners_id_' . $log_date; if ($rds) { $redis->delete($redisKey); } - $c_time = $redis->get($redisKey); - !$c_time && $c_time = strtotime(date('Y-m-d') . ' 00:00:00'); + $id = $redis->get($redisKey); + !$id && $id = 0; $log = []; - $this->load->model('app/app_lichene_qy_log_model', 'mdWechatqyLog'); - $this->load->model('app/app_lichene_qy_model', 'mdWechatqy'); - $this->load->model('receiver/receiver_owners_model', 'mdOwners'); - $this->load->model('app/liche/app_liche_users_model', 'mdUsers'); - $res = $this->mdWechatqyLog->select(["c_time>=" => $c_time, "change_type in('add_external_contact','edit_external_contact')" => null] - , 'c_time asc', 1, $size, 'change_type,external_userid,c_time'); + $where = ['a.id>' => $id, 'a.wxqy' => 0]; + $res = $this->db->select('a.id,a.mobile,a.u_time,b.admin_id,b.biz_id') + ->from('lc_receiver_owners as a') + ->join('lc_receiver_orders_v2 as b', "b.id=a.o_id", 'left') + ->where($where) + ->order_by('a.id asc') + ->limit($size, 0) + ->get()->result_array(); if (!$res) { - if ($params['rds']) { - echo '1执行到当前c_time:' . date('Y-m-d H:i:s', $c_time) . '暂无数据'; - } + echo '执行到车主id:' . $id . '暂无数据'; return; } + $this->load->model('receiver/receiver_owners_model', 'mdOwners'); + $this->load->model("biz/biz_model", 'mdBiz'); + $this->load->model('app/licheb/app_licheb_users_model', 'mdUsers'); + $this->load->model('app/app_lichene_qy_model', 'mdWechatqy'); + $this->load->model('app/app_different_qy_model', 'mdDifferentQy'); + $str_biz_ids = implode(',', array_unique(array_column($res, 'biz_id'))); + $map_biz = $this->mdBiz->map('id', 'city_id,type,status', ["id in({$str_biz_ids})" => null]); + $str_user_ids = implode(',', array_unique(array_column($res, 'admin_id'))); + $map_user = $this->mdUsers->map('id', 'userid', ["id in({$str_user_ids})" => null]); foreach ($res as $key => $value) { - $c_time = $value['c_time']; - if ($value['external_userid']) { - $re_qy = $this->mdWechatqy->get(['external_userid' => $value['external_userid']]); - $mobile = $re_qy['mobile']; - $type = 1; - if (!$mobile && $re_qy['unionid']) { - $re_use = $this->mdUsers->get(['unionid' => $re_qy['unionid']]); - if ($re_use['mobile']) { - $type = 2; - $mobile = $re_use['mobile']; - } + $id = $value['id']; + $biz_type = intval($map_biz[$value['biz_id']]['type']); + $userid = $map_user[$value['admin_id']]; + if ($userid) { + if ($biz_type == 5) {//异业店 + $re = $this->mdDifferentQy->get(['userid' => $userid, 'mobile' => $value['mobile']]); + } else { + $re = $this->mdWechatqy->get(['userid' => $userid, 'mobile' => $value['mobile']]); } - if ($mobile) { - $re_own = $this->mdOwners->get(['mobile' => $mobile]); - if ($re_own) { - $this->mdOwners->update(['wxqy' => 1], ['id' => $re_own['id']]); - if ($params['rds']) { - $log[] = ['mobile' => $mobile, 'type' => $type]; - } - } + if ($re) {//更新企微好友 + $this->mdOwners->update(['wxqy' => 1, 'u_time' => $value['u_time']], ['id' => $id]); + $params['sd'] && $log[] = ['id' => $id, 'mobile' => $value['mobile']]; } } } - $redis->save($redisKey, $c_time); - if ($params['rds']) { - echo '
2执行到当前c_time:' . date('Y-m-d H:i:s', $c_time); + $redis->save($redisKey, $id, 24 * 3600);//保存最后id + if ($params['sd']) { + echo '
执行到当前车主id:' . $redis->get($redisKey); echo '
成功新增:
'; if ($log) { echo json_encode($log, JSON_UNESCAPED_UNICODE); diff --git a/api/controllers/plan/Plan.php b/api/controllers/plan/Plan.php index e0fba881..558034a9 100644 --- a/api/controllers/plan/Plan.php +++ b/api/controllers/plan/Plan.php @@ -40,8 +40,7 @@ class Plan extends CI_Controller $plan[] = array('url' => base_url(array('plan', 'licheb', 'inventory_log')), 'interval' => 5);//更新盘点状态 $plan[] = array('url' => base_url(array('plan', 'liche', 'add_owners')), 'interval' => 5);//新增车主 - $plan[] = array('url' => base_url(array('plan', 'liche', 'owners_wxqy')), 'interval' => 60);//更新车主企业微信 - $plan[] = array('url' => base_url(array('plan', 'liche', 'owners_wxqy_different')), 'interval' => 60);//更新异业店车主企业微信 + $plan[] = array('url' => base_url(array('plan', 'liche', 'owners_wxqy')), 'interval' => 10);//更新车主企业微信 $plan[] = array('url' => base_url(array('plan', 'items', 'stock_log')), 'interval' => 5);//库存车辆日志 diff --git a/api/controllers/wxapp/licheb/Customers.php b/api/controllers/wxapp/licheb/Customers.php index d89951ac..585147b0 100644 --- a/api/controllers/wxapp/licheb/Customers.php +++ b/api/controllers/wxapp/licheb/Customers.php @@ -781,7 +781,8 @@ class Customers extends Wxapp } $this->customer_oplogs_model->add_batch($add_oplogs); } - $this->customers_entity->add_log($customer_id, $uid, $uname, "客户改派"); + $this->customers_entity->add_log($id, $uid, $uname, "客户改派");//改派的客户日志 + $this->customers_entity->add_log($customer_id, $uid, $uname, "客户改派");//改派后的客户日志 } } throw new Exception('分配成功', API_CODE_SUCCESS);