TimerSubscribe.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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 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. }
  44. /**
  45. * 30秒钟执行的方法
  46. */
  47. public function onTimer_30()
  48. {
  49. try {
  50. Db::startTrans();
  51. StoreBargainUser::startBargainUserStatus();//批量修改砍价状态为 砍价失败
  52. Db::commit();
  53. } catch (\Exception $e) {
  54. Db::rollback();
  55. }
  56. try {
  57. Db::startTrans();
  58. StoreOrder::orderUnpaidCancel();//订单未支付默认取消
  59. Db::commit();
  60. } catch (\Exception $e) {
  61. Db::rollback();
  62. }
  63. try {
  64. Db::startTrans();
  65. StoreOrder::startTakeOrder();//7天自动收货
  66. Db::commit();
  67. } catch (\Exception $e) {
  68. Db::rollback();
  69. }
  70. try {
  71. Db::startTrans();
  72. StorePink::statusPink();//拼团到期修改状态
  73. Db::commit();
  74. } catch (\Exception $e) {
  75. Db::rollback();
  76. }
  77. }
  78. /**
  79. * 60秒钟执行的方法
  80. */
  81. public function onTimer_60()
  82. {
  83. $tm = localtime(time(), true);
  84. // 缓存排行榜
  85. if (intval($tm['tm_min']) % 5 == 0) {
  86. $ctl = new UserBoardController();
  87. $ctl->cache_board();
  88. // TODO: for testing, remove line below
  89. // SystemCarousel::add('who will win next race?', '/pages/leader_board/index');
  90. }
  91. if (intval($tm['tm_min']) == 0) {
  92. // 整点做活动
  93. $activities = [new ClearanceCalc(), new LuckyCalc(), new LuckyExtACalc(), new LuckyExtBCalc()];
  94. foreach($activities as $activity) {
  95. $activity->calc();
  96. }
  97. // 刪除跑馬燈
  98. SystemCarousel::removeTrash();
  99. warnlog('onTimer_60() activities calculated.');
  100. // 每日 24
  101. if (intval($tm['tm_hour']) == 0) {
  102. SystemLog::deleteLog();
  103. warnlog('onTimer_60() remove outdated admin logs');
  104. }
  105. }
  106. }
  107. /**
  108. * 180秒钟执行的方法
  109. */
  110. public function onTimer_180()
  111. {
  112. }
  113. /**
  114. * 300秒钟执行的方法
  115. */
  116. public function onTimer_300()
  117. {
  118. UserToken::delToken();//删除一天前的过期token
  119. SystemAttachment::emptyYesterdayAttachment();//清除昨日海报
  120. StoreOrder::sendTen();//10分钟未付款发送通知
  121. }
  122. }