TimerSubscribe.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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 crmeb\services\async\ClearanceCalc;
  10. use crmeb\services\async\LuckyCalc;
  11. use think\facade\Db;
  12. use think\facade\Log;
  13. use crmeb\services\async\WechatNotify;
  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. WechatNotify::notify();
  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 ($tm['tm_min'] % 5 == 0) {
  86. $ctl = new UserBoardController();
  87. $ctl->cache_board();
  88. Log::warning("board updated.");
  89. }
  90. if ($tm['tm_min'] == 0) {
  91. // 整点做活动
  92. $activities = [new ClearanceCalc(), new LuckyCalc()];
  93. foreach($activities as $activity) {
  94. $activity->calc();
  95. }
  96. Log::warning('onTimer_60() activities calculated.');
  97. // 每日 24
  98. if ($tm['tm_hour'] == 0) {
  99. SystemLog::deleteLog();
  100. Log::warning('onTimer_60() remove outdated admin logs');
  101. }
  102. }
  103. }
  104. /**
  105. * 180秒钟执行的方法
  106. */
  107. public function onTimer_180()
  108. {
  109. }
  110. /**
  111. * 300秒钟执行的方法
  112. */
  113. public function onTimer_300()
  114. {
  115. UserToken::delToken();//删除一天前的过期token
  116. SystemAttachment::emptyYesterdayAttachment();//清除昨日海报
  117. StoreOrder::sendTen();//10分钟未付款发送通知
  118. }
  119. }