From 7c5692cee57eb4492fac5397e82504a7f7015596 Mon Sep 17 00:00:00 2001 From: sugar1569 Date: Tue, 21 Feb 2023 15:28:49 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=B3=BB=E7=BB=9F?= =?UTF-8?q?=E5=AE=9A=E6=97=B6=E4=BB=BB=E5=8A=A1=E7=B1=BB=E5=90=8D=20cronta?= =?UTF-8?q?b=EF=BC=8C=E5=AE=B9=E6=98=93=E8=AF=86=E5=88=AB=EF=BC=8C?= =?UTF-8?q?=E4=B8=8D=E5=92=8C=E7=B3=BB=E7=BB=9F=E6=8E=A5=E5=8F=A3=E9=87=8D?= =?UTF-8?q?=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crmeb/app/listener/crontab/SystemCrontab.php | 20 +- crmeb/app/listener/timer/SystemTimer.php | 198 ------------------- 2 files changed, 10 insertions(+), 208 deletions(-) delete mode 100644 crmeb/app/listener/timer/SystemTimer.php diff --git a/crmeb/app/listener/crontab/SystemCrontab.php b/crmeb/app/listener/crontab/SystemCrontab.php index bd9d80e83..226a65259 100644 --- a/crmeb/app/listener/crontab/SystemCrontab.php +++ b/crmeb/app/listener/crontab/SystemCrontab.php @@ -38,7 +38,7 @@ class SystemCrontab implements ListenerInterface $timeStr = $this->getTimerStr($item); //未支付自动取消订单 if ($item['mark'] == 'order_cancel') { - new Crontab($timeStr, function () use ($date, $timer_log_open) { + new Crontab($timeStr, function () { try { /** @var StoreOrderServices $orderServices */ $orderServices = app()->make(StoreOrderServices::class); @@ -51,7 +51,7 @@ class SystemCrontab implements ListenerInterface } //拼团到期订单处理 if ($item['mark'] == 'pink_expiration') { - new Crontab($timeStr, function () use ($date, $timer_log_open) { + new Crontab($timeStr, function () { try { /** @var StorePinkServices $storePinkServices */ $storePinkServices = app()->make(StorePinkServices::class); @@ -64,7 +64,7 @@ class SystemCrontab implements ListenerInterface } //自动解绑上级绑定 if ($item['mark'] == 'agent_unbind') { - new Crontab($timeStr, function () use ($date, $timer_log_open) { + new Crontab($timeStr, function () { try { /** @var AgentManageServices $agentManage */ $agentManage = app()->make(AgentManageServices::class); @@ -77,7 +77,7 @@ class SystemCrontab implements ListenerInterface } //更新直播商品状态 if ($item['mark'] == 'live_product_status') { - new Crontab($timeStr, function () use ($date, $timer_log_open) { + new Crontab($timeStr, function () { try { /** @var LiveGoodsServices $liveGoods */ $liveGoods = app()->make(LiveGoodsServices::class); @@ -90,7 +90,7 @@ class SystemCrontab implements ListenerInterface } //更新直播间状态 if ($item['mark'] == 'live_room_status') { - new Crontab($timeStr, function () use ($date, $timer_log_open) { + new Crontab($timeStr, function () { try { /** @var LiveRoomServices $liveRoom */ $liveRoom = app()->make(LiveRoomServices::class); @@ -104,7 +104,7 @@ class SystemCrontab implements ListenerInterface } //自动收货 if ($item['mark'] == 'take_delivery') { - new Crontab($timeStr, function () use ($date, $timer_log_open) { + new Crontab($timeStr, function () { try { /** @var StoreOrderTakeServices $services */ $services = app()->make(StoreOrderTakeServices::class); @@ -117,7 +117,7 @@ class SystemCrontab implements ListenerInterface } //查询预售到期商品自动下架 if ($item['mark'] == 'advance_off') { - new Crontab($timeStr, function () use ($date, $timer_log_open) { + new Crontab($timeStr, function () { try { /** @var StoreProductServices $product */ $product = app()->make(StoreProductServices::class); @@ -130,7 +130,7 @@ class SystemCrontab implements ListenerInterface } //自动好评 if ($item['mark'] == 'product_replay') { - new Crontab($timeStr, function () use ($date, $timer_log_open) { + new Crontab($timeStr, function () { try { /** @var StoreOrderServices $orderServices */ $orderServices = app()->make(StoreOrderServices::class); @@ -143,7 +143,7 @@ class SystemCrontab implements ListenerInterface } //清除昨日海报 if ($item['mark'] == 'clear_poster') { - new Crontab($timeStr, function () use ($date, $timer_log_open) { + new Crontab($timeStr, function () { try { /** @var SystemAttachmentServices $attach */ $attach = app()->make(SystemAttachmentServices::class); @@ -165,7 +165,7 @@ class SystemCrontab implements ListenerInterface $timer_log_open = config("log.timer_log", false); if ($timer_log_open){ $date = date('Y-m-d H:i:s', time()); - Log::notice($date . ' 执行清除昨日海报'); + Log::notice($date . $msg); } } /** diff --git a/crmeb/app/listener/timer/SystemTimer.php b/crmeb/app/listener/timer/SystemTimer.php deleted file mode 100644 index add6798dc..000000000 --- a/crmeb/app/listener/timer/SystemTimer.php +++ /dev/null @@ -1,198 +0,0 @@ -make(SystemTimerServices::class); - $list = $systemTimerServices->selectList(['is_del' => 0, 'is_open' => 1])->toArray(); - foreach ($list as &$item) { - //获取定时任务时间字符串 - $timeStr = $this->getTimerStr($item); - //未支付自动取消订单 - if ($item['mark'] == 'order_cancel') { - new Crontab($timeStr, function () use ($date, $timer_log_open) { - try { - /** @var StoreOrderServices $orderServices */ - $orderServices = app()->make(StoreOrderServices::class); - $orderServices->orderUnpaidCancel(); - if ($timer_log_open) Log::notice($date . ' 执行未支付自动取消订单'); - } catch (\Throwable $e) { - Log::error('自动取消订单失败,失败原因:' . $e->getMessage()); - } - }); - } - //拼团到期订单处理 - if ($item['mark'] == 'pink_expiration') { - new Crontab($timeStr, function () use ($date, $timer_log_open) { - try { - /** @var StorePinkServices $storePinkServices */ - $storePinkServices = app()->make(StorePinkServices::class); - $storePinkServices->statusPink(); - if ($timer_log_open) Log::notice($date . ' 执行拼团到期订单处理'); - } catch (\Throwable $e) { - Log::error('拼团到期订单处理失败,失败原因:' . $e->getMessage()); - } - }); - } - //自动解绑上级绑定 - if ($item['mark'] == 'agent_unbind') { - new Crontab($timeStr, function () use ($date, $timer_log_open) { - try { - /** @var AgentManageServices $agentManage */ - $agentManage = app()->make(AgentManageServices::class); - $agentManage->removeSpread(); - if ($timer_log_open) Log::notice($date . ' 执行自动解绑上级绑定'); - } catch (\Throwable $e) { - Log::error('自动解除上级绑定失败,失败原因:' . $e->getMessage()); - } - }); - } - //更新直播商品状态 - if ($item['mark'] == 'live_product_status') { - new Crontab($timeStr, function () use ($date, $timer_log_open) { - try { - /** @var LiveGoodsServices $liveGoods */ - $liveGoods = app()->make(LiveGoodsServices::class); - $liveGoods->syncGoodStatus(); - if ($timer_log_open) Log::notice($date . ' 执行更新直播商品状态'); - } catch (\Throwable $e) { - Log::error('更新直播商品状态失败,失败原因:' . $e->getMessage()); - } - }); - } - //更新直播间状态 - if ($item['mark'] == 'live_room_status') { - new Crontab($timeStr, function () use ($date, $timer_log_open) { - try { - /** @var LiveRoomServices $liveRoom */ - $liveRoom = app()->make(LiveRoomServices::class); - $liveRoom->syncRoomStatus(); - if ($timer_log_open) Log::notice($date . ' 执行更新直播间状态'); - } catch (\Throwable $e) { - Log::error('更新直播间状态失败,失败原因:' . $e->getMessage()); - } - }); - } - //自动收货 - if ($item['mark'] == 'take_delivery') { - new Crontab($timeStr, function () use ($date, $timer_log_open) { - try { - /** @var StoreOrderTakeServices $services */ - $services = app()->make(StoreOrderTakeServices::class); - $services->autoTakeOrder(); - if ($timer_log_open) Log::notice($date . ' 执行自动收货'); - } catch (\Throwable $e) { - Log::error('自动收货失败,失败原因:' . $e->getMessage()); - } - }); - } - //查询预售到期商品自动下架 - if ($item['mark'] == 'advance_off') { - new Crontab($timeStr, function () use ($date, $timer_log_open) { - try { - /** @var StoreProductServices $product */ - $product = app()->make(StoreProductServices::class); - $product->downAdvance(); - if ($timer_log_open) Log::notice($date . ' 执行预售到期商品自动下架'); - } catch (\Throwable $e) { - Log::error('预售到期商品自动下架失败,失败原因:' . $e->getMessage()); - } - }); - } - //自动好评 - if ($item['mark'] == 'product_replay') { - new Crontab($timeStr, function () use ($date, $timer_log_open) { - try { - /** @var StoreOrderServices $orderServices */ - $orderServices = app()->make(StoreOrderServices::class); - $orderServices->autoComment(); - if ($timer_log_open) Log::notice($date . ' 执行自动好评'); - } catch (\Throwable $e) { - Log::error('自动好评失败,失败原因:' . $e->getMessage()); - } - }); - } - //清除昨日海报 - if ($item['mark'] == 'clear_poster') { - new Crontab($timeStr, function () use ($date, $timer_log_open) { - try { - /** @var SystemAttachmentServices $attach */ - $attach = app()->make(SystemAttachmentServices::class); - $attach->emptyYesterdayAttachment(); - if ($timer_log_open) Log::notice($date . ' 执行清除昨日海报'); - } catch (\Throwable $e) { - Log::error('清除昨日海报失败,失败原因:' . $e->getMessage()); - } - }); - } - } - } - /** - * 0 1 2 3 4 5 - * | | | | | | - * | | | | | +------ day of week (0 - 6) (Sunday=0) - * | | | | +------ month (1 - 12) - * | | | +-------- day of month (1 - 31) - * | | +---------- hour (0 - 23) - * | +------------ min (0 - 59) - * +-------------- sec (0-59)[可省略,如果没有0位,则最小时间粒度是分钟] - */ - /** - * 获取定时任务时间表达式 - * @param $data - * @return string - */ - public function getTimerStr($data): string - { - $timeStr = ''; - switch ($data['type']) { - case 1:// 每隔几秒 - $timeStr = '*/' . $data['second'] . ' * * * * *'; - break; - case 2:// 每隔几分 - $timeStr = '0 */' . $data['minute'] . ' * * * *'; - break; - case 3:// 每隔几时第几分钟执行 - $timeStr = '0 ' . $data['minute'] . ' */' . $data['hour'] . ' * * *'; - break; - case 4:// 每隔几日第几小时第几分钟执行 - $timeStr = '0 ' . $data['minute'] . ' ' . $data['hour'] . ' */' . $data['day'] . ' * *'; - break; - case 5:// 每日几时几分几秒 - $timeStr = $data['second'] . ' ' . $data['minute'] . ' ' . $data['hour'] . ' * * *'; - break; - case 6:// 每周周几几时几分几秒 - $timeStr = $data['second'] . ' ' . $data['minute'] . ' ' . $data['hour'] . ' * * ' . ($data['week'] == 7 ? 0 : $data['week']); - break; - case 7:// 每月几日几时几分几秒 - $timeStr = $data['second'] . ' ' . $data['minute'] . ' ' . $data['hour'] . ' ' . $data['day'] . ' * *'; - break; - } - return $timeStr; - } -} From 77a9b81301ac561cf8739d3be5e4933c04d99f87 Mon Sep 17 00:00:00 2001 From: sugar1569 Date: Tue, 21 Feb 2023 15:43:56 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=B3=BB=E7=BB=9F?= =?UTF-8?q?=E5=AE=9A=E6=97=B6=E4=BB=BB=E5=8A=A1=E7=B1=BB=E5=90=8D=20cronta?= =?UTF-8?q?b=EF=BC=8C=E5=AE=B9=E6=98=93=E8=AF=86=E5=88=AB=EF=BC=8C?= =?UTF-8?q?=E4=B8=8D=E5=92=8C=E7=B3=BB=E7=BB=9F=E6=8E=A5=E5=8F=A3=E9=87=8D?= =?UTF-8?q?=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crmeb/app/listener/crontab/SystemCrontab.php | 24 +++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/crmeb/app/listener/crontab/SystemCrontab.php b/crmeb/app/listener/crontab/SystemCrontab.php index 226a65259..335c5e0d1 100644 --- a/crmeb/app/listener/crontab/SystemCrontab.php +++ b/crmeb/app/listener/crontab/SystemCrontab.php @@ -22,10 +22,8 @@ class SystemCrontab implements ListenerInterface { public function handle($event): void { + //自动写入文件方便检测是否启动定时任务命令 $time = time(); - $date = date('Y-m-d H:i:s', time()); - $timer_log_open = config("log.timer_log", false); - new Crontab('*/6 * * * * *', function () use ($time) { file_put_contents(root_path() . 'runtime/.timer', $time); }); @@ -50,7 +48,7 @@ class SystemCrontab implements ListenerInterface }); } //拼团到期订单处理 - if ($item['mark'] == 'pink_expiration') { + elseif ($item['mark'] == 'pink_expiration') { new Crontab($timeStr, function () { try { /** @var StorePinkServices $storePinkServices */ @@ -63,7 +61,7 @@ class SystemCrontab implements ListenerInterface }); } //自动解绑上级绑定 - if ($item['mark'] == 'agent_unbind') { + elseif ($item['mark'] == 'agent_unbind') { new Crontab($timeStr, function () { try { /** @var AgentManageServices $agentManage */ @@ -76,7 +74,7 @@ class SystemCrontab implements ListenerInterface }); } //更新直播商品状态 - if ($item['mark'] == 'live_product_status') { + elseif ($item['mark'] == 'live_product_status') { new Crontab($timeStr, function () { try { /** @var LiveGoodsServices $liveGoods */ @@ -89,7 +87,7 @@ class SystemCrontab implements ListenerInterface }); } //更新直播间状态 - if ($item['mark'] == 'live_room_status') { + elseif ($item['mark'] == 'live_room_status') { new Crontab($timeStr, function () { try { /** @var LiveRoomServices $liveRoom */ @@ -103,7 +101,7 @@ class SystemCrontab implements ListenerInterface }); } //自动收货 - if ($item['mark'] == 'take_delivery') { + elseif ($item['mark'] == 'take_delivery') { new Crontab($timeStr, function () { try { /** @var StoreOrderTakeServices $services */ @@ -116,7 +114,7 @@ class SystemCrontab implements ListenerInterface }); } //查询预售到期商品自动下架 - if ($item['mark'] == 'advance_off') { + elseif ($item['mark'] == 'advance_off') { new Crontab($timeStr, function () { try { /** @var StoreProductServices $product */ @@ -129,7 +127,7 @@ class SystemCrontab implements ListenerInterface }); } //自动好评 - if ($item['mark'] == 'product_replay') { + elseif ($item['mark'] == 'product_replay') { new Crontab($timeStr, function () { try { /** @var StoreOrderServices $orderServices */ @@ -142,7 +140,7 @@ class SystemCrontab implements ListenerInterface }); } //清除昨日海报 - if ($item['mark'] == 'clear_poster') { + elseif ($item['mark'] == 'clear_poster') { new Crontab($timeStr, function () { try { /** @var SystemAttachmentServices $attach */ @@ -154,6 +152,10 @@ class SystemCrontab implements ListenerInterface } }); } + // + else { + + } } }