feat: add article and production modules
This commit is contained in:
@@ -0,0 +1,231 @@
|
||||
<?php
|
||||
/**
|
||||
* Article 控制器
|
||||
*/
|
||||
|
||||
namespace plugin\article\app\adminapi\controller;
|
||||
|
||||
use app\adminapi\controller\Crud;
|
||||
use app\adminapi\CurrentUser;
|
||||
use app\adminapi\middleware\OperationMiddleware;
|
||||
use app\adminapi\middleware\PermissionMiddleware;
|
||||
use app\model\system\Admin;
|
||||
use core\tool\Json;
|
||||
use madong\swagger\annotation\response\DataResponse;
|
||||
use madong\swagger\annotation\response\SimpleResponse;
|
||||
use madong\swagger\attribute\Permission;
|
||||
use OpenApi\Attributes as OA;
|
||||
use plugin\article\app\model\Content;
|
||||
use support\annotation\Middleware;
|
||||
use support\Request;
|
||||
use support\Response;
|
||||
|
||||
#[Middleware(OperationMiddleware::class, PermissionMiddleware::class)]
|
||||
class ArticleController
|
||||
{
|
||||
protected CurrentUser $currentUser;
|
||||
|
||||
public function __construct(CurrentUser $currentUser)
|
||||
{
|
||||
$this->currentUser = $currentUser;
|
||||
}
|
||||
|
||||
#[OA\Get(
|
||||
path: '/article/legacy/index',
|
||||
summary: '旧版内容列表示例',
|
||||
tags: ['article-legacy']
|
||||
)]
|
||||
#[DataResponse(description: '获取成功')]
|
||||
#[Permission(code: 'article:legacy:index', description: '旧版内容列表示例')]
|
||||
public function index(Request $request): Response
|
||||
{
|
||||
return Json::success('获取成功', [
|
||||
[
|
||||
'title' => '欢迎使用文章管理插件',
|
||||
'category' => '默认分类',
|
||||
'tags' => '插件, 演示',
|
||||
'status' => '已发布',
|
||||
'updated_at' => '2026-07-25 17:50:00',
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
#[OA\Get(
|
||||
path: '/article/legacy/category',
|
||||
summary: '旧版内容分类列表示例',
|
||||
tags: ['article-legacy']
|
||||
)]
|
||||
#[DataResponse(description: '获取成功')]
|
||||
#[Permission(code: 'article:legacy:category', description: '旧版内容分类列表示例')]
|
||||
public function category(Request $request): Response
|
||||
{
|
||||
return Json::success('获取成功', [
|
||||
[
|
||||
'name' => '默认分类',
|
||||
'slug' => 'default-category',
|
||||
'article_count' => 1,
|
||||
'sort' => 100,
|
||||
'updated_at' => '2026-07-25 17:50:00',
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
#[OA\Get(
|
||||
path: '/article/legacy/tag',
|
||||
summary: '旧版标签列表示例',
|
||||
tags: ['article-legacy']
|
||||
)]
|
||||
#[DataResponse(description: '获取成功')]
|
||||
#[Permission(code: 'article:legacy:tag', description: '旧版标签列表示例')]
|
||||
public function tag(Request $request): Response
|
||||
{
|
||||
return Json::success('获取成功', [
|
||||
[
|
||||
'name' => '插件演示',
|
||||
'slug' => 'plugin-demo',
|
||||
'article_count' => 1,
|
||||
'heat' => 88,
|
||||
'updated_at' => '2026-07-25 17:50:00',
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
#[OA\Get(
|
||||
path: '/article/recycle',
|
||||
summary: '内容回收站列表',
|
||||
tags: ['article-legacy']
|
||||
)]
|
||||
#[DataResponse(description: '获取成功')]
|
||||
#[Permission(code: 'article:recycle:index', description: '内容回收站权限')]
|
||||
public function recycle(Request $request): Response
|
||||
{
|
||||
$keyword = trim((string) $request->input('LIKE_title', ''));
|
||||
|
||||
$items = Content::query()
|
||||
->onlyTrashed()
|
||||
->with(['category'])
|
||||
->when($keyword !== '', function ($query) use ($keyword) {
|
||||
$query->where('title', 'like', "%{$keyword}%");
|
||||
})
|
||||
->orderByDesc('deleted_at')
|
||||
->get();
|
||||
|
||||
$operatorIds = $items->pluck('updated_by')
|
||||
->filter(static fn($id) => !empty($id))
|
||||
->unique()
|
||||
->values()
|
||||
->all();
|
||||
|
||||
$operators = empty($operatorIds)
|
||||
? collect()
|
||||
: Admin::query()->whereIn('id', $operatorIds)->get(['id', 'real_name']);
|
||||
|
||||
$operatorMap = $operators->pluck('real_name', 'id');
|
||||
|
||||
$rows = $items->map(function (Content $item) use ($operatorMap) {
|
||||
$deletedAt = $item->deleted_at;
|
||||
return [
|
||||
'id' => $item->id,
|
||||
'title' => $item->title,
|
||||
'category' => $item->category?->name ?? '',
|
||||
'deleted_by' => $operatorMap[$item->updated_by] ?? '',
|
||||
'deleted_at' => $deletedAt ? date('Y-m-d H:i:s', (int) $deletedAt) : '',
|
||||
'expire_at' => $deletedAt ? date('Y-m-d H:i:s', (int) $deletedAt + 30 * 24 * 60 * 60) : '',
|
||||
];
|
||||
})->values()->all();
|
||||
|
||||
return Json::success('获取成功', $rows);
|
||||
}
|
||||
|
||||
#[OA\Put(
|
||||
path: '/article/recycle/{id}/restore',
|
||||
summary: '恢复内容',
|
||||
tags: ['article-legacy']
|
||||
)]
|
||||
#[SimpleResponse(description: '恢复成功')]
|
||||
#[Permission(code: 'article:recycle:restore', description: '恢复回收站内容')]
|
||||
public function restore(Request $request): Response
|
||||
{
|
||||
try {
|
||||
$id = $request->route?->param('id') ?: $request->input('id');
|
||||
$item = Content::withTrashed()->find($id);
|
||||
if (!$item) {
|
||||
return Json::fail('内容不存在');
|
||||
}
|
||||
$item->restore();
|
||||
return Json::success('恢复成功');
|
||||
} catch (\Throwable $e) {
|
||||
return Json::fail($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
#[OA\Delete(
|
||||
path: '/article/recycle/{id}',
|
||||
summary: '彻底删除内容',
|
||||
tags: ['article-legacy']
|
||||
)]
|
||||
#[SimpleResponse(description: '删除成功')]
|
||||
#[Permission(code: 'article:recycle:delete', description: '彻底删除回收站内容')]
|
||||
public function destroyRecycle(Request $request): Response
|
||||
{
|
||||
try {
|
||||
$id = $request->route?->param('id') ?: $request->input('id');
|
||||
$item = Content::withTrashed()->find($id);
|
||||
if (!$item) {
|
||||
return Json::fail('内容不存在');
|
||||
}
|
||||
$item->forceDelete();
|
||||
return Json::success('删除成功');
|
||||
} catch (\Throwable $e) {
|
||||
return Json::fail($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
#[OA\Post(
|
||||
path: '/article/legacy/create',
|
||||
summary: '旧版创建示例',
|
||||
tags: ['article-legacy']
|
||||
)]
|
||||
#[SimpleResponse(description: '创建成功')]
|
||||
#[Permission(code: 'article:legacy:create', description: '旧版创建示例')]
|
||||
public function create(Request $request): Response
|
||||
{
|
||||
return Json::success('创建成功');
|
||||
}
|
||||
|
||||
#[OA\Get(
|
||||
path: '/article/legacy/info',
|
||||
summary: '旧版详情示例',
|
||||
tags: ['article-legacy']
|
||||
)]
|
||||
#[DataResponse(description: '获取成功')]
|
||||
#[Permission(code: 'article:legacy:info', description: '旧版详情示例')]
|
||||
public function info(Request $request): Response
|
||||
{
|
||||
return Json::success('获取成功', []);
|
||||
}
|
||||
|
||||
#[OA\Post(
|
||||
path: '/article/legacy/update',
|
||||
summary: '旧版更新示例',
|
||||
tags: ['article-legacy']
|
||||
)]
|
||||
#[SimpleResponse(description: '更新成功')]
|
||||
#[Permission(code: 'article:legacy:update', description: '旧版更新示例')]
|
||||
public function update(Request $request): Response
|
||||
{
|
||||
return Json::success('更新成功');
|
||||
}
|
||||
|
||||
#[OA\Post(
|
||||
path: '/article/legacy/delete',
|
||||
summary: '旧版删除示例',
|
||||
tags: ['article-legacy']
|
||||
)]
|
||||
#[SimpleResponse(description: '删除成功')]
|
||||
#[Permission(code: 'article:legacy:delete', description: '旧版删除示例')]
|
||||
public function delete(Request $request): Response
|
||||
{
|
||||
return Json::success('删除成功');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,127 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace plugin\article\app\adminapi\controller;
|
||||
|
||||
use app\adminapi\controller\Crud;
|
||||
use app\adminapi\middleware\OperationMiddleware;
|
||||
use app\adminapi\middleware\PermissionMiddleware;
|
||||
use app\schema\request\BatchDeleteRequest;
|
||||
use app\schema\request\IdRequest;
|
||||
use madong\swagger\annotation\response\PageResponse;
|
||||
use madong\swagger\annotation\response\SimpleResponse;
|
||||
use madong\swagger\attribute\Permission;
|
||||
use OpenApi\Attributes as OA;
|
||||
use plugin\article\app\service\admin\CategoryService;
|
||||
use plugin\article\app\validate\CategoryValidate;
|
||||
use support\annotation\Middleware;
|
||||
use support\Request;
|
||||
use WebmanTech\Swagger\DTO\SchemaConstants;
|
||||
|
||||
#[Middleware(OperationMiddleware::class, PermissionMiddleware::class)]
|
||||
class CategoryController extends Crud
|
||||
{
|
||||
public function __construct(CategoryService $service, CategoryValidate $validate)
|
||||
{
|
||||
$this->service = $service;
|
||||
$this->validate = $validate;
|
||||
}
|
||||
|
||||
#[OA\Get(
|
||||
path: '/article/category',
|
||||
summary: '内容分类列表',
|
||||
tags: ['article-category']
|
||||
)]
|
||||
#[Permission(code: 'article:category:list', description: '内容分类列表')]
|
||||
#[PageResponse(schema: [], example: [])]
|
||||
public function index(Request $request): \support\Response
|
||||
{
|
||||
return parent::index($request);
|
||||
}
|
||||
|
||||
#[OA\Get(
|
||||
path: '/article/category/{id}',
|
||||
summary: '内容分类详情',
|
||||
tags: ['article-category'],
|
||||
x: [
|
||||
SchemaConstants::X_PROPERTY_IN => 'id',
|
||||
SchemaConstants::X_SCHEMA_REQUEST => IdRequest::class,
|
||||
]
|
||||
)]
|
||||
#[Permission(code: 'article:category:read', description: '内容分类详情')]
|
||||
#[SimpleResponse(schema: [], example: [])]
|
||||
public function show(Request $request): \support\Response
|
||||
{
|
||||
return parent::show($request);
|
||||
}
|
||||
|
||||
#[OA\Post(
|
||||
path: '/article/category',
|
||||
summary: '创建内容分类',
|
||||
tags: ['article-category']
|
||||
)]
|
||||
#[Permission(code: 'article:category:create', description: '创建内容分类')]
|
||||
#[SimpleResponse(schema: [], example: [])]
|
||||
public function store(Request $request): \support\Response
|
||||
{
|
||||
return parent::store($request);
|
||||
}
|
||||
|
||||
#[OA\Put(
|
||||
path: '/article/category/{id}',
|
||||
summary: '更新内容分类',
|
||||
tags: ['article-category'],
|
||||
x: [
|
||||
SchemaConstants::X_PROPERTY_IN => 'id',
|
||||
SchemaConstants::X_SCHEMA_REQUEST => IdRequest::class,
|
||||
]
|
||||
)]
|
||||
#[Permission(code: 'article:category:update', description: '更新内容分类')]
|
||||
#[SimpleResponse(schema: [], example: [])]
|
||||
public function update(Request $request): \support\Response
|
||||
{
|
||||
return parent::update($request);
|
||||
}
|
||||
|
||||
#[OA\Post(
|
||||
path: '/article/category/export',
|
||||
summary: '导出内容分类',
|
||||
tags: ['article-category']
|
||||
)]
|
||||
#[Permission(code: 'article:category:list', description: '导出内容分类')]
|
||||
#[SimpleResponse(schema: [], example: [])]
|
||||
public function export(Request $request): \support\Response
|
||||
{
|
||||
return parent::export($request);
|
||||
}
|
||||
|
||||
#[OA\Delete(
|
||||
path: '/article/category/{id}',
|
||||
summary: '删除内容分类',
|
||||
tags: ['article-category'],
|
||||
x: [
|
||||
SchemaConstants::X_PROPERTY_IN => 'id',
|
||||
SchemaConstants::X_SCHEMA_REQUEST => IdRequest::class,
|
||||
]
|
||||
)]
|
||||
#[Permission(code: 'article:category:delete', description: '删除内容分类')]
|
||||
#[SimpleResponse(schema: [], example: [])]
|
||||
public function destroy(Request $request): \support\Response
|
||||
{
|
||||
return parent::destroy($request);
|
||||
}
|
||||
|
||||
#[OA\Delete(
|
||||
path: '/article/category',
|
||||
summary: '批量删除内容分类',
|
||||
tags: ['article-category'],
|
||||
x: [SchemaConstants::X_SCHEMA_REQUEST => BatchDeleteRequest::class]
|
||||
)]
|
||||
#[Permission(code: 'article:category:delete', description: '批量删除内容分类')]
|
||||
#[SimpleResponse(schema: [], example: [])]
|
||||
public function batchDelete(Request $request): \support\Response
|
||||
{
|
||||
return parent::destroy($request);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,183 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace plugin\article\app\adminapi\controller;
|
||||
|
||||
use app\adminapi\controller\Crud;
|
||||
use app\adminapi\CurrentUser;
|
||||
use app\adminapi\middleware\OperationMiddleware;
|
||||
use app\adminapi\middleware\PermissionMiddleware;
|
||||
use app\schema\request\BatchDeleteRequest;
|
||||
use app\schema\request\IdRequest;
|
||||
use core\tool\Json;
|
||||
use madong\swagger\annotation\response\PageResponse;
|
||||
use madong\swagger\annotation\response\SimpleResponse;
|
||||
use madong\swagger\attribute\Permission;
|
||||
use OpenApi\Attributes as OA;
|
||||
use plugin\article\app\model\Content;
|
||||
use plugin\article\app\service\admin\ContentService;
|
||||
use plugin\article\app\validate\ContentValidate;
|
||||
use support\annotation\Middleware;
|
||||
use support\Container;
|
||||
use support\Request;
|
||||
use WebmanTech\Swagger\DTO\SchemaConstants;
|
||||
|
||||
#[Middleware(OperationMiddleware::class, PermissionMiddleware::class)]
|
||||
class ContentController extends Crud
|
||||
{
|
||||
protected CurrentUser $currentUser;
|
||||
|
||||
public function __construct(ContentService $service, ContentValidate $validate)
|
||||
{
|
||||
$this->service = $service;
|
||||
$this->validate = $validate;
|
||||
$this->currentUser = Container::make(CurrentUser::class);
|
||||
}
|
||||
|
||||
#[OA\Get(
|
||||
path: '/article/index',
|
||||
summary: '内容中心列表',
|
||||
tags: ['article-content']
|
||||
)]
|
||||
#[Permission(code: 'article:list', description: '内容中心列表')]
|
||||
#[PageResponse(schema: [], example: [])]
|
||||
public function index(Request $request): \support\Response
|
||||
{
|
||||
return parent::index($request);
|
||||
}
|
||||
|
||||
#[OA\Get(
|
||||
path: '/article/index/{id}',
|
||||
summary: '内容中心详情',
|
||||
tags: ['article-content'],
|
||||
x: [
|
||||
SchemaConstants::X_PROPERTY_IN => 'id',
|
||||
SchemaConstants::X_SCHEMA_REQUEST => IdRequest::class,
|
||||
]
|
||||
)]
|
||||
#[Permission(code: 'article:read', description: '内容中心详情')]
|
||||
#[SimpleResponse(schema: [], example: [])]
|
||||
public function show(Request $request): \support\Response
|
||||
{
|
||||
return parent::show($request);
|
||||
}
|
||||
|
||||
#[OA\Post(
|
||||
path: '/article/index',
|
||||
summary: '创建内容',
|
||||
tags: ['article-content']
|
||||
)]
|
||||
#[Permission(code: 'article:create', description: '创建内容')]
|
||||
#[SimpleResponse(schema: [], example: [])]
|
||||
public function store(Request $request): \support\Response
|
||||
{
|
||||
return parent::store($request);
|
||||
}
|
||||
|
||||
#[OA\Put(
|
||||
path: '/article/index/{id}',
|
||||
summary: '更新内容',
|
||||
tags: ['article-content'],
|
||||
x: [
|
||||
SchemaConstants::X_PROPERTY_IN => 'id',
|
||||
SchemaConstants::X_SCHEMA_REQUEST => IdRequest::class,
|
||||
]
|
||||
)]
|
||||
#[Permission(code: 'article:update', description: '更新内容')]
|
||||
#[SimpleResponse(schema: [], example: [])]
|
||||
public function update(Request $request): \support\Response
|
||||
{
|
||||
return parent::update($request);
|
||||
}
|
||||
|
||||
#[OA\Post(
|
||||
path: '/article/index/export',
|
||||
summary: '导出内容',
|
||||
tags: ['article-content']
|
||||
)]
|
||||
#[Permission(code: 'article:list', description: '导出内容')]
|
||||
#[SimpleResponse(schema: [], example: [])]
|
||||
public function export(Request $request): \support\Response
|
||||
{
|
||||
return parent::export($request);
|
||||
}
|
||||
|
||||
protected function selectInput(Request $request, ?array $config = null): array
|
||||
{
|
||||
$result = parent::selectInput($request, $config);
|
||||
if (empty($result[4])) {
|
||||
$result[4] = 'published_at desc,id desc';
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
protected function insertInput(Request $request): array
|
||||
{
|
||||
return $this->inputFilter($request->all(), ['tag_ids']);
|
||||
}
|
||||
|
||||
#[OA\Delete(
|
||||
path: '/article/index/{id}',
|
||||
summary: '删除内容',
|
||||
tags: ['article-content'],
|
||||
x: [
|
||||
SchemaConstants::X_PROPERTY_IN => 'id',
|
||||
SchemaConstants::X_SCHEMA_REQUEST => IdRequest::class,
|
||||
]
|
||||
)]
|
||||
#[Permission(code: 'article:delete', description: '删除内容')]
|
||||
#[SimpleResponse(schema: [], example: [])]
|
||||
public function destroy(Request $request): \support\Response
|
||||
{
|
||||
return $this->deleteContents($request);
|
||||
}
|
||||
|
||||
#[OA\Delete(
|
||||
path: '/article/index',
|
||||
summary: '批量删除内容',
|
||||
tags: ['article-content'],
|
||||
x: [SchemaConstants::X_SCHEMA_REQUEST => BatchDeleteRequest::class]
|
||||
)]
|
||||
#[Permission(code: 'article:delete', description: '批量删除内容')]
|
||||
#[SimpleResponse(schema: [], example: [])]
|
||||
public function batchDelete(Request $request): \support\Response
|
||||
{
|
||||
return $this->deleteContents($request);
|
||||
}
|
||||
|
||||
protected function deleteContents(Request $request): \support\Response
|
||||
{
|
||||
try {
|
||||
$ids = $this->getDeleteIds($request);
|
||||
if (empty($ids)) {
|
||||
throw new \Exception('删除参数不能为空');
|
||||
}
|
||||
|
||||
$result = $this->service->transaction(function () use ($ids) {
|
||||
$data = is_array($ids) ? $ids : explode(',', $ids);
|
||||
$deletedIds = [];
|
||||
$currentUserId = $this->currentUser->id();
|
||||
foreach ($data as $id) {
|
||||
$item = Content::query()->find($id);
|
||||
if (!$item) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($currentUserId && $item->isFillable('updated_by')) {
|
||||
$item->setAttribute('updated_by', $currentUserId);
|
||||
$item->save();
|
||||
}
|
||||
|
||||
$item->delete();
|
||||
$deletedIds[] = $item->id;
|
||||
}
|
||||
return $deletedIds;
|
||||
});
|
||||
|
||||
return Json::success('ok', $result);
|
||||
} catch (\Throwable $e) {
|
||||
return Json::fail($e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,127 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace plugin\article\app\adminapi\controller;
|
||||
|
||||
use app\adminapi\controller\Crud;
|
||||
use app\adminapi\middleware\OperationMiddleware;
|
||||
use app\adminapi\middleware\PermissionMiddleware;
|
||||
use app\schema\request\BatchDeleteRequest;
|
||||
use app\schema\request\IdRequest;
|
||||
use madong\swagger\annotation\response\PageResponse;
|
||||
use madong\swagger\annotation\response\SimpleResponse;
|
||||
use madong\swagger\attribute\Permission;
|
||||
use OpenApi\Attributes as OA;
|
||||
use plugin\article\app\service\admin\TagService;
|
||||
use plugin\article\app\validate\TagValidate;
|
||||
use support\annotation\Middleware;
|
||||
use support\Request;
|
||||
use WebmanTech\Swagger\DTO\SchemaConstants;
|
||||
|
||||
#[Middleware(OperationMiddleware::class, PermissionMiddleware::class)]
|
||||
class TagController extends Crud
|
||||
{
|
||||
public function __construct(TagService $service, TagValidate $validate)
|
||||
{
|
||||
$this->service = $service;
|
||||
$this->validate = $validate;
|
||||
}
|
||||
|
||||
#[OA\Get(
|
||||
path: '/article/tag',
|
||||
summary: '标签管理列表',
|
||||
tags: ['article-tag']
|
||||
)]
|
||||
#[Permission(code: 'article:tag:list', description: '标签管理列表')]
|
||||
#[PageResponse(schema: [], example: [])]
|
||||
public function index(Request $request): \support\Response
|
||||
{
|
||||
return parent::index($request);
|
||||
}
|
||||
|
||||
#[OA\Get(
|
||||
path: '/article/tag/{id}',
|
||||
summary: '标签详情',
|
||||
tags: ['article-tag'],
|
||||
x: [
|
||||
SchemaConstants::X_PROPERTY_IN => 'id',
|
||||
SchemaConstants::X_SCHEMA_REQUEST => IdRequest::class,
|
||||
]
|
||||
)]
|
||||
#[Permission(code: 'article:tag:read', description: '标签详情')]
|
||||
#[SimpleResponse(schema: [], example: [])]
|
||||
public function show(Request $request): \support\Response
|
||||
{
|
||||
return parent::show($request);
|
||||
}
|
||||
|
||||
#[OA\Post(
|
||||
path: '/article/tag',
|
||||
summary: '创建标签',
|
||||
tags: ['article-tag']
|
||||
)]
|
||||
#[Permission(code: 'article:tag:create', description: '创建标签')]
|
||||
#[SimpleResponse(schema: [], example: [])]
|
||||
public function store(Request $request): \support\Response
|
||||
{
|
||||
return parent::store($request);
|
||||
}
|
||||
|
||||
#[OA\Put(
|
||||
path: '/article/tag/{id}',
|
||||
summary: '更新标签',
|
||||
tags: ['article-tag'],
|
||||
x: [
|
||||
SchemaConstants::X_PROPERTY_IN => 'id',
|
||||
SchemaConstants::X_SCHEMA_REQUEST => IdRequest::class,
|
||||
]
|
||||
)]
|
||||
#[Permission(code: 'article:tag:update', description: '更新标签')]
|
||||
#[SimpleResponse(schema: [], example: [])]
|
||||
public function update(Request $request): \support\Response
|
||||
{
|
||||
return parent::update($request);
|
||||
}
|
||||
|
||||
#[OA\Post(
|
||||
path: '/article/tag/export',
|
||||
summary: '导出标签',
|
||||
tags: ['article-tag']
|
||||
)]
|
||||
#[Permission(code: 'article:tag:list', description: '导出标签')]
|
||||
#[SimpleResponse(schema: [], example: [])]
|
||||
public function export(Request $request): \support\Response
|
||||
{
|
||||
return parent::export($request);
|
||||
}
|
||||
|
||||
#[OA\Delete(
|
||||
path: '/article/tag/{id}',
|
||||
summary: '删除标签',
|
||||
tags: ['article-tag'],
|
||||
x: [
|
||||
SchemaConstants::X_PROPERTY_IN => 'id',
|
||||
SchemaConstants::X_SCHEMA_REQUEST => IdRequest::class,
|
||||
]
|
||||
)]
|
||||
#[Permission(code: 'article:tag:delete', description: '删除标签')]
|
||||
#[SimpleResponse(schema: [], example: [])]
|
||||
public function destroy(Request $request): \support\Response
|
||||
{
|
||||
return parent::destroy($request);
|
||||
}
|
||||
|
||||
#[OA\Delete(
|
||||
path: '/article/tag',
|
||||
summary: '批量删除标签',
|
||||
tags: ['article-tag'],
|
||||
x: [SchemaConstants::X_SCHEMA_REQUEST => BatchDeleteRequest::class]
|
||||
)]
|
||||
#[Permission(code: 'article:tag:delete', description: '批量删除标签')]
|
||||
#[SimpleResponse(schema: [], example: [])]
|
||||
public function batchDelete(Request $request): \support\Response
|
||||
{
|
||||
return parent::destroy($request);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace plugin\article\app\dao;
|
||||
|
||||
use core\base\BaseDao;
|
||||
use plugin\article\app\model\Category;
|
||||
|
||||
class CategoryDao extends BaseDao
|
||||
{
|
||||
protected function setModel(): string
|
||||
{
|
||||
return Category::class;
|
||||
}
|
||||
|
||||
protected function getKeywordFields(): array
|
||||
{
|
||||
return ['name', 'slug', 'description'];
|
||||
}
|
||||
|
||||
public function selectModel(
|
||||
array $where,
|
||||
array|string $field = '*',
|
||||
int $page = 0,
|
||||
int $limit = 0,
|
||||
string $order = '',
|
||||
array $with = [],
|
||||
bool $search = false,
|
||||
?array $withoutScopes = null
|
||||
): \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Query\Builder|\Illuminate\Pagination\LengthAwarePaginator|null {
|
||||
$query = parent::selectModel($where, $field, $page, $limit, $order, $with, $search, $withoutScopes);
|
||||
|
||||
if ($query instanceof \Illuminate\Database\Eloquent\Builder) {
|
||||
$query->withCount(['contents as article_count']);
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace plugin\article\app\dao;
|
||||
|
||||
use core\base\BaseDao;
|
||||
use plugin\article\app\model\Content;
|
||||
|
||||
class ContentDao extends BaseDao
|
||||
{
|
||||
protected function setModel(): string
|
||||
{
|
||||
return Content::class;
|
||||
}
|
||||
|
||||
protected function getKeywordFields(): array
|
||||
{
|
||||
return ['title', 'slug', 'summary', 'content'];
|
||||
}
|
||||
|
||||
public function get($id, ?array $field = null, ?array $with = ['category', 'tags', 'createds', 'updateds'], string $order = '', ?array $withoutScopes = null): ?\Illuminate\Database\Eloquent\Model
|
||||
{
|
||||
return parent::get($id, $field, $with, $order, $withoutScopes);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace plugin\article\app\dao;
|
||||
|
||||
use core\base\BaseDao;
|
||||
use plugin\article\app\model\Tag;
|
||||
|
||||
class TagDao extends BaseDao
|
||||
{
|
||||
protected function setModel(): string
|
||||
{
|
||||
return Tag::class;
|
||||
}
|
||||
|
||||
protected function getKeywordFields(): array
|
||||
{
|
||||
return ['name', 'slug', 'description'];
|
||||
}
|
||||
|
||||
public function selectModel(
|
||||
array $where,
|
||||
array|string $field = '*',
|
||||
int $page = 0,
|
||||
int $limit = 0,
|
||||
string $order = '',
|
||||
array $with = [],
|
||||
bool $search = false,
|
||||
?array $withoutScopes = null
|
||||
): \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Query\Builder|\Illuminate\Pagination\LengthAwarePaginator|null {
|
||||
$query = parent::selectModel($where, $field, $page, $limit, $order, $with, $search, $withoutScopes);
|
||||
|
||||
if ($query instanceof \Illuminate\Database\Eloquent\Builder) {
|
||||
$query->withCount(['contents as article_count']);
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace plugin\article\app\model;
|
||||
|
||||
use app\model\system\Admin;
|
||||
use core\base\BaseModel as CoreBaseModel;
|
||||
use Illuminate\Database\Eloquent\Relations\HasOne;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
abstract class BaseModel extends CoreBaseModel
|
||||
{
|
||||
use SoftDeletes;
|
||||
|
||||
protected $appends = ['created_date', 'updated_date', 'created_name', 'updated_name'];
|
||||
|
||||
public function createds(): HasOne
|
||||
{
|
||||
return $this->hasOne(Admin::class, 'id', 'created_by')->select('id', 'real_name as created_name');
|
||||
}
|
||||
|
||||
public function updateds(): HasOne
|
||||
{
|
||||
return $this->hasOne(Admin::class, 'id', 'updated_by')->select('id', 'real_name as updated_name');
|
||||
}
|
||||
|
||||
public function getCreatedNameAttribute(): string
|
||||
{
|
||||
return $this->createds?->created_name ?? '';
|
||||
}
|
||||
|
||||
public function getUpdatedNameAttribute(): string
|
||||
{
|
||||
return $this->updateds?->updated_name ?? '';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace plugin\article\app\model;
|
||||
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class Category extends BaseModel
|
||||
{
|
||||
protected $table = 'article_category';
|
||||
|
||||
protected $fillable = [
|
||||
'id',
|
||||
'name',
|
||||
'slug',
|
||||
'parent_id',
|
||||
'sort',
|
||||
'enabled',
|
||||
'description',
|
||||
'created_by',
|
||||
'updated_by',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
'deleted_at',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'parent_id' => 'integer',
|
||||
'sort' => 'integer',
|
||||
'enabled' => 'integer',
|
||||
'created_at' => 'integer',
|
||||
'updated_at' => 'integer',
|
||||
'deleted_at' => 'integer',
|
||||
];
|
||||
|
||||
public function contents(): HasMany
|
||||
{
|
||||
return $this->hasMany(Content::class, 'category_id', 'id');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace plugin\article\app\model;
|
||||
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
|
||||
class Content extends BaseModel
|
||||
{
|
||||
protected $table = 'article_content';
|
||||
|
||||
protected $fillable = [
|
||||
'id',
|
||||
'title',
|
||||
'content_type',
|
||||
'slug',
|
||||
'category_id',
|
||||
'channel',
|
||||
'visibility',
|
||||
'author',
|
||||
'source',
|
||||
'cover',
|
||||
'seo_keywords',
|
||||
'seo_title',
|
||||
'seo_description',
|
||||
'summary',
|
||||
'content',
|
||||
'status',
|
||||
'is_top',
|
||||
'is_recommend',
|
||||
'allow_comment',
|
||||
'sort',
|
||||
'view_count',
|
||||
'like_count',
|
||||
'comment_count',
|
||||
'favorite_count',
|
||||
'published_at',
|
||||
'offline_at',
|
||||
'created_by',
|
||||
'updated_by',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
'deleted_at',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'category_id' => 'integer',
|
||||
'visibility' => 'integer',
|
||||
'status' => 'integer',
|
||||
'is_top' => 'integer',
|
||||
'is_recommend' => 'integer',
|
||||
'allow_comment' => 'integer',
|
||||
'sort' => 'integer',
|
||||
'view_count' => 'integer',
|
||||
'like_count' => 'integer',
|
||||
'comment_count' => 'integer',
|
||||
'favorite_count' => 'integer',
|
||||
'published_at' => 'integer',
|
||||
'offline_at' => 'integer',
|
||||
'created_at' => 'integer',
|
||||
'updated_at' => 'integer',
|
||||
'deleted_at' => 'integer',
|
||||
];
|
||||
|
||||
protected $appends = ['tag_names', 'tag_ids', 'category_name', 'created_date', 'updated_date', 'created_name', 'updated_name'];
|
||||
|
||||
public function category(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Category::class, 'category_id', 'id');
|
||||
}
|
||||
|
||||
public function tags(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(Tag::class, 'article_content_tag', 'content_id', 'tag_id');
|
||||
}
|
||||
|
||||
public function getCategoryNameAttribute(): string
|
||||
{
|
||||
return $this->category?->name ?? '';
|
||||
}
|
||||
|
||||
public function getTagNamesAttribute(): string
|
||||
{
|
||||
return $this->tags->pluck('name')->implode('、');
|
||||
}
|
||||
|
||||
public function getTagIdsAttribute(): array
|
||||
{
|
||||
return $this->tags->pluck('id')->map(static fn($id) => is_numeric($id) ? (int)$id : $id)->values()->all();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace plugin\article\app\model;
|
||||
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
|
||||
class Tag extends BaseModel
|
||||
{
|
||||
protected $table = 'article_tag';
|
||||
|
||||
protected $fillable = [
|
||||
'id',
|
||||
'name',
|
||||
'slug',
|
||||
'sort',
|
||||
'heat',
|
||||
'enabled',
|
||||
'description',
|
||||
'created_by',
|
||||
'updated_by',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
'deleted_at',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'sort' => 'integer',
|
||||
'heat' => 'integer',
|
||||
'enabled' => 'integer',
|
||||
'created_at' => 'integer',
|
||||
'updated_at' => 'integer',
|
||||
'deleted_at' => 'integer',
|
||||
];
|
||||
|
||||
public function contents(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(Content::class, 'article_content_tag', 'tag_id', 'content_id');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace plugin\article\app\service\admin;
|
||||
|
||||
use core\base\BaseService;
|
||||
use plugin\article\app\dao\CategoryDao;
|
||||
|
||||
class CategoryService extends BaseService
|
||||
{
|
||||
public function __construct(CategoryDao $dao)
|
||||
{
|
||||
$this->dao = $dao;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,129 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace plugin\article\app\service\admin;
|
||||
|
||||
use core\exception\handler\AdminException;
|
||||
use madong\helper\PropertyCopier;
|
||||
use core\base\BaseService;
|
||||
use core\uuid\Snowflake;
|
||||
use Illuminate\Support\Str;
|
||||
use plugin\article\app\dao\ContentDao;
|
||||
use plugin\article\app\model\Content;
|
||||
use support\Db;
|
||||
|
||||
class ContentService extends BaseService
|
||||
{
|
||||
public function __construct(ContentDao $dao)
|
||||
{
|
||||
$this->dao = $dao;
|
||||
}
|
||||
|
||||
public function save(array $data): ?\plugin\article\app\model\Content
|
||||
{
|
||||
try {
|
||||
return $this->transaction(function () use ($data) {
|
||||
$payload = $this->normalizePayload($data);
|
||||
$tagIds = $payload['tag_ids'] ?? [];
|
||||
unset($payload['tag_ids']);
|
||||
|
||||
$model = new Content();
|
||||
PropertyCopier::copyProperties((object) $payload, $model);
|
||||
$model->save();
|
||||
|
||||
$this->syncTags($model, $tagIds);
|
||||
|
||||
return $model->refresh()?->load(['category', 'tags', 'createds', 'updateds']);
|
||||
});
|
||||
} catch (\Throwable $e) {
|
||||
throw new AdminException($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function update($id, $data): void
|
||||
{
|
||||
try {
|
||||
$this->transaction(function () use ($id, $data) {
|
||||
$model = $this->dao->get($id);
|
||||
if (!$model) {
|
||||
throw new AdminException('内容不存在');
|
||||
}
|
||||
|
||||
$payload = $this->normalizePayload($data, false);
|
||||
$tagIds = $payload['tag_ids'] ?? null;
|
||||
unset($payload['tag_ids']);
|
||||
|
||||
PropertyCopier::copyProperties((object) $payload, $model);
|
||||
$model->save();
|
||||
|
||||
if ($tagIds !== null) {
|
||||
$this->syncTags($model, $tagIds);
|
||||
}
|
||||
});
|
||||
} catch (\Throwable $e) {
|
||||
throw new AdminException($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
protected function normalizePayload(array $data, bool $isCreate = true): array
|
||||
{
|
||||
$payload = $data;
|
||||
|
||||
$payload['content_type'] = $payload['content_type'] ?? 'article';
|
||||
$payload['channel'] = $payload['channel'] ?? 'official';
|
||||
$payload['visibility'] = isset($payload['visibility']) ? (int) $payload['visibility'] : 1;
|
||||
$payload['source'] = $payload['source'] ?? 'original';
|
||||
$payload['status'] = isset($payload['status']) ? (int) $payload['status'] : 0;
|
||||
$payload['is_top'] = isset($payload['is_top']) ? (int) $payload['is_top'] : 0;
|
||||
$payload['is_recommend'] = isset($payload['is_recommend']) ? (int) $payload['is_recommend'] : 0;
|
||||
$payload['allow_comment'] = isset($payload['allow_comment']) ? (int) $payload['allow_comment'] : 1;
|
||||
$payload['sort'] = isset($payload['sort']) ? (int) $payload['sort'] : 100;
|
||||
$payload['view_count'] = isset($payload['view_count']) ? (int) $payload['view_count'] : 0;
|
||||
$payload['like_count'] = isset($payload['like_count']) ? (int) $payload['like_count'] : 0;
|
||||
$payload['comment_count'] = isset($payload['comment_count']) ? (int) $payload['comment_count'] : 0;
|
||||
$payload['favorite_count'] = isset($payload['favorite_count']) ? (int) $payload['favorite_count'] : 0;
|
||||
$payload['category_id'] = isset($payload['category_id']) ? (int) $payload['category_id'] : 0;
|
||||
|
||||
if (!empty($payload['slug'])) {
|
||||
$payload['slug'] = trim((string) $payload['slug']);
|
||||
} elseif ($isCreate && !empty($payload['title'])) {
|
||||
$payload['slug'] = Str::slug((string) $payload['title']);
|
||||
}
|
||||
|
||||
if (array_key_exists('tag_ids', $payload)) {
|
||||
$payload['tag_ids'] = collect($payload['tag_ids'] ?? [])
|
||||
->filter(static fn($id) => $id !== null && $id !== '' && $id !== 0 && $id !== '0')
|
||||
->map(static fn($id) => (int) $id)
|
||||
->unique()
|
||||
->values()
|
||||
->all();
|
||||
}
|
||||
|
||||
return $payload;
|
||||
}
|
||||
|
||||
protected function syncTags(Content $model, array $tagIds): void
|
||||
{
|
||||
$tableName = $model->tags()->getTable();
|
||||
|
||||
Db::table($tableName)->where('content_id', $model->id)->delete();
|
||||
|
||||
if (empty($tagIds)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$now = time();
|
||||
$rows = [];
|
||||
foreach ($tagIds as $tagId) {
|
||||
$rows[] = [
|
||||
'id' => (string) Snowflake::generate(),
|
||||
'content_id' => $model->id,
|
||||
'tag_id' => (int) $tagId,
|
||||
'created_at' => $now,
|
||||
];
|
||||
}
|
||||
|
||||
Db::table($tableName)->insert($rows);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace plugin\article\app\service\admin;
|
||||
|
||||
use core\base\BaseService;
|
||||
use plugin\article\app\dao\TagDao;
|
||||
|
||||
class TagService extends BaseService
|
||||
{
|
||||
public function __construct(TagDao $dao)
|
||||
{
|
||||
$this->dao = $dao;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace plugin\article\app\validate;
|
||||
|
||||
use core\base\BaseValidate;
|
||||
use Illuminate\Validation\Rule;
|
||||
use plugin\article\app\model\Category;
|
||||
|
||||
class CategoryValidate extends BaseValidate
|
||||
{
|
||||
public function rules(): array
|
||||
{
|
||||
$id = request()->route?->param('id');
|
||||
|
||||
return [
|
||||
'name' => ['required', 'max:100', Rule::unique(Category::class, 'name')->ignore($id, 'id')],
|
||||
'slug' => ['nullable', 'max:100', Rule::unique(Category::class, 'slug')->ignore($id, 'id')],
|
||||
'parent_id' => ['nullable', 'integer'],
|
||||
'sort' => ['nullable', 'integer', 'min:0'],
|
||||
'enabled' => ['nullable', 'integer', 'in:0,1'],
|
||||
'description' => ['nullable', 'max:65535'],
|
||||
];
|
||||
}
|
||||
|
||||
protected array $message = [
|
||||
'name.required' => '分类名称不能为空',
|
||||
'name.max' => '分类名称不能超过100个字符',
|
||||
'name.unique' => '分类名称已存在',
|
||||
'slug.max' => '分类标识不能超过100个字符',
|
||||
'slug.unique' => '分类标识已存在',
|
||||
'parent_id.integer' => '父级分类格式不正确',
|
||||
'sort.integer' => '排序必须为整数',
|
||||
'sort.min' => '排序不能小于0',
|
||||
'enabled.integer' => '状态格式不正确',
|
||||
'enabled.in' => '状态值不正确',
|
||||
'description.max' => '分类描述内容过长',
|
||||
];
|
||||
|
||||
protected array $scene = [
|
||||
'store' => ['name', 'slug', 'parent_id', 'sort', 'enabled', 'description'],
|
||||
'update' => ['name', 'slug', 'parent_id', 'sort', 'enabled', 'description'],
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace plugin\article\app\validate;
|
||||
|
||||
use core\base\BaseValidate;
|
||||
use Illuminate\Validation\Rule;
|
||||
use plugin\article\app\model\Content;
|
||||
|
||||
class ContentValidate extends BaseValidate
|
||||
{
|
||||
public function rules(): array
|
||||
{
|
||||
$id = request()->route?->param('id');
|
||||
|
||||
return [
|
||||
'title' => ['required', 'max:200', Rule::unique(Content::class, 'title')->ignore($id, 'id')],
|
||||
'content_type' => ['nullable', 'max:50'],
|
||||
'slug' => ['nullable', 'max:200', Rule::unique(Content::class, 'slug')->ignore($id, 'id')],
|
||||
'category_id' => ['required', 'integer'],
|
||||
'channel' => ['nullable', 'max:100'],
|
||||
'visibility' => ['nullable', 'integer', 'in:1,2,3'],
|
||||
'author' => ['nullable', 'max:100'],
|
||||
'source' => ['nullable', 'max:100'],
|
||||
'cover' => ['nullable', 'max:255'],
|
||||
'seo_keywords' => ['nullable', 'max:255'],
|
||||
'seo_title' => ['nullable', 'max:200'],
|
||||
'seo_description' => ['nullable', 'max:500'],
|
||||
'summary' => ['nullable', 'max:500'],
|
||||
'content' => ['nullable'],
|
||||
'status' => ['nullable', 'integer', 'in:0,1,2'],
|
||||
'is_top' => ['nullable', 'integer', 'in:0,1'],
|
||||
'is_recommend' => ['nullable', 'integer', 'in:0,1'],
|
||||
'allow_comment' => ['nullable', 'integer', 'in:0,1'],
|
||||
'sort' => ['nullable', 'integer', 'min:0'],
|
||||
'view_count' => ['nullable', 'integer', 'min:0'],
|
||||
'like_count' => ['nullable', 'integer', 'min:0'],
|
||||
'comment_count' => ['nullable', 'integer', 'min:0'],
|
||||
'favorite_count' => ['nullable', 'integer', 'min:0'],
|
||||
'published_at' => ['nullable', 'integer'],
|
||||
'offline_at' => ['nullable', 'integer'],
|
||||
'tag_ids' => ['nullable', 'array'],
|
||||
];
|
||||
}
|
||||
|
||||
protected array $message = [
|
||||
'title.required' => '文章标题不能为空',
|
||||
'title.max' => '文章标题不能超过200个字符',
|
||||
'title.unique' => '文章标题已存在',
|
||||
'content_type.max' => '内容类型不能超过50个字符',
|
||||
'slug.max' => '文章标识不能超过200个字符',
|
||||
'slug.unique' => '文章标识已存在',
|
||||
'category_id.required' => '请选择内容分类',
|
||||
'category_id.integer' => '内容分类格式不正确',
|
||||
'channel.max' => '所属频道不能超过100个字符',
|
||||
'visibility.integer' => '可见范围格式不正确',
|
||||
'visibility.in' => '可见范围值不正确',
|
||||
'author.max' => '作者不能超过100个字符',
|
||||
'source.max' => '内容来源不能超过100个字符',
|
||||
'cover.max' => '封面地址不能超过255个字符',
|
||||
'seo_keywords.max' => 'SEO关键词不能超过255个字符',
|
||||
'seo_title.max' => 'SEO标题不能超过200个字符',
|
||||
'seo_description.max' => 'SEO描述不能超过500个字符',
|
||||
'summary.max' => '摘要不能超过500个字符',
|
||||
'status.integer' => '状态格式不正确',
|
||||
'status.in' => '状态值不正确',
|
||||
'is_top.integer' => '置顶状态格式不正确',
|
||||
'is_top.in' => '置顶状态值不正确',
|
||||
'is_recommend.integer' => '推荐状态格式不正确',
|
||||
'is_recommend.in' => '推荐状态值不正确',
|
||||
'allow_comment.integer' => '评论设置格式不正确',
|
||||
'allow_comment.in' => '评论设置值不正确',
|
||||
'sort.integer' => '排序必须为整数',
|
||||
'sort.min' => '排序不能小于0',
|
||||
'view_count.integer' => '浏览量必须为整数',
|
||||
'view_count.min' => '浏览量不能小于0',
|
||||
'like_count.integer' => '点赞量必须为整数',
|
||||
'like_count.min' => '点赞量不能小于0',
|
||||
'comment_count.integer' => '评论量必须为整数',
|
||||
'comment_count.min' => '评论量不能小于0',
|
||||
'favorite_count.integer' => '收藏量必须为整数',
|
||||
'favorite_count.min' => '收藏量不能小于0',
|
||||
'published_at.integer' => '发布时间格式不正确',
|
||||
'offline_at.integer' => '下线时间格式不正确',
|
||||
'tag_ids.array' => '标签数据格式不正确',
|
||||
];
|
||||
|
||||
protected array $scene = [
|
||||
'store' => ['title', 'content_type', 'slug', 'category_id', 'channel', 'visibility', 'author', 'source', 'cover', 'seo_keywords', 'seo_title', 'seo_description', 'summary', 'content', 'status', 'is_top', 'is_recommend', 'allow_comment', 'sort', 'view_count', 'like_count', 'comment_count', 'favorite_count', 'published_at', 'offline_at', 'tag_ids'],
|
||||
'update' => ['title', 'content_type', 'slug', 'category_id', 'channel', 'visibility', 'author', 'source', 'cover', 'seo_keywords', 'seo_title', 'seo_description', 'summary', 'content', 'status', 'is_top', 'is_recommend', 'allow_comment', 'sort', 'view_count', 'like_count', 'comment_count', 'favorite_count', 'published_at', 'offline_at', 'tag_ids'],
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace plugin\article\app\validate;
|
||||
|
||||
use core\base\BaseValidate;
|
||||
use Illuminate\Validation\Rule;
|
||||
use plugin\article\app\model\Tag;
|
||||
|
||||
class TagValidate extends BaseValidate
|
||||
{
|
||||
public function rules(): array
|
||||
{
|
||||
$id = request()->route?->param('id');
|
||||
|
||||
return [
|
||||
'name' => ['required', 'max:100', Rule::unique(Tag::class, 'name')->ignore($id, 'id')],
|
||||
'slug' => ['nullable', 'max:100', Rule::unique(Tag::class, 'slug')->ignore($id, 'id')],
|
||||
'sort' => ['nullable', 'integer', 'min:0'],
|
||||
'heat' => ['nullable', 'integer', 'min:0'],
|
||||
'enabled' => ['nullable', 'integer', 'in:0,1'],
|
||||
'description' => ['nullable', 'max:65535'],
|
||||
];
|
||||
}
|
||||
|
||||
protected array $message = [
|
||||
'name.required' => '标签名称不能为空',
|
||||
'name.max' => '标签名称不能超过100个字符',
|
||||
'name.unique' => '标签名称已存在',
|
||||
'slug.max' => '标签标识不能超过100个字符',
|
||||
'slug.unique' => '标签标识已存在',
|
||||
'sort.integer' => '排序必须为整数',
|
||||
'sort.min' => '排序不能小于0',
|
||||
'heat.integer' => '热度必须为整数',
|
||||
'heat.min' => '热度不能小于0',
|
||||
'enabled.integer' => '状态格式不正确',
|
||||
'enabled.in' => '状态值不正确',
|
||||
'description.max' => '标签描述内容过长',
|
||||
];
|
||||
|
||||
protected array $scene = [
|
||||
'store' => ['name', 'slug', 'sort', 'heat', 'enabled', 'description'],
|
||||
'update' => ['name', 'slug', 'sort', 'heat', 'enabled', 'description'],
|
||||
];
|
||||
}
|
||||
Reference in New Issue
Block a user