feat(publish-plan): add publish plan query and API routes
- Introduced `buildPublishPlanQuery` method in `DyVideoCron` model to create a base query for the publish plan module, filtering records based on user ID and project status. - Added new API routes under `v1/publish-plan` for listing, starting, and stopping publish plans, requiring user authentication.
This commit is contained in:
@@ -0,0 +1,115 @@
|
||||
<?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 {
|
||||
$payload = $this->request->payload ?? null;
|
||||
if (!$payload || empty($payload['userid'])) {
|
||||
return Response::error('未登录', 401);
|
||||
}
|
||||
|
||||
$result = $this->publishPlanService->getPlanList((int) $payload['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 {
|
||||
$payload = $this->request->payload ?? null;
|
||||
if (!$payload || empty($payload['userid'])) {
|
||||
return Response::error('未登录', 401);
|
||||
}
|
||||
|
||||
$result = $this->publishPlanService->startPlan((int) $payload['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 {
|
||||
$payload = $this->request->payload ?? null;
|
||||
if (!$payload || empty($payload['userid'])) {
|
||||
return Response::error('未登录', 401);
|
||||
}
|
||||
|
||||
$result = $this->publishPlanService->stopPlan((int) $payload['userid'], $id);
|
||||
|
||||
return Response::success($result, '设置成功');
|
||||
} catch (\Exception $exception) {
|
||||
return Response::error($exception->getMessage(), $exception->getCode() ?: 500);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user