diff --git a/admin/controllers/receiver/Clues.php b/admin/controllers/receiver/Clues.php
index e3a347bd..b90f9a5a 100644
--- a/admin/controllers/receiver/Clues.php
+++ b/admin/controllers/receiver/Clues.php
@@ -591,6 +591,12 @@ class Clues extends HD_Controller
$this->load->library('receiver/customers_entity');
$this->customers_entity->syn_clues($customers_id, $re['id']);
+ //短信通知店长
+ $this->load->model('app/licheb/app_licheb_users_model');
+ $where = array('biz_id' => $re['biz_id'], 'status' => 1, 'group_id' => 2);
+ $res_u = $this->app_licheb_users_model->get($where);
+ b2m_send_sms($res_u['mobile'], '【理车宝】您好,门店新增了1个客户线索。请及时到小程序"理车宝-待分配客户”分配给销售顾问跟进。祝您生活愉快!');
+
$msg = '移交成功';
} else {
$code = SYS_CODE_FAIL;
diff --git a/admin/controllers/receiver/Customer.php b/admin/controllers/receiver/Customer.php
index bd2d05a4..ad572d3e 100644
--- a/admin/controllers/receiver/Customer.php
+++ b/admin/controllers/receiver/Customer.php
@@ -127,7 +127,7 @@ class Customer extends HD_Controller
$qdjl_lists = $this->app_licheb_users_model->select(array('group_id' => 4, 'status' => 1, 'biz_id<>' => '0'), 'id desc', 0, 0, 'id,uname as name');
$show_info['levelAry'] = $this->customers_model->get_sdata('level');
$show_info['cfroms'] = $this->clues_cfrom_model->map('id', 'title', array('status' => 1, 'pid' => 0), '', 0, 0, 'id, title');
- $show_info['cfroms2'] = $this->clues_cfrom_model->map('id', 'title', array('status' => 1, 'pid' => $params['of_id']), '', 0, 0, 'id, title');
+ $show_info['cfroms2'] = $params['of_id'] ? $this->clues_cfrom_model->map('id', 'title', array('status' => 1, 'pid' => $params['of_id']), '', 0, 0, 'id, title') : [];
$show_info['wxgrAry'] = $wxgrAry;
$this->data['show_info'] = $show_info;
$this->data['lists'] = $lists;
diff --git a/api/controllers/plan/Licheb.php b/api/controllers/plan/Licheb.php
new file mode 100644
index 00000000..40a49c03
--- /dev/null
+++ b/api/controllers/plan/Licheb.php
@@ -0,0 +1,313 @@
+log_file = 'licheb.log';
+ $this->load->model('receiver/receiver_customers_model', 'mdCustomers');
+ }
+
+ /**
+ * Notes:更新客户回访记录
+ * Created on: 2022/05/24 17:15
+ * Created by: dengbw
+ * https://liche-api-dev.xiaoyu.com/plan/licheb/visit_data?sd=1
+ * https://api.liche.cn/plan/licheb/visit_data
+ */
+ public function visit_data()
+ {
+ $params = $this->input->get();
+ $hour = date('H.i');
+ if (($hour > 00.00 && $hour < 02.00) || $params['sd']) {
+ if ($params['sd']) {
+ echo "开始执行客户回访[{$hour}]
";
+ }
+ } else {
+ echo '[00.00-02.00]执行客户回访[' . $hour . ']
';
+ return;
+ }
+ $this->load->model('receiver/receiver_customers_visit_data_model', 'mdCustomerVisitData');
+ $time = strtotime("-1 day");//昨天此时的时间戳
+ $size = 200;//每次最多处理多少条
+ $rds = intval($this->input->get('rds'));
+ $redis = &load_cache('redis');
+ $t_day = date('Y-m-d', $time);
+ $redisKey = 'app_licheb_visit_data_id_' . $t_day;
+ if ($rds) {
+ $redis->delete($redisKey);
+ }
+ $id = $redis->get($redisKey);
+ !$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,pid');
+ if (!$res) {
+ echo '执行到当前客户回访id:' . $id . '暂无数据';
+ return;
+ }
+ $this->load->model('receiver/receiver_customers_visit_sales_model', 'mdCustomerVisitSales');
+ $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');//今天
+ foreach ($res as $key => $value) {
+ $id = $value['id'];
+ $re_opl = $this->mdCustomerOpLogs->get(['customer_id' => $value['c_id'], 'uid' => $value['sales_id'], 'type in(0,1,2)' => null, 'c_time>=' => $s_time, 'c_time<=' => $e_time]);
+ if ($re_opl) {
+ //已跟进
+ $this->mdCustomerVisitData->update(['status' => 2], ['id' => $value['id']]);
+ } else {
+ //只跟进status 0未见客户1到店客户
+ $re_cust = $this->mdCustomers->get(['id' => $value['c_id'], 'status in(0,1)' => null]);
+ if (!$re_cust) {
+ continue;
+ }
+ $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'];
+ $where_vis['c_time'] = time();
+ $add_id = $this->mdCustomerVisitData->add($where_vis);
+ if ($add_id) {
+ //更新回访时间
+ $this->mdCustomers->update(['visit_time' => $today], ['id' => $value['c_id']]);
+ $params['sd'] && $log[] = $where_vis;
+ }
+ }
+ }
+ }
+
+ $redis->save($redisKey, $id, 24 * 3600);//保存最后id
+ if ($params['sd']) {
+ echo '
执行到当前客户回访id:' . $redis->get($redisKey);
+ echo ' 日期:' . $t_day;
+ echo '
成功新增:
';
+ if ($log) {
+ echo json_encode($log, JSON_UNESCAPED_UNICODE);
+ echo '
';
+ }
+ echo '数据库获取:
';
+ echo json_encode($res, JSON_UNESCAPED_UNICODE);
+ }
+ }
+
+ /**
+ * Notes:客户回访顾问统计
+ * Created on: 2022/05/24 17:15
+ * Created by: dengbw
+ * https://liche-api-dev.xiaoyu.com/plan/licheb/visit_sales?sd=1
+ * https://api.liche.cn/plan/licheb/visit_sales
+ */
+ public function visit_sales()
+ {
+ $params = $this->input->get();
+ $hour = date('H.i');
+ if (($hour > 02.00 && $hour < 04.00) || $params['sd']) {
+ if ($params['sd']) {
+ echo "开始执行库顾问日志[{$hour}]
";
+ }
+ } else {
+ echo '[02.00-04.00]执行顾问日志[' . $hour . ']
';
+ return;
+ }
+ $this->load->model('app/licheb/app_licheb_users_model', 'mdUsers');
+ $this->load->model('receiver/receiver_customers_visit_data_model', 'mdCustomerVisitData');
+ $this->load->model('receiver/receiver_customers_visit_sales_model', 'mdCustomerVisitSales');
+ $time = strtotime("-1 day");//昨天此时的时间戳
+
+ $size = 200;//每次最多处理多少条
+ $rds = intval($this->input->get('rds'));
+ $redis = &load_cache('redis');
+ $t_day = date('Y-m-d', $time);
+ $redisKey = 'app_licheb_visit_sales_id_' . $t_day;
+
+// if ($rds) {
+// $redis->delete($redisKey);
+// }
+ $id = $redis->get($redisKey);
+ !$id && $id = 0;
+ $log = [];
+ $where = ['id >' => $id, 'group_id in (1,2,3)' => null, 'status' => 1];
+ $res = $this->mdUsers->select($where, 'id asc', 1, $size, 'id,biz_id');
+
+ if (!$res) {
+ echo '执行到当前顾问id:' . $id . '暂无数据';
+ return;
+ }
+ foreach ($res as $key => $value) {
+ $sales_id = $id = $value['id'];
+ $biz_id = intval($value['biz_id']);
+// if ($biz_id == 1 || $biz_id == 110) {//门店用户不写入
+// continue;
+// }
+ $where_sal = ['t_day' => $t_day, 'sales_id' => $sales_id, 'biz_id' => $biz_id];
+ $re_sal = $this->mdCustomerVisitSales->get($where_sal);
+ if (!$re_sal) {//判断当天是否已加入
+ $t_follows = $this->mdCustomerVisitData->count(array_merge($where_sal, ['status' => 1]));
+ $h_follows = $this->mdCustomerVisitData->count(array_merge($where_sal, ['status' => 2]));
+ $w_follows = $this->mdCustomerVisitData->count(array_merge($where_sal, ['status' => 3]));
+ #这里的逾期未跟进数 需要把 已改派 的过滤掉
+ #$w_follows = $this->mdCustomerVisitData->count(array_merge($where_sal, ['status' => 3], ['c_id in (select id from lc_receiver_customers where cs_biz_id >= 0)' => null]));
+ $add_item = ['t_day' => $t_day, 'sales_id' => $sales_id, 'biz_id' => $biz_id, 't_follows' => $t_follows, 'h_follows' => $h_follows, 'w_follows' => $w_follows, 'c_time' => time()];
+ $add_id = $this->mdCustomerVisitSales->add($add_item);
+ if ($add_id && $params['sd']) {
+ $log[] = array('id' => $sales_id, 'add_item' => $add_item);
+ }
+ }
+ }
+ $redis->save($redisKey, $id, 24 * 3600);//保存最后id
+ if ($params['sd']) {
+ echo '
执行到当前顾问id:' . $redis->get($redisKey);
+ echo ' 日期:' . $t_day;
+ 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
+ * Created by: dengbw
+ * https://liche-api-dev.xiaoyu.com/plan/licheb/visit_sales_sms?sd=1
+ * https://api.liche.cn/plan/licheb/visit_sales_sms
+ */
+ public function visit_sales_sms()
+ {
+ $params = $this->input->get();
+ $hour = date('H.i');
+ if (($hour > 09.00 && $hour < 10.00) || $params['sd']) {
+ if ($params['sd']) {
+ echo "开始执行发短信给销售[{$hour}]
";
+ }
+ } else {
+ echo '[09.00-10.00]点过才会开始执行发短信给销售[' . $hour . ']
';
+ return;
+ }
+ $size = 100;//每次最多处理多少条
+ $rds = intval($this->input->get('rds'));
+ $redis = &load_cache('redis');
+ $t_day = date('Y-m-d');
+ $redisKey = 'visit_sales_sms_id_' . $t_day;
+ if ($rds) {
+ $redis->delete($redisKey);
+ }
+ $id = $redis->get($redisKey);
+ !$id && $id = 0;
+ $log = array();
+ $this->load->model('receiver/receiver_customers_visit_data_model', 'mdCustomerVisitData');
+ $this->load->model('app/licheb/app_licheb_users_model', 'mdUsers');
+ $where = array('id >' => $id, 'status' => 1, 'group_id in (1,2)' => null);
+ $res_u = $this->mdUsers->select($where, 'id asc', 1, $size, 'id,biz_id,mobile');
+ if (!$res_u) {
+ echo '执行到当前销售id:' . $id . '暂无数据';
+ return;
+ }
+ foreach ($res_u as $key => $value) {
+ $id = $value['id'];
+ $biz_id = $value['biz_id'];
+ $where_v = ['a.biz_id' => $biz_id, 'a.status in(0,1)' => null, 'b.t_day' => $t_day, 'b.sales_id' => $id, 'b.status<>' => 2];
+ $visit_count = $this->mdCustomerVisitData->count_visit($where_v);
+
+ if ($visit_count) {//发送短信
+ b2m_send_sms($value['mobile'], '【理车宝】您好,今天共有 '.$visit_count.' 个客户需要回访,线索来之不易,请及时跟进~');
+ $log[] = array('id' => $id, 'mobile' => $value['mobile'], 'count' => $visit_count);
+ }
+ }
+ $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);
+ echo '
';
+ }
+ echo '数据库获取:
';
+ echo json_encode($res_u, JSON_UNESCAPED_UNICODE);
+ }
+ }
+
+ /**
+ * Notes:给店长发送待分配短信
+ * Created on: 2021/10/19 17:15
+ * Created by: dengbw
+ * https://liche-api-dev.xiaoyu.com/plan/licheb/customer_manager_sms
+ * https://api.liche.cn/plan/licheb/customer_manager_sms
+ */
+ public function customer_manager_sms()
+ {
+ $params = $this->input->get();
+ $hour = date('H.i');
+ if (($hour > 09.00 && $hour < 10.00) || $params['sd']) {
+ if ($params['sd']) {
+ echo "开始执行发短信给店长[{$hour}]
";
+ }
+ } else {
+ echo '[09.00-10.00]点过才会开始执行发短信给店长[' . $hour . ']
';
+ return;
+ }
+ $this->load->model('receiver/receiver_customers_visit_model', 'mdCustomersVisit');
+ $size = 100;//每次最多处理多少条
+ $rds = intval($this->input->get('rds'));
+ $redis = &load_cache('redis');
+ $t_day = date('Y-m-d');
+ $redisKey = 'customer_manager_sms_id_' . $t_day;
+
+ if ($rds) {
+ $redis->delete($redisKey);
+ }
+ $id = $redis->get($redisKey);
+ !$id && $id = 0;
+ $log = array();
+ $this->load->model('app/licheb/app_licheb_users_model', 'mdUsers');
+ $where = array('id >' => $id, 'status' => 1, 'group_id' => 2);
+ $res_u = $this->mdUsers->select($where, 'id asc', 1, $size, 'id,biz_id,mobile');
+
+ if (!$res_u) {
+ echo '执行到当前店长id:' . $id . '暂无数据';
+ return;
+ }
+ foreach ($res_u as $key => $value) {
+ $id = $value['id'];
+ $biz_id = $value['biz_id'];
+// if ($biz_id == '1' || $biz_id == '110') {
+// continue;
+// }
+ $where_c = array("biz_id in ($biz_id)" => null, 'status' => 0, 'admin_id' => 0);
+ $Customers_count = $this->mdCustomers->count($where_c);
+ if ($Customers_count) {
+ //发送短信
+ b2m_send_sms($value['mobile'], '【理车宝】您好,门店有 '.$Customers_count.' 个客户线索尚未分配。请及时到小程序"理车宝-待分配客户”分配给销售顾问跟进。祝您生活愉快!');
+ $log[] = array('id' => $id, 'mobile' => $value['mobile'], 'count' => $Customers_count);
+ }
+ }
+ $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);
+ echo '
';
+ }
+ echo '数据库获取:
';
+ echo json_encode($res_u, JSON_UNESCAPED_UNICODE);
+ }
+ }
+}
\ No newline at end of file
diff --git a/api/controllers/plan/Plan.php b/api/controllers/plan/Plan.php
new file mode 100644
index 00000000..c60ac6f9
--- /dev/null
+++ b/api/controllers/plan/Plan.php
@@ -0,0 +1,151 @@
+log_dir = "plan";
+
+ $plan = array();
+ //执行失败的plan重跑
+ $plan[] = array('url' => base_url(array('plan', 'plan', 'replan')), 'interval' => 1);
+ $plan[] = array('url' => base_url(array('plan', 'licheb', 'visit_data')), 'interval' => 3);//更新客户回访记录
+ $plan[] = array('url' => base_url(array('plan', 'licheb', 'visit_sales')), 'interval' => 3);//客户回访顾问统计
+ $plan[] = array('url' => base_url(array('plan', 'licheb', 'visit_sales_sms')), 'interval' => 2);//给销售发送待回访短信
+ $plan[] = array('url' => base_url(array('plan', 'licheb', 'customer_manager_sms')), 'interval' => 2);//给店长发送待分配短信
+ //$plan[] = array('url' => base_url(array('plan', 'licheb', 'users_log')), 'interval' => 2);//顾问日志
+ //$plan[] = array('url' => base_url(array('plan', 'licheb', 'bizs_log')), 'interval' => 2);//门店日志
+
+ $this->plan = $plan;
+ }
+
+ public function last_runtime()
+ {
+ $redis = &load_cache('redis');
+ $value = $redis->get($this->key_last_runtime);
+ !$value && $value = 0;
+ $dts = $value ? date("Y-m-d H:i:s", $value) : '';
+ echo json_encode(array('last_runtime' => $value, 'datetime' => $dts), JSON_UNESCAPED_UNICODE);
+ }
+
+ public function index()
+ {
+ $plan = $this->plan;
+
+ if ($plan) {
+ $redis = &load_cache('redis');
+
+ echo "------ mission start " . date("Y-m-d H:i:s") . " ------\n";
+
+ foreach ($plan as $v) {
+ $key = 'hd_plan_job_' . md5($v['url']);
+
+ if (!$redis->get($key)) {
+ $this->benchmark->mark('code_start');
+ $res = $this->get_https($v['url']);
+ $res && $redis->save($key, 1, $v['interval'] * 60);
+ $this->benchmark->mark('code_end');
+
+ echo $v['url'] . " --- mission" . ($res ? " succ" : " fail") . " spend:" . $this->benchmark->elapsed_time('code_start', 'code_end') . "\n";
+ }
+ }
+
+ echo "Finished " . date("Y-m-d H:i:s") . "\n";
+ }
+
+ $redis = &load_cache('redis');
+ $redis->save($this->key_last_runtime, time());
+ }
+
+ /*
+ * 重置计划脚本
+ */
+ public function reset_plan()
+ {
+ $id = $this->input->get('id');
+
+ $v = $this->plan[$id];
+
+ echo json_encode($v, JSON_UNESCAPED_UNICODE) . "\n";
+
+ if ($v) {
+ $key = 'hd_plan_job_' . md5($v['url']);
+
+ $redis = &load_cache('redis');
+
+ if ($redis->get($key)) {
+ $ret = $redis->delete($key);
+ echo "redis del: {$ret}\n";
+ } else {
+ echo "redis not save\n";
+ }
+ }
+ }
+
+ //执行异常的脚本重新跑
+ public function replan()
+ {
+ $redis = &load_cache('redis');
+ $redis = $redis->redis();
+
+ $key_batch = "return_plan_batch";
+
+ $now = time();
+ $rows = $redis->zRangeByScore($key_batch, 0, $now);
+ debug_log("[info]# return_plan_batch:" . json_encode($rows), __FUNCTION__, $this->log_dir);
+ echo "return_plan_batch:" . json_encode($rows) . " \n";
+
+ $total = count($rows);
+ $done = 0;
+ foreach ($rows as $k => $v) {
+ $url = $v;
+
+ $res = $this->get_https($url);
+ debug_log("[info]# url={$url}; res={$res}", __FUNCTION__, $this->log_dir);
+ if ($res) {
+ $done++;
+ }
+ $redis->zRem($key_batch, $v);
+ }
+
+ $msg = "all:{$total}; done:{$done}";
+ debug_log("[info]# {$msg}", __FUNCTION__, $this->log_dir);
+ echo $msg;
+ }
+
+ private function get_https($url)
+ {
+ $curl = curl_init();
+ curl_setopt($curl, CURLOPT_URL, $url);
+ curl_setopt($curl, CURLOPT_HEADER, 1);
+ curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
+ curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE); //这个是重点,规避ssl的证书检查。
+ curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE); // 跳过host验证
+
+ curl_exec($curl);
+
+ if (curl_errno($curl)) {
+ curl_close($curl);
+ return false;
+ }
+
+ curl_close($curl);
+ return true;
+ }
+
+}
diff --git a/api/controllers/wxapp/licheb/Sms.php b/api/controllers/wxapp/licheb/Sms.php
index c4f17f33..25cfec5b 100644
--- a/api/controllers/wxapp/licheb/Sms.php
+++ b/api/controllers/wxapp/licheb/Sms.php
@@ -44,7 +44,7 @@ class Sms extends Wxapp
$code = random_string('numeric', 6);
$mc->save($key, $code, 600);
}
- $content = "【{$this->smsSign}】" . "您的验证码为:{$code},请勿泄露于他们!";
+ $content = "【{$this->smsSign}】" . "您的验证码为:{$code},请勿泄露于他人!";
b2m_send_sms($mobile, $content);
$msg = '发送成功';
throw new Exception($msg, API_CODE_SUCCESS);
diff --git a/api/controllers/wxapp/licheb/User.php b/api/controllers/wxapp/licheb/User.php
index 2939f4af..f1867e45 100644
--- a/api/controllers/wxapp/licheb/User.php
+++ b/api/controllers/wxapp/licheb/User.php
@@ -324,8 +324,8 @@ class User extends Wxapp
$defeat_count = $this->customers_model->count(['biz_id' => $biz_id, 'cs_biz_id<>' => -1, 'if_defeat' => 1, 'status>' => -1]);
$clues_count = $this->clues_model->count(['biz_id' => $biz_id, 'status' => 0]);
$customer_op_list = [
- ['title' => '待分配客户(人)', 'icon' => 'icon-daifenpei', 'total' => $unuse_count, 'page' => '/pages/customer/allot/index'],
['title' => '线索池(人)', 'icon' => 'icon-daifenpei', 'total' => $clues_count, 'page' => '/pages/clues/index'],
+ ['title' => '待分配客户(人)', 'icon' => 'icon-daifenpei', 'total' => $unuse_count, 'page' => '/pages/customer/allot/index'],
['title' => '战败申请(人)', 'icon' => 'icon-statistics-custom-5', 'total' => $defeat_count, 'page' => '/pages/customer/optDefeat/index'],
];
diff --git a/common/models/receiver/Receiver_customers_visit_sales_model.php b/common/models/receiver/Receiver_customers_visit_sales_model.php
new file mode 100644
index 00000000..c7a384d9
--- /dev/null
+++ b/common/models/receiver/Receiver_customers_visit_sales_model.php
@@ -0,0 +1,19 @@
+table_name, 'default');
+ }
+
+}