CrontabRunServices.php 6.4 KB

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