CrontabRunServices.php 8.2 KB

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