302 lines
13 KiB
PHP
302 lines
13 KiB
PHP
<?php
|
||
|
||
/**
|
||
* Notes:狸车宝任务
|
||
* Created on: 2021/10/19 17:15
|
||
* Created by: dengbw
|
||
*/
|
||
class Licheb extends HD_Controller
|
||
{
|
||
|
||
private $log_file;
|
||
|
||
public function __construct()
|
||
{
|
||
parent::__construct();
|
||
$this->log_file = 'licheb.log';
|
||
$this->load->model('receiver/receiver_customers_model', 'mdCustomers');
|
||
$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/visit_sales_sms
|
||
* https://api.liche.cn/plan/licheb/visit_sales_sms
|
||
*/
|
||
public function visit_sales_sms()
|
||
{
|
||
$params = $this->input->get();
|
||
$hour = date('H');
|
||
if ($hour != '09' && !$params['sd']) {
|
||
echo '[9]点过后才会开始执行发短信给销售[' . $hour . ']';
|
||
return;
|
||
}
|
||
$size = 100;//每次最多处理多少条
|
||
$rds = intval($this->input->get('rds'));
|
||
$redis = &load_cache('redis');
|
||
$redisKey = 'visit_sales_sms_id';
|
||
$day = date('Y-m-d');
|
||
$re_v = $this->mdCustomersVisit->get(array('day' => $day));//查找当天是否有数据
|
||
if (!$re_v || $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' => 1);
|
||
$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 = array("a.biz_id in ($biz_id)" => null, 'a.admin_id' => $id, 'b.contact' => 1, 'b.status' => 1, 'b.day=' => $day);
|
||
$visit_count = $this->mdCustomersVisit->count_visit($where_v);
|
||
if ($visit_count) {//发送短信
|
||
send_alisms(array('mobile' => $value['mobile'], 'template' => 'SMS_226985259', 'param' => ['count' => $visit_count]));
|
||
$log[] = array('id' => $id, 'mobile' => $value['mobile'], 'count' => $visit_count);
|
||
}
|
||
}
|
||
$redis->save($redisKey, $id);//保存最后销售id
|
||
if ($params['sd']) {
|
||
echo '<br>执行到当前销售id:' . $redis->get($redisKey);
|
||
echo '<br>成功新增:<br>';
|
||
if ($log) {
|
||
echo json_encode($log, JSON_UNESCAPED_UNICODE);
|
||
echo '<br>';
|
||
}
|
||
echo '数据库获取:<br>';
|
||
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');
|
||
if ($hour != '09' && !$params['sd']) {
|
||
echo '[9]点过后才会开始执行发短信给销售[' . $hour . ']';
|
||
return;
|
||
}
|
||
$size = 100;//每次最多处理多少条
|
||
$rds = intval($this->input->get('rds'));
|
||
$redis = &load_cache('redis');
|
||
$redisKey = 'customer_manager_sms_id';
|
||
$day = date('Y-m-d');
|
||
$re_v = $this->mdCustomersVisit->get(array('day' => $day));//查找当天是否有数据
|
||
if (!$re_v || $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'];
|
||
$where_c = array("biz_id in ($biz_id)" => null, 'status>=' => 0, 'admin_id' => 0);
|
||
$Customers_count = $this->mdCustomers->count($where_c);
|
||
if ($Customers_count) {//发送短信
|
||
send_alisms(array('mobile' => $value['mobile'], 'template' => 'SMS_226970475', 'param' => ['count' => $Customers_count]));
|
||
$log[] = array('id' => $id, 'mobile' => $value['mobile'], 'count' => $Customers_count);
|
||
}
|
||
}
|
||
$redis->save($redisKey, $id);//保存最后销售id
|
||
if ($params['sd']) {
|
||
echo '<br>执行到当前店长id:' . $redis->get($redisKey);
|
||
echo '<br>成功新增:<br>';
|
||
if ($log) {
|
||
echo json_encode($log, JSON_UNESCAPED_UNICODE);
|
||
echo '<br>';
|
||
}
|
||
echo '数据库获取:<br>';
|
||
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_visit
|
||
* https://api.liche.cn/plan/licheb/customer_visit
|
||
*/
|
||
public function customer_visit()
|
||
{
|
||
$params = $this->input->get();
|
||
$hour = date('H');
|
||
if ($hour != '00' && !$params['sd']) {
|
||
echo '[0]点过后才会开始执行客户待回访[' . $hour . ']';
|
||
return;
|
||
}
|
||
$size = 100;//每次最多处理多少条
|
||
$rds = intval($this->input->get('rds'));
|
||
$redis = &load_cache('redis');
|
||
$redisVisit = 'customers_visit_cid';
|
||
$day = date('Y-m-d');
|
||
$day_1 = date('Y-m-d', strtotime('-1 day'));//前1天
|
||
$day_7 = date('Y-m-d', strtotime('-7 day'));//1周前
|
||
$day_30 = date('Y-m-d', strtotime('-1 month'));//1个月前
|
||
$re_v = $this->mdCustomersVisit->get(array('day' => $day));//查找当天是否有数据
|
||
if (!$re_v || $rds) {
|
||
$redis->delete($redisVisit);
|
||
}
|
||
$c_id = $redis->get($redisVisit);
|
||
!$c_id && $c_id = 0;
|
||
$log = array();
|
||
$where = array('id >' => $c_id, 'status in(0,1)' => null, 'admin_id >' => 0, 'level <>' => 'D'
|
||
, 'c_time >=' => strtotime('2021-10-25 00:00:00'), 'c_time <' => strtotime($day . ' 00:00:00'));
|
||
$res_c = $this->mdCustomers->select($where, 'id asc', 1, $size, 'id,level,c_time');
|
||
if (!$res_c) {
|
||
echo '执行到当前客户id:' . $c_id . '暂无数据';
|
||
return;
|
||
}
|
||
foreach ($res_c as $key => $value) {
|
||
$c_id = $value['id'];
|
||
$level = $value['level'];
|
||
$if_add = 0;
|
||
// $up_level = '';
|
||
// if ($level == 'h') {
|
||
// $up_level = 'H';
|
||
// } else if ($level == 'a') {
|
||
// $up_level = 'A';
|
||
// } else if ($level == 'b') {
|
||
// $up_level = 'B';
|
||
// } else if ($level == 'c') {
|
||
// $up_level = 'C';
|
||
// }
|
||
// if ($up_level) {//小写更新为大写
|
||
// $ret = $this->mdCustomers->update(array('level' => $up_level), array('id' => $c_id));
|
||
// $ret && $level = $up_level;
|
||
// }
|
||
if ($level == 'H') {//每天回访一次
|
||
$re_v = $this->mdCustomersVisit->get(array('day' => $day, 'c_id' => $c_id));
|
||
!$re_v && $if_add = 1;
|
||
} else if ($level == 'A' && ($value['c_time'] < strtotime('-1 day'))) {//隔一天打
|
||
$re_v = $this->mdCustomersVisit->get(array('day>=' => $day_1, 'day<=' => $day, 'c_id' => $c_id));
|
||
!$re_v && $if_add = 1;
|
||
} else if ($level == 'B' && ($value['c_time'] < strtotime('-7 day'))) {//一周回访一次
|
||
$re_v = $this->mdCustomersVisit->get(array('day>=' => $day_7, 'day<=' => $day, 'c_id' => $c_id));
|
||
!$re_v && $if_add = 1;
|
||
} else if ($level == 'C' && ($value['c_time'] < strtotime('-1 month'))) {//一个月打一次
|
||
$re_v = $this->mdCustomersVisit->get(array('day>=' => $day_30, 'day<=' => $day, 'c_id' => $c_id));
|
||
!$re_v && $if_add = 1;
|
||
}
|
||
if ($if_add) {
|
||
$this->mdCustomersVisit->update(array('status' => 2), array('c_id' => $c_id, 'status' => 1));
|
||
$id = $this->mdCustomersVisit->add(array('c_id' => $c_id, 'day' => $day, 'level' => $level, 'c_time' => time()));
|
||
$log[] = array('id' => $c_id, 'add_id' => $id);
|
||
}
|
||
}
|
||
$redis->save($redisVisit, $c_id);//保存最后客户id
|
||
if ($params['sd']) {
|
||
echo '<br>执行到当前客户id:' . $redis->get($redisVisit);
|
||
echo '日期:' . json_encode(array('day' => $day, 'day_1' => $day_1, 'day_7' => $day_7, 'day_30' => $day_30), JSON_UNESCAPED_UNICODE);
|
||
echo '<br>成功新增:<br>';
|
||
if ($log) {
|
||
echo json_encode($log, JSON_UNESCAPED_UNICODE);
|
||
echo '<br>';
|
||
}
|
||
echo '数据库获取:<br>';
|
||
echo json_encode($res_c, JSON_UNESCAPED_UNICODE);
|
||
}
|
||
}
|
||
|
||
/**
|
||
* Notes:更新客户等级
|
||
* Created on: 2021/10/19 17:15
|
||
* Created by: dengbw
|
||
* https://liche-api-dev.xiaoyu.com/plan/licheb/customer_level
|
||
* https://api.liche.cn/plan/licheb/customer_level
|
||
*/
|
||
public function customer_level()
|
||
{
|
||
$params = $this->input->get();
|
||
$hour = date('H');
|
||
if ($hour != '23' && !$params['sd']) {
|
||
echo '[23]点过后才会更新客户等级[' . $hour . ']';
|
||
return;
|
||
}
|
||
$size = 100;//每次最多处理多少条
|
||
$rds = intval($this->input->get('rds'));
|
||
$redis = &load_cache('redis');
|
||
$redisVisit = 'customers_level_cid';
|
||
$day = date('Y-m-d');
|
||
$day_1 = date('Y-m-d', strtotime('-1 day'));//前1天
|
||
$day_7 = date('Y-m-d', strtotime('-7 day'));//1周前
|
||
$day_14 = date('Y-m-d', strtotime('-14 day'));//2周前
|
||
$day_30 = date('Y-m-d', strtotime('-1 month'));//1个月前
|
||
$re_v = $this->mdCustomersVisit->get(array('day' => $day));//查找当天是否有数据
|
||
if (!$re_v || $rds) {
|
||
$redis->delete($redisVisit);
|
||
}
|
||
$c_id = $redis->get($redisVisit);
|
||
!$c_id && $c_id = 0;
|
||
$log = array();
|
||
$where = array('id >' => $c_id, 'status in(0,1)' => null, 'admin_id >' => 0, 'level <>' => 'D'
|
||
, 'c_time >=' => strtotime('2021-10-25 00:00:00'), 'c_time <' => strtotime($day . ' 00:00:00'));
|
||
$res_c = $this->mdCustomers->select($where, 'id asc', 1, $size, 'id,level');
|
||
if (!$res_c) {
|
||
echo '执行到当前客户id:' . $c_id . '暂无数据';
|
||
return;
|
||
}
|
||
$this->load->library('receiver/customers_entity');
|
||
foreach ($res_c as $key => $value) {
|
||
$c_id = $value['id'];
|
||
$level = $value['level'];
|
||
$up_level = '';
|
||
if ($level == 'H') {//每天回访一次,打7天后降为A
|
||
$count = $this->mdCustomersVisit->count(array('day>=' => $day_7, 'day<=' => $day, 'c_id' => $c_id, 'level' => $level));
|
||
$count >= 7 && $up_level = 'A';
|
||
} else if ($level == 'A') {//隔一天打,打2周后降B
|
||
$count = $this->mdCustomersVisit->count(array('day>=' => $day_14, 'day<=' => $day, 'c_id' => $c_id, 'level' => $level));
|
||
$count >= 7 && $up_level = 'B';
|
||
} else if ($level == 'B') {//一周回访一次,1个月后降C
|
||
$count = $this->mdCustomersVisit->count(array('day>=' => $day_30, 'day<=' => $day, 'c_id' => $c_id, 'level' => $level));
|
||
$count >= 4 && $up_level = 'C';
|
||
}
|
||
if ($up_level) {//降级更新
|
||
$ret = $this->mdCustomers->update(array('level' => $up_level), array('id' => $c_id));
|
||
if ($ret) {
|
||
$this->customers_entity->add_log($c_id, 0, '系统', '客户等级从' . $level . '降级到' . $up_level);
|
||
$log[] = array('id' => $c_id, 'level' => $level, 'up_level' => $up_level);
|
||
}
|
||
}
|
||
}
|
||
$redis->save($redisVisit, $c_id);//保存最后客户id
|
||
if ($params['sd']) {
|
||
echo '<br>执行到当前客户id:' . $redis->get($redisVisit);
|
||
echo '日期:' . json_encode(array('day' => $day, 'day_1' => $day_1, 'day_7' => $day_7, 'day_14' => $day_14
|
||
, 'day_30' => $day_30), JSON_UNESCAPED_UNICODE);
|
||
echo '<br>成功更新:<br>';
|
||
if ($log) {
|
||
$_data = json_encode($log, JSON_UNESCAPED_UNICODE);
|
||
echo $_data;
|
||
echo '<br>';
|
||
debug_log('降级客户:' . $_data, $this->log_file);
|
||
}
|
||
echo '数据库获取:<br>';
|
||
echo json_encode($res_c, JSON_UNESCAPED_UNICODE);
|
||
}
|
||
}
|
||
|
||
} |