按天插入过期时间 每天23点30执行

This commit is contained in:
ASUS 2025-10-23 14:54:24 +08:00
parent e370b69d37
commit dbb9a3dfe1
4 changed files with 45 additions and 3 deletions

View File

@ -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);
}
}
});
}
}

View File

@ -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);

View File

@ -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);

View File

@ -65,7 +65,7 @@ return [
'ExpiredRedis' => [
'handler' => \app\process\ExpiredRedis::class,
],
// 定时任务/查询短信发送状态/查询模版审核状态
// 定时任务/查询短信发送状态/查询模版审核状态/按天插入过期时间
'QuerySmsStatus' => [
'handler' => MessagePushTask::class
]