更新 线下预约 推送和取消逻辑

main
yanzai 2 months ago
parent 982df592f3
commit 7f55a939b4

@ -758,12 +758,13 @@ class OrderNewController extends Controller
$type = request('type');//1通知2取消 $type = request('type');//1通知2取消
$now = new DateTime(); $now = new DateTime();
// 时间点1当前时间 +1 个月
$date1 = (clone $now)->modify('+1 month')->format('Y-m-d H:i:00'); $date1 = (clone $now)->modify('+1 month')->format('Y-m-d H:i:00');
// 时间点2当前时间 +7 天
$date2 = (clone $now)->modify('+7 days')->format('Y-m-d H:i:00'); $date2 = (clone $now)->modify('+23 days')->format('Y-m-d H:i:00');
// 时间点3当前时间 +6 天(你定义了 $date3但没用上这里也加上可选
$date3 = (clone $now)->modify('+6 days')->format('Y-m-d H:i:00'); // 时间点3date1 + 8 天
$date3 = (clone $now)->modify('+22 days')->format('Y-m-d H:i:00');
$currentTime = $now->format('Y-m-d H:i:00'); $currentTime = $now->format('Y-m-d H:i:00');
if($type==1){ if($type==1){
$AspZhuan = new AspNetZhuanController(); $AspZhuan = new AspNetZhuanController();
@ -813,10 +814,15 @@ class OrderNewController extends Controller
->where('status', 1) ->where('status', 1)
->where('source', 'LIKE', '%线下体检预约%') ->where('source', 'LIKE', '%线下体检预约%')
->where(function ($query) use ($date3, $currentTime) { ->where(function ($query) use ($date3, $currentTime) {
// 条件组:满足任一即可 // 条件1offline_sendmsg_status 在 [1,2] 且 预约时间 = +6天
$query->whereRaw('TIMESTAMP(appointment_date, appointment_time) = ?', [$date3]) // 精确匹配 +6天 $query->where(function ($q) use ($date3) {
->orWhereRaw('TIMESTAMP(appointment_date, appointment_time) < ?', [$currentTime]); // 小于当前时间 $q->whereIn('offline_sendmsg_status', [1, 2])
})->get(); ->whereRaw('TIMESTAMP(appointment_date, appointment_time) = ?', [$date3]);
})
// 条件2预约时间已过期不管 offline_sendmsg_status 是多少)
->orWhereRaw('TIMESTAMP(appointment_date, appointment_time) < ?', [$currentTime]);
})
->get();
$do = new OrderService(); $do = new OrderService();
foreach ($order_cancels as $order) { foreach ($order_cancels as $order) {
$orderids[]=$order->id; $orderids[]=$order->id;

@ -10,12 +10,12 @@ $bot_loop->count = 1;
$bot_loop->name = 'OfflineOrderCheck'; $bot_loop->name = 'OfflineOrderCheck';
function OfflineOrderCheck($type) function OfflineOrderCheck($type)
{ {
Tool::log('开始执行线下预约订单任务type:'.$type, 2); Tool::log('开始执行线下预约订单任务type:'.$type, 2);
$url = Tool::ini('OFFLINEORDER_CHECK'); $url = Tool::ini('OFFLINEORDER_CHECK');
$res = Tool::post($url ,[ $res = Tool::post($url ,[
'type' => $type 'type' => $type
]); ]);
Tool::log(json_encode($res, JSON_UNESCAPED_UNICODE), 2); Tool::log(json_encode($res, JSON_UNESCAPED_UNICODE), 2);
} }
function OfflineOrderCheckFunc() function OfflineOrderCheckFunc()
@ -23,17 +23,21 @@ function OfflineOrderCheckFunc()
$db = Db::get(); $db = Db::get();
$now = new DateTime(); $now = new DateTime();
// 时间点1当前时间 +1 个月 // 时间点1当前时间 +1 个月
$date1 = (clone $now)->modify('+1 month')->format('Y-m-d H:i:00'); $date1 = (clone $now)->modify('+1 month')->format('Y-m-d H:i:00');
// 时间点2当前时间 +7 天
$date2 = (clone $now)->modify('+7 days')->format('Y-m-d H:i:00'); $date2 = (clone $now)->modify('+23 days')->format('Y-m-d H:i:00');
$date3 = (clone $now)->modify('+6 days')->format('Y-m-d H:i:00');
// 时间点3date1 + 8 天
$date3 = (clone $now)->modify('+22 days')->format('Y-m-d H:i:00');
$currentTime = $now->format('Y-m-d H:i:00'); $currentTime = $now->format('Y-m-d H:i:00');
$order_tongzhi = $db->getRow( $order_tongzhi = $db->getRow(
"SELECT COUNT(1) AS c "SELECT COUNT(1) AS c
FROM orders FROM orders
WHERE status = ? WHERE status = ?
AND TIMESTAMP(appointment_date, appointment_time) IN (?, ?) AND
((TIMESTAMP(appointment_date, appointment_time) IN (?) and offline_sendmsg_status=0) or (TIMESTAMP(appointment_date, appointment_time) IN (?) and offline_sendmsg_status in(0,1)))
AND source LIKE ? AND source LIKE ?
AND offline_sendmsg_status <> 2", AND offline_sendmsg_status <> 2",
[ [
@ -45,33 +49,38 @@ function OfflineOrderCheckFunc()
); );
$order_cancel = $db->getRow( $order_cancel = $db->getRow(
"SELECT COUNT(1) AS c "SELECT COUNT(1) AS c
FROM orders FROM orders
WHERE status = ? WHERE status = ?
AND ( AND source LIKE ?
TIMESTAMP(appointment_date, appointment_time) = ? AND (
OR -- 条件1预约时间 = +6天 且 offline_sendmsg_status 在 (1,2)
TIMESTAMP(appointment_date, appointment_time) < ? (TIMESTAMP(appointment_date, appointment_time) = ?
) AND offline_sendmsg_status IN (1,2))
AND source LIKE ?",
OR
-- 条件2预约时间 < 当前时间(已过期),不关心 offline_sendmsg_status
(TIMESTAMP(appointment_date, appointment_time) < ?)
)",
[ [
1, 1,
'%线下体检预约%',
$date3, // 条件1+6天 $date3, // 条件1+6天
$currentTime, // 条件2小于当前时间 $currentTime // 条件2小于当前时间
'%线下体检预约%'
] ]
); );
if ($order_tongzhi['c'] > 0) { if ($order_tongzhi['c'] > 0) {
OfflineOrderCheck(1); OfflineOrderCheck(1);
} else if ($order_cancel['c'] > 0){ } else if ($order_cancel['c'] > 0){
OfflineOrderCheck(2); OfflineOrderCheck(2);
}else { }else {
Tool::log('未检测到任务'); Tool::log('下线预约订单未检测到任务date1:'.$date1.',date2:'.$date2.',date3:'.$date3.',currentTime:'.$currentTime);
} }
} }
$bot_loop->onWorkerStart = function () { $bot_loop->onWorkerStart = function () {
OfflineOrderCheckFunc(); OfflineOrderCheckFunc();
Timer::add(10, function () { Timer::add(10, function () {
OfflineOrderCheckFunc(); OfflineOrderCheckFunc();
}); });
}; };

Loading…
Cancel
Save