diff --git a/Laravel/app/Http/Controllers/API/H5/OrderNewController.php b/Laravel/app/Http/Controllers/API/H5/OrderNewController.php index c993075..a40e2bb 100644 --- a/Laravel/app/Http/Controllers/API/H5/OrderNewController.php +++ b/Laravel/app/Http/Controllers/API/H5/OrderNewController.php @@ -758,12 +758,13 @@ class OrderNewController extends Controller $type = request('type');//1通知2取消 $now = new DateTime(); -// 时间点1:当前时间 +1 个月 + $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'); -// 时间点3:当前时间 +6 天(你定义了 $date3,但没用上,这里也加上可选) - $date3 = (clone $now)->modify('+6 days')->format('Y-m-d H:i:00'); + + $date2 = (clone $now)->modify('+23 days')->format('Y-m-d H:i:00'); + +// 时间点3:date1 + 8 天 + $date3 = (clone $now)->modify('+22 days')->format('Y-m-d H:i:00'); $currentTime = $now->format('Y-m-d H:i:00'); if($type==1){ $AspZhuan = new AspNetZhuanController(); @@ -813,10 +814,15 @@ class OrderNewController extends Controller ->where('status', 1) ->where('source', 'LIKE', '%线下体检预约%') ->where(function ($query) use ($date3, $currentTime) { - // 条件组:满足任一即可 - $query->whereRaw('TIMESTAMP(appointment_date, appointment_time) = ?', [$date3]) // 精确匹配 +6天 - ->orWhereRaw('TIMESTAMP(appointment_date, appointment_time) < ?', [$currentTime]); // 小于当前时间 - })->get(); + // 条件1:offline_sendmsg_status 在 [1,2] 且 预约时间 = +6天 + $query->where(function ($q) use ($date3) { + $q->whereIn('offline_sendmsg_status', [1, 2]) + ->whereRaw('TIMESTAMP(appointment_date, appointment_time) = ?', [$date3]); + }) + // 条件2:预约时间已过期(不管 offline_sendmsg_status 是多少) + ->orWhereRaw('TIMESTAMP(appointment_date, appointment_time) < ?', [$currentTime]); + }) + ->get(); $do = new OrderService(); foreach ($order_cancels as $order) { $orderids[]=$order->id; diff --git a/bot/bot/bot_offlineOrderCheck.php b/bot/bot/bot_offlineOrderCheck.php index 16a1978..ec910ac 100644 --- a/bot/bot/bot_offlineOrderCheck.php +++ b/bot/bot/bot_offlineOrderCheck.php @@ -10,12 +10,12 @@ $bot_loop->count = 1; $bot_loop->name = 'OfflineOrderCheck'; function OfflineOrderCheck($type) { - Tool::log('开始执行线下预约订单任务type:'.$type, 2); - $url = Tool::ini('OFFLINEORDER_CHECK'); - $res = Tool::post($url ,[ - 'type' => $type - ]); - Tool::log(json_encode($res, JSON_UNESCAPED_UNICODE), 2); + Tool::log('开始执行线下预约订单任务type:'.$type, 2); + $url = Tool::ini('OFFLINEORDER_CHECK'); + $res = Tool::post($url ,[ + 'type' => $type + ]); + Tool::log(json_encode($res, JSON_UNESCAPED_UNICODE), 2); } function OfflineOrderCheckFunc() @@ -23,17 +23,21 @@ function OfflineOrderCheckFunc() $db = Db::get(); $now = new DateTime(); + // 时间点1:当前时间 +1 个月 $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'); - $date3 = (clone $now)->modify('+6 days')->format('Y-m-d H:i:00'); + + $date2 = (clone $now)->modify('+23 days')->format('Y-m-d H:i:00'); + +// 时间点3:date1 + 8 天 + $date3 = (clone $now)->modify('+22 days')->format('Y-m-d H:i:00'); $currentTime = $now->format('Y-m-d H:i:00'); $order_tongzhi = $db->getRow( "SELECT COUNT(1) AS c FROM orders 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 offline_sendmsg_status <> 2", [ @@ -45,33 +49,38 @@ function OfflineOrderCheckFunc() ); $order_cancel = $db->getRow( "SELECT COUNT(1) AS c - FROM orders - WHERE status = ? - AND ( - TIMESTAMP(appointment_date, appointment_time) = ? - OR - TIMESTAMP(appointment_date, appointment_time) < ? - ) - AND source LIKE ?", +FROM orders +WHERE status = ? + AND source LIKE ? + AND ( + -- 条件1:预约时间 = +6天 且 offline_sendmsg_status 在 (1,2) + (TIMESTAMP(appointment_date, appointment_time) = ? + AND offline_sendmsg_status IN (1,2)) + + OR + + -- 条件2:预约时间 < 当前时间(已过期),不关心 offline_sendmsg_status + (TIMESTAMP(appointment_date, appointment_time) < ?) + )", [ 1, + '%线下体检预约%', $date3, // 条件1:+6天 - $currentTime, // 条件2:小于当前时间 - '%线下体检预约%' + $currentTime // 条件2:小于当前时间 ] ); - if ($order_tongzhi['c'] > 0) { - OfflineOrderCheck(1); - } else if ($order_cancel['c'] > 0){ - OfflineOrderCheck(2); - }else { - Tool::log('未检测到任务'); - } + if ($order_tongzhi['c'] > 0) { + OfflineOrderCheck(1); + } else if ($order_cancel['c'] > 0){ + OfflineOrderCheck(2); + }else { + Tool::log('下线预约订单未检测到任务,date1:'.$date1.',date2:'.$date2.',date3:'.$date3.',currentTime:'.$currentTime); + } } $bot_loop->onWorkerStart = function () { OfflineOrderCheckFunc(); - Timer::add(10, function () { - OfflineOrderCheckFunc(); - }); + Timer::add(10, function () { + OfflineOrderCheckFunc(); + }); };