From dbb9a3dfe1c1b591f810f0bf5b5059324fab9562 Mon Sep 17 00:00:00 2001 From: ASUS <515617283@qq.com> Date: Thu, 23 Oct 2025 14:54:24 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8C=89=E5=A4=A9=E6=8F=92=E5=85=A5=E8=BF=87?= =?UTF-8?q?=E6=9C=9F=E6=97=B6=E9=97=B4=20=E6=AF=8F=E5=A4=A923=E7=82=B930?= =?UTF-8?q?=E6=89=A7=E8=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/process/MessagePushTask.php | 42 ++++++++++++++++++++++++++++++ app/queue/redis/SendMarkSms.php | 2 +- app/queue/redis/SendWechatTemp.php | 2 +- config/process.php | 2 +- 4 files changed, 45 insertions(+), 3 deletions(-) diff --git a/app/process/MessagePushTask.php b/app/process/MessagePushTask.php index 52d15f4..9f9e48b 100644 --- a/app/process/MessagePushTask.php +++ b/app/process/MessagePushTask.php @@ -2,6 +2,8 @@ namespace app\process; use support\Log; +use support\Redis; +use support\think\Db; use Workerman\Crontab\Crontab; // 消息推送 @@ -33,5 +35,45 @@ class MessagePushTask // 处理执行结果 Log::info('查询模版审核状态:执行状态'. $status . '/执行结果:' . json_encode($output, JSON_UNESCAPED_UNICODE)); }); + + + // 按天插入过期时间 每天23点30执行 + new Crontab('30 23 * * *', function(){ + // 查询只有明天到期的任务 + $next_day = date('Y-m-d 00:00:00', strtotime('+1 day')); + $next_end_day = date('Y-m-d 23:59:59', strtotime('+1 day')); + + // 先处理营销短信的 只有明天到期的 + $record = Db::table('sms_push_event') + ->where(['status' => 0, 'send_type' => 2, 'is_del' => 0]) + ->where('send_time', '>=', $next_day) + ->where('send_time', '<=', $next_end_day) + ->select()->toArray(); + if($record) { + foreach ($record as $key => $value) { + $stortime = strtotime($value['send_time']); + $res = Redis::setEx('expired:sms:'.$value['id'], $stortime - time(), 1); + Log::info('定时任务/营销短信--定时发送,已存入redis, ID-->' .$value['id'] . '/过期时间->>>' . $value['send_time'] . '/' . $stortime - time() . '保存结果' . $res); + } + } + + // 微信模版 只有明天到期的 + $record = Db::table('ac_push_event') + ->where(['status' => 0, 'is_del' => 0, 'send_type' => 2]) + ->where('send_time', '>=', $next_day) + ->where('send_time', '<=', $next_end_day) + ->select()->toArray(); + if($record) { + foreach ($record as $key => $value) { + $stortime = strtotime($value['send_time']); + $res = Redis::setEx('expired:wechat:'.$value['id'], $stortime - time(), 1); + Log::info('定时任务/发送微信模版消息--定时发送,已存入redis, ID-->' .$value['id'] . '/过期时间->>>' . $value['send_time'] . '/' . $stortime - time() . '保存结果' . $res); + } + } + }); + + + + } } \ No newline at end of file diff --git a/app/queue/redis/SendMarkSms.php b/app/queue/redis/SendMarkSms.php index 94ad255..f69ea49 100644 --- a/app/queue/redis/SendMarkSms.php +++ b/app/queue/redis/SendMarkSms.php @@ -43,7 +43,7 @@ class SendMarkSms implements Consumer $record = Db::table('sms_push_event')->where(['id' => $sms_push_event_id, 'status' => 0])->find(); if($record) { // 查询是否是定时发送 - if($record['send_type'] == 2 && $record['send_time'] > date('Y-m-d H:i:s')) { + if($record['send_type'] == 2 && $record['send_time'] > date('Y-m-d H:i:s') && $record['send_time'] <= date('Y-m-d 23:59:59')) { // 推给redis $stortime = strtotime($record['send_time']); $a = Redis::setEx('expired:sms:'.$record['id'], $stortime - time(), 1); diff --git a/app/queue/redis/SendWechatTemp.php b/app/queue/redis/SendWechatTemp.php index a9f8fb7..dcd6f51 100644 --- a/app/queue/redis/SendWechatTemp.php +++ b/app/queue/redis/SendWechatTemp.php @@ -37,7 +37,7 @@ class SendWechatTemp implements Consumer $record = Db::table('ac_push_event')->where(['id' => $sms_push_event_id, 'status' => 0, 'is_del' => 0])->find(); if($record) { // 查询是否是定时发送 - if($record['send_type'] == 2 && $record['send_time'] > date('Y-m-d H:i:s')) { + if($record['send_type'] == 2 && $record['send_time'] > date('Y-m-d H:i:s') && $record['send_time'] <= date('Y-m-d 23:59:59')) { // 推给redis $stortime = strtotime($record['send_time']); $a = Redis::setEx('expired:wechat:'.$record['id'], $stortime - time(), 1); diff --git a/config/process.php b/config/process.php index b885ab6..59a642c 100644 --- a/config/process.php +++ b/config/process.php @@ -65,7 +65,7 @@ return [ 'ExpiredRedis' => [ 'handler' => \app\process\ExpiredRedis::class, ], - // 定时任务/查询短信发送状态/查询模版审核状态 + // 定时任务/查询短信发送状态/查询模版审核状态/按天插入过期时间 'QuerySmsStatus' => [ 'handler' => MessagePushTask::class ]