107 lines
3.0 KiB
PHP
107 lines
3.0 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
namespace app\api\controller\v1;
|
|
|
|
use app\api\common\Response;
|
|
use app\api\controller\BaseController;
|
|
use app\api\service\PublishPlanService;
|
|
use think\App;
|
|
|
|
/**
|
|
* 发布计划控制器。
|
|
*
|
|
* 本控制器用于给小程序“发布计划”页面提供基础能力:
|
|
* 1. 计划列表查询
|
|
* 2. 按状态筛选
|
|
* 3. 按 acgpmw `cron.php` 对齐的 start / stop 最小动作
|
|
*/
|
|
class PublishPlan extends BaseController
|
|
{
|
|
protected PublishPlanService $publishPlanService;
|
|
|
|
public function __construct(App $app)
|
|
{
|
|
parent::__construct($app);
|
|
$this->publishPlanService = new PublishPlanService();
|
|
}
|
|
|
|
/**
|
|
* 发布计划列表。
|
|
*
|
|
* GET /api/v1/publish-plan/list
|
|
*
|
|
* 请求参数:
|
|
* - `status`:筛选值,支持 `all` / `running` / `stopped` / `finished`
|
|
* - `page`:页码,可选
|
|
* - `page_size`:每页数量,可选
|
|
*
|
|
* 返回结构:
|
|
* - `filters`:状态筛选项
|
|
* - `summary`:顶部统计卡片
|
|
* - `pagination`:分页信息
|
|
* - `list`:计划卡片数据
|
|
*/
|
|
public function index()
|
|
{
|
|
try {
|
|
$userid = $this->getLoginUserId();
|
|
|
|
$result = $this->publishPlanService->getPlanList($userid, [
|
|
'status' => (string) $this->request->get('status', 'all'),
|
|
'page' => (int) $this->request->get('page', 1),
|
|
'page_size' => (int) $this->request->get('page_size', 20),
|
|
]);
|
|
|
|
return Response::success($result);
|
|
} catch (\Exception $exception) {
|
|
return Response::error($exception->getMessage(), $exception->getCode() ?: 500);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 开启发布计划。
|
|
*
|
|
* 这里按 acgpmw `cron::fabu()` 逻辑对齐,只更新 `jrstop=0`。
|
|
* 已完成计划不提供恢复操作,避免小程序在未完整对齐复杂编辑流程时误操作。
|
|
*
|
|
* @param int $id 计划ID
|
|
* @return \think\response\Json
|
|
*/
|
|
public function start(int $id)
|
|
{
|
|
try {
|
|
$userid = $this->getLoginUserId();
|
|
|
|
$result = $this->publishPlanService->startPlan($userid, $id);
|
|
|
|
return Response::success($result, '设置成功');
|
|
} catch (\Exception $exception) {
|
|
return Response::error($exception->getMessage(), $exception->getCode() ?: 500);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 暂停发布计划。
|
|
*
|
|
* 这里按 acgpmw `cron::stop()` 逻辑对齐:
|
|
* 1. 更新 `jrstop=1`
|
|
* 2. 尝试把 `dy_cron_account` 中待执行状态改为 5
|
|
*
|
|
* @param int $id 计划ID
|
|
* @return \think\response\Json
|
|
*/
|
|
public function stop(int $id)
|
|
{
|
|
try {
|
|
$userid = $this->getLoginUserId();
|
|
|
|
$result = $this->publishPlanService->stopPlan($userid, $id);
|
|
|
|
return Response::success($result, '设置成功');
|
|
} catch (\Exception $exception) {
|
|
return Response::error($exception->getMessage(), $exception->getCode() ?: 500);
|
|
}
|
|
}
|
|
}
|