TimerSubscribe.php 3.2 KB

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