定时任务优化

This commit is contained in:
吴昊天 2023-02-21 16:26:32 +08:00
parent bf78ff8acd
commit ca02d7b69d
9 changed files with 58 additions and 52 deletions

View File

@ -3,12 +3,12 @@
namespace app\adminapi\controller\v1\system;
use app\adminapi\controller\AuthController;
use app\services\system\timer\SystemTimerServices;
use app\services\system\crontab\SystemCrontabServices;
use think\facade\App;
class SystemTimer extends AuthController
class SystemCrontab extends AuthController
{
public function __construct(App $app, SystemTimerServices $services)
public function __construct(App $app, SystemCrontabServices $services)
{
parent::__construct($app);
$this->services = $services;

View File

@ -99,17 +99,17 @@ Route::group('system', function () {
/** 定时任务 */
//定时任务列表
Route::get('timer/list', 'v1.system.SystemTimer/getTimerList')->option(['real_name' => '定时任务列表']);
Route::get('timer/list', 'v1.system.SystemCrontab/getTimerList')->option(['real_name' => '定时任务列表']);
//定时任务类型
Route::get('timer/mark', 'v1.system.SystemTimer/getMarkList')->option(['real_name' => '定时任务类型']);
Route::get('timer/mark', 'v1.system.SystemCrontab/getMarkList')->option(['real_name' => '定时任务类型']);
//定时任务详情
Route::get('timer/info/:id', 'v1.system.SystemTimer/getTimerInfo')->option(['real_name' => '定时任务详情']);
Route::get('timer/info/:id', 'v1.system.SystemCrontab/getTimerInfo')->option(['real_name' => '定时任务详情']);
//定时任务添加编辑
Route::post('timer/save', 'v1.system.SystemTimer/saveTimer')->option(['real_name' => '定时任务添加编辑']);
Route::post('timer/save', 'v1.system.SystemCrontab/saveTimer')->option(['real_name' => '定时任务添加编辑']);
//删除定时任务
Route::delete('timer/del/:id', 'v1.system.SystemTimer/delTimer')->option(['real_name' => '删除定时任务']);
Route::delete('timer/del/:id', 'v1.system.SystemCrontab/delTimer')->option(['real_name' => '删除定时任务']);
//定时任务是否开启开关
Route::get('timer/set_open/:id/:is_open', 'v1.system.SystemTimer/setTimerStatus')->option(['real_name' => '定时任务是否开启开关']);
Route::get('timer/set_open/:id/:is_open', 'v1.system.SystemCrontab/setTimerStatus')->option(['real_name' => '定时任务是否开启开关']);
})->middleware([
\app\http\middleware\AllowOriginMiddleware::class,

View File

@ -10,9 +10,15 @@ use app\services\order\StoreOrderServices;
use app\services\order\StoreOrderTakeServices;
use app\services\product\product\StoreProductServices;
use app\services\system\attachment\SystemAttachmentServices;
use app\services\system\timer\SystemTimerServices;
use app\services\system\crontab\SystemCrontabServices;
class TimerController
/**
* 定时任务控制器
* @author 吴汐
* @email 442384644@qq.com
* @date 2023/02/21
*/
class CrontabController
{
/**
* 定时任务调用接口
@ -22,13 +28,13 @@ class TimerController
*/
public function crontabRun()
{
app()->make(SystemTimerServices::class)->crontabRun();
app()->make(SystemCrontabServices::class)->crontabRun();
}
/**
* 检测定时任务是否正常,必须6秒执行一次
*/
public function timerCheck()
public function crontabCheck()
{
file_put_contents(root_path() . 'runtime/.timer', time());
}

View File

@ -391,27 +391,27 @@ Route::group(function () {
/** 定时任务接口 */
//定时任务调用接口
Route::get('crontab/run', 'v1.TimerController/crontabRun')->name('crontabRun');
Route::get('crontab/run', 'v1.CrontabController/crontabRun')->name('crontabRun');
//检测定时任务接口
Route::get('timer/check', 'v1.TimerController/timerCheck')->name('timerCheck');
Route::get('crontab/check', 'v1.CrontabController/crontabCheck')->name('crontabCheck');
//未支付自动取消订单
Route::get('timer/order_cancel', 'v1.TimerController/orderUnpaidCancel')->name('orderUnpaidCancel');
Route::get('crontab/order_cancel', 'v1.CrontabController/orderUnpaidCancel')->name('orderUnpaidCancel');
//拼团到期订单处理
Route::get('timer/pink_expiration', 'v1.TimerController/pinkExpiration')->name('pinkExpiration');
Route::get('crontab/pink_expiration', 'v1.CrontabController/pinkExpiration')->name('pinkExpiration');
//自动解绑上级绑定
Route::get('timer/agent_unbind', 'v1.TimerController/agentUnbind')->name('agentUnbind');
Route::get('crontab/agent_unbind', 'v1.CrontabController/agentUnbind')->name('agentUnbind');
//更新直播商品状态
Route::get('timer/live_product_status', 'v1.TimerController/syncGoodStatus')->name('syncGoodStatus');
Route::get('crontab/live_product_status', 'v1.CrontabController/syncGoodStatus')->name('syncGoodStatus');
//更新直播间状态
Route::get('timer/live_room_status', 'v1.TimerController/syncRoomStatus')->name('syncRoomStatus');
Route::get('crontab/live_room_status', 'v1.CrontabController/syncRoomStatus')->name('syncRoomStatus');
//自动收货
Route::get('timer/take_delivery', 'v1.TimerController/autoTakeOrder')->name('autoTakeOrder');
Route::get('crontab/take_delivery', 'v1.CrontabController/autoTakeOrder')->name('autoTakeOrder');
//查询预售到期商品自动下架
Route::get('timer/advance_off', 'v1.TimerController/downAdvance')->name('downAdvance');
Route::get('crontab/advance_off', 'v1.CrontabController/downAdvance')->name('downAdvance');
//自动好评
Route::get('timer/product_replay', 'v1.TimerController/autoComment')->name('autoComment');
Route::get('crontab/product_replay', 'v1.CrontabController/autoComment')->name('autoComment');
//清除昨日海报
Route::get('timer/clear_poster', 'v1.TimerController/emptyYesterdayAttachment')->name('emptyYesterdayAttachment');
Route::get('crontab/clear_poster', 'v1.CrontabController/emptyYesterdayAttachment')->name('emptyYesterdayAttachment');
})->middleware(\app\http\middleware\AllowOriginMiddleware::class)->middleware(\app\api\middleware\StationOpenMiddleware::class)->middleware(\app\api\middleware\AuthTokenMiddleware::class, false);

View File

@ -0,0 +1,18 @@
<?php
namespace app\dao\system\crontab;
use app\dao\BaseDao;
use app\model\system\crontab\SystemCrontab;
class SystemCrontabDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return SystemCrontab::class;
}
}

View File

@ -1,18 +0,0 @@
<?php
namespace app\dao\system\timer;
use app\dao\BaseDao;
use app\model\system\timer\SystemTimer;
class SystemTimerDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return SystemTimer::class;
}
}

View File

@ -10,7 +10,7 @@ use app\services\order\StoreOrderServices;
use app\services\order\StoreOrderTakeServices;
use app\services\product\product\StoreProductServices;
use app\services\system\attachment\SystemAttachmentServices;
use app\services\system\timer\SystemTimerServices;
use app\services\system\crontab\SystemCrontabServices;
use crmeb\interfaces\ListenerInterface;
use think\facade\Log;
use Workerman\Crontab\Crontab;
@ -27,9 +27,9 @@ class SystemCrontab implements ListenerInterface
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) {
//获取定时任务时间字符串
$timeStr = $this->getTimerStr($item);

View File

@ -1,11 +1,11 @@
<?php
namespace app\model\system\timer;
namespace app\model\system\crontab;
use crmeb\basic\BaseModel;
use crmeb\traits\ModelTrait;
class SystemTimer extends BaseModel
class SystemCrontab extends BaseModel
{
use ModelTrait;

View File

@ -1,8 +1,8 @@
<?php
namespace app\services\system\timer;
namespace app\services\system\crontab;
use app\dao\system\timer\SystemTimerDao;
use app\dao\system\crontab\SystemCrontabDao;
use app\services\activity\combination\StorePinkServices;
use app\services\activity\live\LiveGoodsServices;
use app\services\activity\live\LiveRoomServices;
@ -15,7 +15,7 @@ use app\services\system\attachment\SystemAttachmentServices;
use crmeb\exceptions\AdminException;
use think\facade\Log;
class SystemTimerServices extends BaseServices
class SystemCrontabServices extends BaseServices
{
/**
* 定时任务类型
@ -33,7 +33,7 @@ class SystemTimerServices extends BaseServices
'clear_poster' => '清除昨日海报',
];
public function __construct(SystemTimerDao $dao)
public function __construct(SystemCrontabDao $dao)
{
$this->dao = $dao;
}