TimerSubscribe.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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 crmeb\services\async\ClearanceCalc;
  11. use crmeb\services\async\LuckyCalc;
  12. use think\facade\Db;
  13. use think\facade\Log;
  14. use crmeb\services\async\WechatNotify;
  15. use app\admin\model\system\SystemLog;
  16. /**
  17. * 定时任务类
  18. * Class TaskSubscribe
  19. * @package crmeb\subscribes
  20. */
  21. class TimerSubscribe
  22. {
  23. public function handle()
  24. {
  25. }
  26. /**
  27. * 2秒钟执行的方法
  28. */
  29. public function onTimer_2()
  30. {
  31. }
  32. /**
  33. * 6秒钟执行的方法
  34. */
  35. public function onTimer_6()
  36. {
  37. }
  38. /**
  39. * 10秒钟执行的方法
  40. */
  41. public function onTimer_10()
  42. {
  43. WechatNotify::notify();
  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. Log::warning("onTimer_60()" . $tm['tm_hour'] . ':' . $tm['tm_min']);
  87. if (intval($tm['tm_min']) % 5 == 0) {
  88. Log::warning("board updated.");
  89. $ctl = new UserBoardController();
  90. $ctl->cache_board();
  91. // TODO: for testing, remove line below
  92. SystemCarousel::add('who will win next race?', '/pages/leader_board/index');
  93. }
  94. if (intval($tm['tm_min']) == 0) {
  95. // 整点做活动
  96. $activities = [new ClearanceCalc(), new LuckyCalc()];
  97. foreach($activities as $activity) {
  98. $activity->calc();
  99. }
  100. SystemCarousel::removeTrash();
  101. Log::warning('onTimer_60() activities calculated.');
  102. // 每日 24
  103. if (intval($tm['tm_hour']) == 0) {
  104. SystemLog::deleteLog();
  105. Log::warning('onTimer_60() remove outdated admin logs');
  106. }
  107. }
  108. }
  109. /**
  110. * 180秒钟执行的方法
  111. */
  112. public function onTimer_180()
  113. {
  114. }
  115. /**
  116. * 300秒钟执行的方法
  117. */
  118. public function onTimer_300()
  119. {
  120. UserToken::delToken();//删除一天前的过期token
  121. SystemAttachment::emptyYesterdayAttachment();//清除昨日海报
  122. StoreOrder::sendTen();//10分钟未付款发送通知
  123. }
  124. }