CrontabRunServices.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. <?php
  2. namespace app\services\system\crontab;
  3. use app\services\activity\combination\StorePinkServices;
  4. use app\services\activity\live\LiveGoodsServices;
  5. use app\services\activity\live\LiveRoomServices;
  6. use app\services\agent\AgentManageServices;
  7. use app\services\BaseServices;
  8. use app\services\order\StoreOrderServices;
  9. use app\services\order\StoreOrderTakeServices;
  10. use app\services\product\product\StoreProductServices;
  11. use app\services\system\attachment\SystemAttachmentServices;
  12. use think\facade\Log;
  13. /**
  14. * 执行定时任务
  15. * @author 吴汐
  16. * @email 442384644@qq.com
  17. * @date 2023/03/01
  18. */
  19. class CrontabRunServices extends BaseServices
  20. {
  21. /**
  22. * 调用不存在的方法
  23. * @param $name
  24. * @param $arguments
  25. * @return mixed|void
  26. * @author 吴汐
  27. * @email 442384644@qq.com
  28. * @date 2023/03/01
  29. */
  30. public function __call($name, $arguments)
  31. {
  32. $this->crontabLog($name . '方法不存在');
  33. }
  34. /**
  35. * 定时任务日志
  36. * @param $msg
  37. */
  38. public function crontabLog($msg)
  39. {
  40. $timer_log_open = config("log.timer_log", false);
  41. if ($timer_log_open) {
  42. $date = date('Y-m-d H:i:s', time());
  43. Log::write($date . $msg, 'crontab');
  44. }
  45. }
  46. /**
  47. * 未支付自动取消订单
  48. * @author 吴汐
  49. * @email 442384644@qq.com
  50. * @date 2023/03/01
  51. */
  52. public function orderCancel()
  53. {
  54. try {
  55. app()->make(StoreOrderServices::class)->orderUnpaidCancel();
  56. $this->crontabLog(' 执行未支付自动取消订单');
  57. } catch (\Throwable $e) {
  58. $this->crontabLog('自动取消订单失败,失败原因:' . $e->getMessage());
  59. }
  60. }
  61. /**
  62. * 拼团到期订单处理
  63. * @author 吴汐
  64. * @email 442384644@qq.com
  65. * @date 2023/03/01
  66. */
  67. public function pinkExpiration()
  68. {
  69. try {
  70. app()->make(StorePinkServices::class)->statusPink();
  71. $this->crontabLog(' 执行拼团到期订单处理');
  72. } catch (\Throwable $e) {
  73. $this->crontabLog('拼团到期订单处理失败,失败原因:' . $e->getMessage());
  74. }
  75. }
  76. /**
  77. * 自动解除上级绑定
  78. * @author 吴汐
  79. * @email 442384644@qq.com
  80. * @date 2023/03/01
  81. */
  82. public function agentUnbind()
  83. {
  84. try {
  85. app()->make(AgentManageServices::class)->removeSpread();
  86. $this->crontabLog(' 执行自动解绑上级绑定');
  87. } catch (\Throwable $e) {
  88. $this->crontabLog('自动解除上级绑定失败,失败原因:' . $e->getMessage());
  89. }
  90. }
  91. /**
  92. * 更新直播商品状态
  93. * @author 吴汐
  94. * @email 442384644@qq.com
  95. * @date 2023/03/01
  96. */
  97. public function liveProductStatus()
  98. {
  99. try {
  100. app()->make(LiveGoodsServices::class)->syncGoodStatus();
  101. $this->crontabLog(' 执行更新直播商品状态');
  102. } catch (\Throwable $e) {
  103. $this->crontabLog('更新直播商品状态失败,失败原因:' . $e->getMessage());
  104. }
  105. }
  106. /**
  107. * 更新直播间状态
  108. * @author 吴汐
  109. * @email 442384644@qq.com
  110. * @date 2023/03/01
  111. */
  112. public function liveRoomStatus()
  113. {
  114. try {
  115. app()->make(LiveRoomServices::class)->syncRoomStatus();
  116. $this->crontabLog(' 执行更新直播间状态');
  117. } catch (\Throwable $e) {
  118. $this->crontabLog('更新直播间状态失败,失败原因:' . $e->getMessage());
  119. }
  120. }
  121. /**
  122. * 自动收货
  123. * @author 吴汐
  124. * @email 442384644@qq.com
  125. * @date 2023/03/01
  126. */
  127. public function takeDelivery()
  128. {
  129. try {
  130. app()->make(StoreOrderTakeServices::class)->autoTakeOrder();
  131. $this->crontabLog(' 执行自动收货');
  132. } catch (\Throwable $e) {
  133. $this->crontabLog('自动收货失败,失败原因:' . $e->getMessage());
  134. }
  135. }
  136. /**
  137. * 预售到期商品自动下架
  138. * @author 吴汐
  139. * @email 442384644@qq.com
  140. * @date 2023/03/01
  141. */
  142. public function advanceOff()
  143. {
  144. try {
  145. app()->make(StoreProductServices::class)->downAdvance();
  146. $this->crontabLog(' 执行预售到期商品自动下架');
  147. } catch (\Throwable $e) {
  148. $this->crontabLog('预售到期商品自动下架失败,失败原因:' . $e->getMessage());
  149. }
  150. }
  151. /**
  152. * 自动好评
  153. * @author 吴汐
  154. * @email 442384644@qq.com
  155. * @date 2023/03/01
  156. */
  157. public function productReplay()
  158. {
  159. try {
  160. app()->make(StoreOrderServices::class)->autoComment();
  161. $this->crontabLog(' 执行自动好评');
  162. } catch (\Throwable $e) {
  163. $this->crontabLog('自动好评失败,失败原因:' . $e->getMessage());
  164. }
  165. }
  166. /**
  167. * 清除昨日海报
  168. * @author 吴汐
  169. * @email 442384644@qq.com
  170. * @date 2023/03/01
  171. */
  172. public function clearPoster()
  173. {
  174. try {
  175. app()->make(SystemAttachmentServices::class)->emptyYesterdayAttachment();
  176. $this->crontabLog(' 执行清除昨日海报');
  177. } catch (\Throwable $e) {
  178. $this->crontabLog('清除昨日海报失败,失败原因:' . $e->getMessage());
  179. }
  180. }
  181. }