2020-11-23 16:30:13 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
$is_script = 1;
|
2020-11-27 10:46:39 +08:00
|
|
|
include_once __DIR__ . '/../index.php';
|
2020-11-23 16:30:13 +08:00
|
|
|
|
|
|
|
|
use app\manager\model\FollowRecord;
|
|
|
|
|
use app\manager\model\ProductOrder;
|
|
|
|
|
use app\manager\model\User;
|
|
|
|
|
use enum\user\User as UserEnum;
|
|
|
|
|
|
|
|
|
|
$user_model = new User;
|
|
|
|
|
$product_order_model = new ProductOrder;
|
2020-11-25 11:07:12 +08:00
|
|
|
$follow_record_model = new FollowRecord;
|
2020-11-23 16:30:13 +08:00
|
|
|
$user_enum = new UserEnum;
|
|
|
|
|
|
|
|
|
|
$date1 = date("Y-m-01", time());
|
|
|
|
|
$date2 = date("Y-m-d H:i:s", time());
|
|
|
|
|
$flag = date("d", time()) == date("t", time());
|
|
|
|
|
$date3 = date("Y-m-01", strtotime("-1 month"));
|
|
|
|
|
$date4 = $flag ? date("Y-m-t H:i:s", strtotime("-1 month")) : date("Y-m-d H:i:s", strtotime("-1 month"));
|
|
|
|
|
|
|
|
|
|
$time_where1 = '';
|
|
|
|
|
$time_where2 = '';
|
|
|
|
|
|
|
|
|
|
$user_id_list = [];
|
|
|
|
|
$register_id_list = [];
|
|
|
|
|
$cost_user_id_list = [];
|
|
|
|
|
$uncost_user_id_list = [];
|
2020-11-25 11:07:12 +08:00
|
|
|
$uncost_overtime_user_id_list = [];
|
|
|
|
|
$cost_overtime_user_id_list = [];
|
2020-11-23 16:30:13 +08:00
|
|
|
$finish_record_data = [];
|
|
|
|
|
$unfollow_record_data = [];
|
|
|
|
|
$last_cost_list = [];
|
|
|
|
|
|
|
|
|
|
//本月
|
|
|
|
|
$time_where1 .= " UpdateTime>='" . $date1 . "' and UpdateTime<='" . $date2 . "' ";
|
|
|
|
|
$time_where2 .= " UpdateTime>='" . $date3 . "' and UpdateTime<='" . $date4 . "' ";
|
|
|
|
|
|
|
|
|
|
//获取本月注册的用户
|
|
|
|
|
$register_user_list = $user_model->getAllManagerUser([]);
|
|
|
|
|
|
|
|
|
|
foreach ($register_user_list as $info) {
|
2020-11-25 11:07:12 +08:00
|
|
|
|
2020-11-23 16:30:13 +08:00
|
|
|
//本月注册用户
|
|
|
|
|
if (strtotime($info['CreateTime']) >= strtotime($date1) && strtotime($info['CreateTime']) <= strtotime($date2)) {
|
|
|
|
|
$register_id_list[] = $info['Id'];
|
|
|
|
|
} else {
|
|
|
|
|
$user_id_list[] = $info['Id'];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//本月注册用户消费
|
|
|
|
|
$user_month_cost_list = $product_order_model->getPreMonthCost($register_id_list, $time_where1);
|
|
|
|
|
|
|
|
|
|
foreach ($user_month_cost_list as $info) {
|
|
|
|
|
$cost_user_id_list[] = $info['UserId'];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//老用户本月消费
|
|
|
|
|
$user_now_cost_list = $product_order_model->getPreMonthCost($user_id_list, $time_where1);
|
|
|
|
|
//老用户上月消费
|
|
|
|
|
$user_last_cost_list = $product_order_model->getPreMonthCost($user_id_list, $time_where2);
|
|
|
|
|
|
2020-11-25 11:07:12 +08:00
|
|
|
foreach ($user_last_cost_list as $cost) {
|
2020-11-23 16:30:13 +08:00
|
|
|
$last_cost_list[$cost['UserId']] = $cost;
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-25 11:07:12 +08:00
|
|
|
foreach ($user_now_cost_list as $cost) {
|
|
|
|
|
$user_follow_status = $user_model->getOne(['Id' => $cost['UserId']], 'follow_status')['follow_status'];
|
2020-11-26 13:45:27 +08:00
|
|
|
if (in_array($user_follow_status, $user_enum::$Lost)) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2020-11-25 11:07:12 +08:00
|
|
|
if (isset($last_cost_list[$cost['UserId']])) {
|
|
|
|
|
if ($last_cost_list[$cost['UserId']]['money'] > $cost['money']) {
|
2020-11-23 16:30:13 +08:00
|
|
|
$uncost_user_id_list[] = $cost['UserId'];
|
|
|
|
|
} else {
|
|
|
|
|
//已完成
|
|
|
|
|
$cost_user_id_list[] = $cost['UserId'];
|
|
|
|
|
}
|
2020-11-25 16:53:29 +08:00
|
|
|
} else {
|
|
|
|
|
//已完成
|
|
|
|
|
$cost_user_id_list[] = $cost['UserId'];
|
2020-11-23 16:30:13 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//获取待跟进状态超过15天
|
2020-11-25 11:07:12 +08:00
|
|
|
$over_15_list = $follow_record_model->getOverTime();
|
|
|
|
|
foreach ($over_15_list as $info) {
|
|
|
|
|
switch ($info['follow_status']) {
|
2020-11-23 16:30:13 +08:00
|
|
|
case $user_enum::$UnfollowNotBuy:
|
2020-11-25 11:07:12 +08:00
|
|
|
$uncost_overtime_user_id_list[] = $info['user_id'];
|
|
|
|
|
break;
|
2020-11-23 16:30:13 +08:00
|
|
|
case $user_enum::$UnfollowBuyReduce:
|
2020-11-25 11:07:12 +08:00
|
|
|
$cost_overtime_user_id_list[] = $info['user_id'];
|
|
|
|
|
break;
|
2020-11-23 16:30:13 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$user_model->updateOne(['Id' => ['in', $cost_user_id_list]], ['follow_status' => $user_enum::$Finish]);
|
2020-11-25 12:05:56 +08:00
|
|
|
$user_model->updateOne(['Id' => ['in', $uncost_user_id_list]], ['follow_status' => $user_enum::$UnfollowBuyReduce]);
|
2020-11-25 11:07:12 +08:00
|
|
|
$user_model->updateOne(['Id' => ['in', $uncost_overtime_user_id_list]], ['follow_status' => $user_enum::$FollowOverTimeNotBuy]);
|
|
|
|
|
$user_model->updateOne(['Id' => ['in', $cost_overtime_user_id_list]], ['follow_status' => $user_enum::$FollowOverTimeBuyReduce]);
|
|
|
|
|
|
2020-11-25 13:22:00 +08:00
|
|
|
//获取所有用户的最后支付时间
|
|
|
|
|
$all_last_cost = $product_order_model->getUserCostTime();
|
|
|
|
|
$user_last_cost_id = [];
|
|
|
|
|
$all_last_cost_list = [];
|
2020-11-25 13:28:22 +08:00
|
|
|
foreach ($all_last_cost as $info) {
|
2020-11-25 13:22:00 +08:00
|
|
|
$all_last_cost_list[$info['UserId']] = $info;
|
|
|
|
|
$user_last_cost_id[] = $info['UserId'];
|
2020-11-25 11:35:37 +08:00
|
|
|
}
|
2020-11-25 13:22:00 +08:00
|
|
|
//更新用户最后的支付时间
|
2020-11-26 13:45:27 +08:00
|
|
|
$all_user_list = $user_model->getList(['Id' => ['in', $user_last_cost_id]], 'Id,pay_time');
|
2020-11-25 11:35:37 +08:00
|
|
|
|
2020-11-26 13:45:27 +08:00
|
|
|
foreach ($all_user_list as $info) {
|
|
|
|
|
if ($info['pay_time'] != $all_last_cost_list[$info['Id']]['last_time']) {
|
|
|
|
|
$user_model->updateOne(['Id' => $info['Id']], ['pay_time' => $all_last_cost_list[$info['Id']]['last_time']]);
|
2020-11-25 13:22:00 +08:00
|
|
|
}
|
2020-11-26 13:45:27 +08:00
|
|
|
}
|