| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 |
- <?php
- namespace crmeb\subscribes;
- use app\admin\model\system\SystemAttachment;
- use app\api\controller\board\UserBoardController;
- use app\models\store\StoreBargainUser;
- use app\models\store\StoreOrder;
- use app\models\store\StorePink;
- use app\models\user\UserToken;
- use crmeb\services\async\ClearanceCalc;
- use crmeb\services\async\LuckyCalc;
- use think\facade\Db;
- use think\facade\Log;
- use crmeb\services\async\WechatNotify;
- use app\admin\model\system\SystemLog;
- /**
- * 定时任务类
- * Class TaskSubscribe
- * @package crmeb\subscribes
- */
- class TimerSubscribe
- {
- public function handle()
- {
- }
- /**
- * 2秒钟执行的方法
- */
- public function onTimer_2()
- {
- }
- /**
- * 6秒钟执行的方法
- */
- public function onTimer_6()
- {
- }
- /**
- * 10秒钟执行的方法
- */
- public function onTimer_10()
- {
- WechatNotify::notify();
- }
- /**
- * 30秒钟执行的方法
- */
- public function onTimer_30()
- {
- try {
- Db::startTrans();
- StoreBargainUser::startBargainUserStatus();//批量修改砍价状态为 砍价失败
- Db::commit();
- } catch (\Exception $e) {
- Db::rollback();
- }
- try {
- Db::startTrans();
- StoreOrder::orderUnpaidCancel();//订单未支付默认取消
- Db::commit();
- } catch (\Exception $e) {
- Db::rollback();
- }
- try {
- Db::startTrans();
- StoreOrder::startTakeOrder();//7天自动收货
- Db::commit();
- } catch (\Exception $e) {
- Db::rollback();
- }
- try {
- Db::startTrans();
- StorePink::statusPink();//拼团到期修改状态
- Db::commit();
- } catch (\Exception $e) {
- Db::rollback();
- }
- }
- /**
- * 60秒钟执行的方法
- */
- public function onTimer_60()
- {
- $tm = localtime(time(), true);
- // 缓存排行榜
- Log::warning("onTimer_60()" . $tm['tm_hour'] . ':' . $tm['tm_min']);
- if (intval($tm['tm_min']) % 5 == 0) {
- Log::warning("board updated.");
- $ctl = new UserBoardController();
- $ctl->cache_board();
- }
- if (intval($tm['tm_min']) == 0) {
- // 整点做活动
- $activities = [new ClearanceCalc(), new LuckyCalc()];
- foreach($activities as $activity) {
- $activity->calc();
- }
- Log::warning('onTimer_60() activities calculated.');
- // 每日 24
- if (intval($tm['tm_hour']) == 0) {
- SystemLog::deleteLog();
- Log::warning('onTimer_60() remove outdated admin logs');
- }
- }
- }
- /**
- * 180秒钟执行的方法
- */
- public function onTimer_180()
- {
- }
- /**
- * 300秒钟执行的方法
- */
- public function onTimer_300()
- {
- UserToken::delToken();//删除一天前的过期token
- SystemAttachment::emptyYesterdayAttachment();//清除昨日海报
- StoreOrder::sendTen();//10分钟未付款发送通知
- }
- }
|