p_ysk/app/process/MessagePushTask.php

82 lines
3.5 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace app\process;
use support\Log;
use support\Redis;
use support\think\Db;
use Workerman\Crontab\Crontab;
// 消息推送
class MessagePushTask
{
public function onWorkerStart()
{
// 查询短信发送状态
new Crontab('0 */5 * * * *', function(){
$command = 'cd ' . BASE_PATH . ' && php webman querysmsstatus';
// 存储命令输出的数组
$output = [];
// 存储命令返回状态码0为成功非0为失败
$status = 0;
// 执行命令
exec($command, $output, $status);
// 处理执行结果
Log::info('查询短信发送状态:执行状态'. $status . '/执行结果:' . json_encode($output, JSON_UNESCAPED_UNICODE));
});
// 查询模版审核状态
new Crontab('0 */5 * * * *', function(){
$command = 'cd ' . BASE_PATH . ' && php webman querysmstempstatus';
// 存储命令输出的数组
$output = [];
// 存储命令返回状态码0为成功非0为失败
$status = 0;
// 执行命令
exec($command, $output, $status);
// 处理执行结果
Log::info('查询模版审核状态:执行状态'. $status . '/执行结果:' . json_encode($output, JSON_UNESCAPED_UNICODE));
});
// 按天插入过期时间 每天23点30执行
new Crontab('30 23 * * *', function(){
Log::info('开始插入过期时间');
// 查询只有明天到期的任务
$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();
Log::info('开始插入过期时间-》营销短信查询结果' . json_encode($record));
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();
Log::info('开始插入过期时间-》微信模版查询结果' . json_encode($record));
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);
}
}
});
}
}