CrontabRunServices.php 7.6 KB

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