|
@@ -1,6 +1,6 @@
|
|
|
<?php
|
|
<?php
|
|
|
|
|
|
|
|
-namespace app\listener\timer;
|
|
|
|
|
|
|
+namespace app\listener\crontab;
|
|
|
|
|
|
|
|
use app\services\activity\combination\StorePinkServices;
|
|
use app\services\activity\combination\StorePinkServices;
|
|
|
use app\services\activity\live\LiveGoodsServices;
|
|
use app\services\activity\live\LiveGoodsServices;
|
|
@@ -10,148 +10,148 @@ use app\services\order\StoreOrderServices;
|
|
|
use app\services\order\StoreOrderTakeServices;
|
|
use app\services\order\StoreOrderTakeServices;
|
|
|
use app\services\product\product\StoreProductServices;
|
|
use app\services\product\product\StoreProductServices;
|
|
|
use app\services\system\attachment\SystemAttachmentServices;
|
|
use app\services\system\attachment\SystemAttachmentServices;
|
|
|
-use app\services\system\timer\SystemTimerServices;
|
|
|
|
|
|
|
+use app\services\system\crontab\SystemCrontabServices;
|
|
|
use crmeb\interfaces\ListenerInterface;
|
|
use crmeb\interfaces\ListenerInterface;
|
|
|
use think\facade\Log;
|
|
use think\facade\Log;
|
|
|
use Workerman\Crontab\Crontab;
|
|
use Workerman\Crontab\Crontab;
|
|
|
|
|
|
|
|
-class SystemTimer implements ListenerInterface
|
|
|
|
|
|
|
+/**
|
|
|
|
|
+ * 系统定时任务
|
|
|
|
|
+ */
|
|
|
|
|
+class SystemCrontabListener implements ListenerInterface
|
|
|
{
|
|
{
|
|
|
public function handle($event): void
|
|
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);
|
|
|
|
|
|
|
+ //自动写入文件方便检测是否启动定时任务命令
|
|
|
|
|
+ new Crontab('*/6 * * * * *', function () {
|
|
|
|
|
+ file_put_contents(root_path() . 'runtime/.timer', time());
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
- /** @var SystemTimerServices $systemTimerServices */
|
|
|
|
|
- $systemTimerServices = app()->make(SystemTimerServices::class);
|
|
|
|
|
- $list = $systemTimerServices->selectList(['is_del' => 0, 'is_open' => 1])->toArray();
|
|
|
|
|
|
|
+ /** @var SystemCrontabServices $systemTimerServices */
|
|
|
|
|
+ $systemCrontabServices = app()->make(SystemCrontabServices::class);
|
|
|
|
|
+ $list = $systemCrontabServices->selectList(['is_del' => 0, 'is_open' => 1])->toArray();
|
|
|
foreach ($list as &$item) {
|
|
foreach ($list as &$item) {
|
|
|
//获取定时任务时间字符串
|
|
//获取定时任务时间字符串
|
|
|
$timeStr = $this->getTimerStr($item);
|
|
$timeStr = $this->getTimerStr($item);
|
|
|
//未支付自动取消订单
|
|
//未支付自动取消订单
|
|
|
if ($item['mark'] == 'order_cancel') {
|
|
if ($item['mark'] == 'order_cancel') {
|
|
|
- new Crontab($timeStr, function () use ($date, $timer_log_open) {
|
|
|
|
|
|
|
+ new Crontab($timeStr, function () {
|
|
|
try {
|
|
try {
|
|
|
- /** @var StoreOrderServices $orderServices */
|
|
|
|
|
- $orderServices = app()->make(StoreOrderServices::class);
|
|
|
|
|
- $orderServices->orderUnpaidCancel();
|
|
|
|
|
- if ($timer_log_open) Log::notice($date . ' 执行未支付自动取消订单');
|
|
|
|
|
|
|
+ app()->make(StoreOrderServices::class)->orderUnpaidCancel();
|
|
|
|
|
+ $this->crontabLog(' 执行未支付自动取消订单');
|
|
|
} catch (\Throwable $e) {
|
|
} catch (\Throwable $e) {
|
|
|
Log::error('自动取消订单失败,失败原因:' . $e->getMessage());
|
|
Log::error('自动取消订单失败,失败原因:' . $e->getMessage());
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
//拼团到期订单处理
|
|
//拼团到期订单处理
|
|
|
- if ($item['mark'] == 'pink_expiration') {
|
|
|
|
|
- new Crontab($timeStr, function () use ($date, $timer_log_open) {
|
|
|
|
|
|
|
+ elseif ($item['mark'] == 'pink_expiration') {
|
|
|
|
|
+ new Crontab($timeStr, function () {
|
|
|
try {
|
|
try {
|
|
|
- /** @var StorePinkServices $storePinkServices */
|
|
|
|
|
- $storePinkServices = app()->make(StorePinkServices::class);
|
|
|
|
|
- $storePinkServices->statusPink();
|
|
|
|
|
- if ($timer_log_open) Log::notice($date . ' 执行拼团到期订单处理');
|
|
|
|
|
|
|
+ app()->make(StorePinkServices::class)->statusPink();
|
|
|
|
|
+ $this->crontabLog(' 执行拼团到期订单处理');
|
|
|
} catch (\Throwable $e) {
|
|
} catch (\Throwable $e) {
|
|
|
Log::error('拼团到期订单处理失败,失败原因:' . $e->getMessage());
|
|
Log::error('拼团到期订单处理失败,失败原因:' . $e->getMessage());
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
//自动解绑上级绑定
|
|
//自动解绑上级绑定
|
|
|
- if ($item['mark'] == 'agent_unbind') {
|
|
|
|
|
- new Crontab($timeStr, function () use ($date, $timer_log_open) {
|
|
|
|
|
|
|
+ elseif ($item['mark'] == 'agent_unbind') {
|
|
|
|
|
+ new Crontab($timeStr, function () {
|
|
|
try {
|
|
try {
|
|
|
- /** @var AgentManageServices $agentManage */
|
|
|
|
|
- $agentManage = app()->make(AgentManageServices::class);
|
|
|
|
|
- $agentManage->removeSpread();
|
|
|
|
|
- if ($timer_log_open) Log::notice($date . ' 执行自动解绑上级绑定');
|
|
|
|
|
|
|
+ app()->make(AgentManageServices::class)->removeSpread();
|
|
|
|
|
+ $this->crontabLog(' 执行自动解绑上级绑定');
|
|
|
} catch (\Throwable $e) {
|
|
} catch (\Throwable $e) {
|
|
|
Log::error('自动解除上级绑定失败,失败原因:' . $e->getMessage());
|
|
Log::error('自动解除上级绑定失败,失败原因:' . $e->getMessage());
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
//更新直播商品状态
|
|
//更新直播商品状态
|
|
|
- if ($item['mark'] == 'live_product_status') {
|
|
|
|
|
- new Crontab($timeStr, function () use ($date, $timer_log_open) {
|
|
|
|
|
|
|
+ elseif ($item['mark'] == 'live_product_status') {
|
|
|
|
|
+ new Crontab($timeStr, function () {
|
|
|
try {
|
|
try {
|
|
|
- /** @var LiveGoodsServices $liveGoods */
|
|
|
|
|
- $liveGoods = app()->make(LiveGoodsServices::class);
|
|
|
|
|
- $liveGoods->syncGoodStatus();
|
|
|
|
|
- if ($timer_log_open) Log::notice($date . ' 执行更新直播商品状态');
|
|
|
|
|
|
|
+ app()->make(LiveGoodsServices::class)->syncGoodStatus();
|
|
|
|
|
+ $this->crontabLog(' 执行更新直播商品状态');
|
|
|
} catch (\Throwable $e) {
|
|
} catch (\Throwable $e) {
|
|
|
Log::error('更新直播商品状态失败,失败原因:' . $e->getMessage());
|
|
Log::error('更新直播商品状态失败,失败原因:' . $e->getMessage());
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
//更新直播间状态
|
|
//更新直播间状态
|
|
|
- if ($item['mark'] == 'live_room_status') {
|
|
|
|
|
- new Crontab($timeStr, function () use ($date, $timer_log_open) {
|
|
|
|
|
|
|
+ elseif ($item['mark'] == 'live_room_status') {
|
|
|
|
|
+ new Crontab($timeStr, function () {
|
|
|
try {
|
|
try {
|
|
|
- /** @var LiveRoomServices $liveRoom */
|
|
|
|
|
- $liveRoom = app()->make(LiveRoomServices::class);
|
|
|
|
|
- $liveRoom->syncRoomStatus();
|
|
|
|
|
- if ($timer_log_open) Log::notice($date . ' 执行更新直播间状态');
|
|
|
|
|
|
|
+ app()->make(LiveRoomServices::class)->syncRoomStatus();
|
|
|
|
|
+ $this->crontabLog(' 执行更新直播间状态');
|
|
|
} catch (\Throwable $e) {
|
|
} catch (\Throwable $e) {
|
|
|
Log::error('更新直播间状态失败,失败原因:' . $e->getMessage());
|
|
Log::error('更新直播间状态失败,失败原因:' . $e->getMessage());
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
//自动收货
|
|
//自动收货
|
|
|
- if ($item['mark'] == 'take_delivery') {
|
|
|
|
|
- new Crontab($timeStr, function () use ($date, $timer_log_open) {
|
|
|
|
|
|
|
+ elseif ($item['mark'] == 'take_delivery') {
|
|
|
|
|
+ new Crontab($timeStr, function () {
|
|
|
try {
|
|
try {
|
|
|
- /** @var StoreOrderTakeServices $services */
|
|
|
|
|
- $services = app()->make(StoreOrderTakeServices::class);
|
|
|
|
|
- $services->autoTakeOrder();
|
|
|
|
|
- if ($timer_log_open) Log::notice($date . ' 执行自动收货');
|
|
|
|
|
|
|
+ app()->make(StoreOrderTakeServices::class)->autoTakeOrder();
|
|
|
|
|
+ $this->crontabLog(' 执行自动收货');
|
|
|
} catch (\Throwable $e) {
|
|
} catch (\Throwable $e) {
|
|
|
Log::error('自动收货失败,失败原因:' . $e->getMessage());
|
|
Log::error('自动收货失败,失败原因:' . $e->getMessage());
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
//查询预售到期商品自动下架
|
|
//查询预售到期商品自动下架
|
|
|
- if ($item['mark'] == 'advance_off') {
|
|
|
|
|
- new Crontab($timeStr, function () use ($date, $timer_log_open) {
|
|
|
|
|
|
|
+ elseif ($item['mark'] == 'advance_off') {
|
|
|
|
|
+ new Crontab($timeStr, function () {
|
|
|
try {
|
|
try {
|
|
|
- /** @var StoreProductServices $product */
|
|
|
|
|
- $product = app()->make(StoreProductServices::class);
|
|
|
|
|
- $product->downAdvance();
|
|
|
|
|
- if ($timer_log_open) Log::notice($date . ' 执行预售到期商品自动下架');
|
|
|
|
|
|
|
+ app()->make(StoreProductServices::class)->downAdvance();
|
|
|
|
|
+ $this->crontabLog(' 执行预售到期商品自动下架');
|
|
|
} catch (\Throwable $e) {
|
|
} catch (\Throwable $e) {
|
|
|
Log::error('预售到期商品自动下架失败,失败原因:' . $e->getMessage());
|
|
Log::error('预售到期商品自动下架失败,失败原因:' . $e->getMessage());
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
//自动好评
|
|
//自动好评
|
|
|
- if ($item['mark'] == 'product_replay') {
|
|
|
|
|
- new Crontab($timeStr, function () use ($date, $timer_log_open) {
|
|
|
|
|
|
|
+ elseif ($item['mark'] == 'product_replay') {
|
|
|
|
|
+ new Crontab($timeStr, function () {
|
|
|
try {
|
|
try {
|
|
|
- /** @var StoreOrderServices $orderServices */
|
|
|
|
|
- $orderServices = app()->make(StoreOrderServices::class);
|
|
|
|
|
- $orderServices->autoComment();
|
|
|
|
|
- if ($timer_log_open) Log::notice($date . ' 执行自动好评');
|
|
|
|
|
|
|
+ app()->make(StoreOrderServices::class)->autoComment();
|
|
|
|
|
+ $this->crontabLog(' 执行自动好评');
|
|
|
} catch (\Throwable $e) {
|
|
} catch (\Throwable $e) {
|
|
|
Log::error('自动好评失败,失败原因:' . $e->getMessage());
|
|
Log::error('自动好评失败,失败原因:' . $e->getMessage());
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
//清除昨日海报
|
|
//清除昨日海报
|
|
|
- if ($item['mark'] == 'clear_poster') {
|
|
|
|
|
- new Crontab($timeStr, function () use ($date, $timer_log_open) {
|
|
|
|
|
|
|
+ elseif ($item['mark'] == 'clear_poster') {
|
|
|
|
|
+ new Crontab($timeStr, function () {
|
|
|
try {
|
|
try {
|
|
|
- /** @var SystemAttachmentServices $attach */
|
|
|
|
|
- $attach = app()->make(SystemAttachmentServices::class);
|
|
|
|
|
- $attach->emptyYesterdayAttachment();
|
|
|
|
|
- if ($timer_log_open) Log::notice($date . ' 执行清除昨日海报');
|
|
|
|
|
|
|
+ app()->make(SystemAttachmentServices::class)->emptyYesterdayAttachment();
|
|
|
|
|
+ $this->crontabLog(' 执行清除昨日海报');
|
|
|
} catch (\Throwable $e) {
|
|
} catch (\Throwable $e) {
|
|
|
Log::error('清除昨日海报失败,失败原因:' . $e->getMessage());
|
|
Log::error('清除昨日海报失败,失败原因:' . $e->getMessage());
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
|
|
+ //
|
|
|
|
|
+ else {
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 定时任务日志
|
|
|
|
|
+ * @param $msg
|
|
|
|
|
+ */
|
|
|
|
|
+ public function crontabLog($msg)
|
|
|
|
|
+ {
|
|
|
|
|
+ $timer_log_open = config("log.timer_log", false);
|
|
|
|
|
+ if ($timer_log_open){
|
|
|
|
|
+ $date = date('Y-m-d H:i:s', time());
|
|
|
|
|
+ Log::notice($date . $msg);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 0 1 2 3 4 5
|
|
* 0 1 2 3 4 5
|
|
|
* | | | | | |
|
|
* | | | | | |
|