CrontabRunServices.php 5.9 KB

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