CrontabRunServices.php 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  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\StoreOrderInvoiceServices;
  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. 'autoInvoice' => '自动开具发票以及退款自动冲红',
  36. 'customTimer' => '自定义定时任务',
  37. ];
  38. /**
  39. * 调用不存在的方法
  40. * @param $name
  41. * @param $arguments
  42. * @return mixed|void
  43. * @author 吴汐
  44. * @email 442384644@qq.com
  45. * @date 2023/03/01
  46. */
  47. public function __call($name, $arguments)
  48. {
  49. $this->crontabLog($name . '方法不存在');
  50. }
  51. /**
  52. * 定时任务日志
  53. * @param $msg
  54. */
  55. protected function crontabLog($msg)
  56. {
  57. $timer_log_open = config("log.timer_log", false);
  58. if ($timer_log_open) {
  59. $date = date('Y-m-d H:i:s', time());
  60. Log::write($date . $msg, 'crontab');
  61. }
  62. }
  63. /**
  64. * 未支付自动取消订单
  65. * @author 吴汐
  66. * @email 442384644@qq.com
  67. * @date 2023/03/01
  68. */
  69. public function orderCancel()
  70. {
  71. try {
  72. app()->make(StoreOrderServices::class)->orderUnpaidCancel();
  73. $this->crontabLog(' 执行未支付自动取消订单');
  74. } catch (\Throwable $e) {
  75. $this->crontabLog('自动取消订单失败,失败原因:' . $e->getMessage());
  76. }
  77. }
  78. /**
  79. * 拼团到期订单处理
  80. * @author 吴汐
  81. * @email 442384644@qq.com
  82. * @date 2023/03/01
  83. */
  84. public function pinkExpiration()
  85. {
  86. try {
  87. app()->make(StorePinkServices::class)->statusPink();
  88. $this->crontabLog(' 执行拼团到期订单处理');
  89. } catch (\Throwable $e) {
  90. $this->crontabLog('拼团到期订单处理失败,失败原因:' . $e->getMessage());
  91. }
  92. }
  93. /**
  94. * 自动解除上级绑定
  95. * @author 吴汐
  96. * @email 442384644@qq.com
  97. * @date 2023/03/01
  98. */
  99. public function agentUnbind()
  100. {
  101. try {
  102. app()->make(AgentManageServices::class)->removeSpread();
  103. $this->crontabLog(' 执行自动解绑上级绑定');
  104. } catch (\Throwable $e) {
  105. $this->crontabLog('自动解除上级绑定失败,失败原因:' . $e->getMessage());
  106. }
  107. }
  108. /**
  109. * 更新直播商品状态
  110. * @author 吴汐
  111. * @email 442384644@qq.com
  112. * @date 2023/03/01
  113. */
  114. public function liveProductStatus()
  115. {
  116. try {
  117. app()->make(LiveGoodsServices::class)->syncGoodStatus();
  118. $this->crontabLog(' 执行更新直播商品状态');
  119. } catch (\Throwable $e) {
  120. $this->crontabLog('更新直播商品状态失败,失败原因:' . $e->getMessage());
  121. }
  122. }
  123. /**
  124. * 更新直播间状态
  125. * @author 吴汐
  126. * @email 442384644@qq.com
  127. * @date 2023/03/01
  128. */
  129. public function liveRoomStatus()
  130. {
  131. try {
  132. app()->make(LiveRoomServices::class)->syncRoomStatus();
  133. $this->crontabLog(' 执行更新直播间状态');
  134. } catch (\Throwable $e) {
  135. $this->crontabLog('更新直播间状态失败,失败原因:' . $e->getMessage());
  136. }
  137. }
  138. /**
  139. * 自动收货
  140. * @author 吴汐
  141. * @email 442384644@qq.com
  142. * @date 2023/03/01
  143. */
  144. public function takeDelivery()
  145. {
  146. try {
  147. app()->make(StoreOrderTakeServices::class)->autoTakeOrder();
  148. $this->crontabLog(' 执行自动收货');
  149. } catch (\Throwable $e) {
  150. $this->crontabLog('自动收货失败,失败原因:' . $e->getMessage());
  151. }
  152. }
  153. /**
  154. * 预售到期商品自动下架
  155. * @author 吴汐
  156. * @email 442384644@qq.com
  157. * @date 2023/03/01
  158. */
  159. public function advanceOff()
  160. {
  161. try {
  162. app()->make(StoreProductServices::class)->downAdvance();
  163. $this->crontabLog(' 执行预售到期商品自动下架');
  164. } catch (\Throwable $e) {
  165. $this->crontabLog('预售到期商品自动下架失败,失败原因:' . $e->getMessage());
  166. }
  167. }
  168. /**
  169. * 自动好评
  170. * @author 吴汐
  171. * @email 442384644@qq.com
  172. * @date 2023/03/01
  173. */
  174. public function productReplay()
  175. {
  176. try {
  177. app()->make(StoreOrderServices::class)->autoComment();
  178. $this->crontabLog(' 执行自动好评');
  179. } catch (\Throwable $e) {
  180. $this->crontabLog('自动好评失败,失败原因:' . $e->getMessage());
  181. }
  182. }
  183. /**
  184. * 清除昨日海报
  185. * @author 吴汐
  186. * @email 442384644@qq.com
  187. * @date 2023/03/01
  188. */
  189. public function clearPoster()
  190. {
  191. try {
  192. app()->make(SystemAttachmentServices::class)->emptyYesterdayAttachment();
  193. $this->crontabLog(' 执行清除昨日海报');
  194. } catch (\Throwable $e) {
  195. $this->crontabLog('清除昨日海报失败,失败原因:' . $e->getMessage());
  196. }
  197. }
  198. /**
  199. * 执行自动开具/冲红电子发票
  200. * @author 吴汐
  201. * @email 442384644@qq.com
  202. * @date 2023/03/01
  203. */
  204. public function autoInvoice()
  205. {
  206. try {
  207. $invoiceServices = app()->make(StoreOrderInvoiceServices::class);
  208. $invoiceServices->autoInvoice();
  209. $invoiceServices->autoInvoiceRed();
  210. $this->crontabLog(' 执行自动开具/冲红电子发票');
  211. } catch (\Throwable $e) {
  212. $this->crontabLog('自动开具/冲红电子发票失败,失败原因:' . $e->getMessage());
  213. }
  214. }
  215. /**
  216. * 自定义定时器
  217. * @param string $customCode
  218. * @author wuhaotian
  219. * @email 442384644@qq.com
  220. * @date 2024/6/6
  221. */
  222. public function customTimer($customCode = '')
  223. {
  224. try {
  225. eval($customCode);
  226. $this->crontabLog(' 自定义定时器执行成功');
  227. } catch (\Throwable $e) {
  228. $this->crontabLog('自定义定时器执行失败,失败原因:' . $e->getMessage());
  229. }
  230. }
  231. }