TimerSubscribe.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <?php
  2. namespace crmeb\subscribes;
  3. use app\admin\model\system\SystemAttachment;
  4. use app\api\controller\board\UserBoardController;
  5. use app\models\store\StoreBargainUser;
  6. use app\models\store\StoreOrder;
  7. use app\models\store\StorePink;
  8. use app\models\user\UserToken;
  9. use app\models\redis\SystemCarousel;
  10. use tw\async\activities\ClearanceCalc;
  11. use tw\async\activities\LuckyCalc;
  12. use tw\async\activities\LuckyExtACalc;
  13. use tw\async\activities\LuckyExtBCalc;
  14. use think\facade\Db;
  15. use think\facade\Log;
  16. use app\admin\model\system\SystemLog;
  17. /**
  18. * 定时任务类
  19. * Class TaskSubscribe
  20. * @package crmeb\subscribes
  21. */
  22. class TimerSubscribe
  23. {
  24. public function handle()
  25. {
  26. }
  27. /**
  28. * 2秒钟执行的方法
  29. */
  30. public function onTimer_2()
  31. {
  32. }
  33. /**
  34. * 6秒钟执行的方法
  35. */
  36. public function onTimer_6()
  37. {
  38. }
  39. /**
  40. * 10秒钟执行的方法
  41. */
  42. public function onTimer_10()
  43. {
  44. }
  45. /**
  46. * 30秒钟执行的方法
  47. */
  48. public function onTimer_30()
  49. {
  50. try {
  51. Db::startTrans();
  52. StoreBargainUser::startBargainUserStatus();//批量修改砍价状态为 砍价失败
  53. Db::commit();
  54. } catch (\Exception $e) {
  55. Db::rollback();
  56. }
  57. try {
  58. Db::startTrans();
  59. StoreOrder::orderUnpaidCancel();//订单未支付默认取消
  60. Db::commit();
  61. } catch (\Exception $e) {
  62. Db::rollback();
  63. }
  64. try {
  65. Db::startTrans();
  66. StoreOrder::startTakeOrder();//7天自动收货
  67. Db::commit();
  68. } catch (\Exception $e) {
  69. Db::rollback();
  70. }
  71. try {
  72. Db::startTrans();
  73. StorePink::statusPink();//拼团到期修改状态
  74. Db::commit();
  75. } catch (\Exception $e) {
  76. Db::rollback();
  77. }
  78. }
  79. /**
  80. * 60秒钟执行的方法
  81. */
  82. public function onTimer_60()
  83. {
  84. $tm = localtime(time(), true);
  85. // 缓存排行榜
  86. if (intval($tm['tm_min']) % 5 == 0) {
  87. $ctl = new UserBoardController();
  88. $ctl->cache_board();
  89. // TODO: for testing, remove line below
  90. // SystemCarousel::add('who will win next race?', '/pages/leader_board/index');
  91. }
  92. if (intval($tm['tm_min']) == 0) {
  93. // 整点做活动
  94. $activities = [new ClearanceCalc(), new LuckyCalc(), new LuckyExtACalc(), new LuckyExtBCalc()];
  95. foreach($activities as $activity) {
  96. $activity->calc();
  97. }
  98. // 刪除跑馬燈
  99. SystemCarousel::removeTrash();
  100. Log::warning('onTimer_60() activities calculated.');
  101. // 每日 24
  102. if (intval($tm['tm_hour']) == 0) {
  103. SystemLog::deleteLog();
  104. Log::warning('onTimer_60() remove outdated admin logs');
  105. }
  106. }
  107. }
  108. /**
  109. * 180秒钟执行的方法
  110. */
  111. public function onTimer_180()
  112. {
  113. }
  114. /**
  115. * 300秒钟执行的方法
  116. */
  117. public function onTimer_300()
  118. {
  119. UserToken::delToken();//删除一天前的过期token
  120. SystemAttachment::emptyYesterdayAttachment();//清除昨日海报
  121. StoreOrder::sendTen();//10分钟未付款发送通知
  122. }
  123. }