From 173b90a7f6a42806c2b6c549ce4c53260aebfebb Mon Sep 17 00:00:00 2001 From: jsasg <735273025@qq.com> Date: Wed, 19 Feb 2025 18:01:09 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E8=A7=86=E9=A2=91?= =?UTF-8?q?=E5=88=86=E9=A1=B5/=E8=AF=A6=E6=83=85=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/admin/controller/v1/Video.php | 64 ++++++++++++++++++- app/admin/model/v1/VideoCategoryModel.php | 15 +++++ app/admin/model/v1/VideoModel.php | 52 +++++++++++++++ app/admin/route/v1.php | 15 +++++ app/common/model/VideoBaseModel.php | 39 +++++++++++ app/common/model/VideoCategoryBaseModel.php | 29 +++++++++ .../20241220072926_create_video.php | 3 + .../20241220073105_create_video_category.php | 2 + 8 files changed, 217 insertions(+), 2 deletions(-) create mode 100644 app/admin/model/v1/VideoCategoryModel.php create mode 100644 app/admin/model/v1/VideoModel.php create mode 100644 app/common/model/VideoBaseModel.php create mode 100644 app/common/model/VideoCategoryBaseModel.php diff --git a/app/admin/controller/v1/Video.php b/app/admin/controller/v1/Video.php index 9bebe770..7fccf10e 100644 --- a/app/admin/controller/v1/Video.php +++ b/app/admin/controller/v1/Video.php @@ -1,12 +1,72 @@ param([ + 'name', + 'category_id', + 'page/d' => 1, + 'size/d' => 10 + ]); + + $videos = VideoModel::field([ + 'id', + 'image', + 'name', + 'category_id', + 'sort', + 'recommend', + 'status', + 'created_at' + ]) + ->with(['category' => function ($query) { + $query->field(['id', 'name']); + }]) + ->withSearch(['name', 'created_at'], [ + 'name' => $params['name'] ?? null, + 'created_at' => !empty($params['created_at']) ? explode(",", $params['created_at']) : null + ]) + ->categoryId($params['category_id'] ?? null) + ->order(['sort' => 'desc', 'id' => 'desc']) + ->paginate([ + 'list_rows' => $params['size'], + 'page' => $params['page'], + ]) + ->hidden(['category', 'category_id']); + + return success('获取成功', $videos); + } + + /** + * 视频信息详情 + */ + public function read() + { + $video = VideoModel::withoutField([ + 'created_at', + 'updated_at', + 'deleted_at' + ]) + ->bypk(request()->param('id')) + ->find(); + if (empty($video)) { + return error('视频不存在'); + } + + return success('获取成功', $video); + } } diff --git a/app/admin/model/v1/VideoCategoryModel.php b/app/admin/model/v1/VideoCategoryModel.php new file mode 100644 index 00000000..e18ef866 --- /dev/null +++ b/app/admin/model/v1/VideoCategoryModel.php @@ -0,0 +1,15 @@ +belongsTo(VideoCategoryModel::class, 'category_id', 'id'); + } + + // 名称搜索器 + public function searchNameAttr($query, $value, $data) + { + if (empty($value)) { + return; + } + $query->where('name', 'like', '%' . $value . '%'); + } + + // 搜索发布时间 + public function searchCreatedAtAttr($query, $value, $data) + { + if (empty($value)) { + return; + } + if (is_array($value)) { + if (count($value) == 2) { + $query->whereBetweenTime('created_at', $value[0], $value[1]); + } else { + $query->whereTime('created_at', '>=', $value[0]); + } + } + } + + // 分类查询 + public function scopeCategoryId($query, $value) + { + if (empty($value)) { + return; + } + $query->where('category_id', '=', $value); + } +} diff --git a/app/admin/route/v1.php b/app/admin/route/v1.php index 46c5fb57..de7cf779 100644 --- a/app/admin/route/v1.php +++ b/app/admin/route/v1.php @@ -45,6 +45,21 @@ Route::group('v1', function () { Route::group('video', function () { // 视频上传 Route::post('/:module/upload', 'Upload/video'); + + // 视频信息列表 + Route::get('index', 'Video/index'); + + // 视频信息详情 + Route::get('read/:id', 'Video/read'); + + // 视频信息添加 + Route::post('save', 'Video/save'); + + // 视频信息更新 + Route::put('update/:id', 'Video/update'); + + // 视频信息删除 + Route::delete('delete/:id', 'Video/delete'); }); // 文章模块 diff --git a/app/common/model/VideoBaseModel.php b/app/common/model/VideoBaseModel.php new file mode 100644 index 00000000..138a99a6 --- /dev/null +++ b/app/common/model/VideoBaseModel.php @@ -0,0 +1,39 @@ + 'int', + 'language_id' => 'int', + 'category_id' => 'int', + 'name' => 'string', + 'desc' => 'string', + 'image' => 'string', + 'video' => 'string', + 'link' => 'string', + 'sort' => 'int', + 'recommend' => 'int', + 'status' => 'int', + 'seo_title' => 'string', + 'seo_keywords' => 'string', + 'seo_desc' => 'string', + 'created_at' => 'datetime', + 'updated_at' => 'datetime', + 'deleted_at' => 'datetime' + ]; +} diff --git a/app/common/model/VideoCategoryBaseModel.php b/app/common/model/VideoCategoryBaseModel.php new file mode 100644 index 00000000..c7ae635b --- /dev/null +++ b/app/common/model/VideoCategoryBaseModel.php @@ -0,0 +1,29 @@ + 'int', + 'language_id' => 'int', + 'name' => 'string', + 'sort' => 'int', + 'is_show' => 'int', + 'created_at' => 'datetime', + 'updated_at' => 'datetime', + ]; +} diff --git a/database/migrations/20241220072926_create_video.php b/database/migrations/20241220072926_create_video.php index 4e3e8f26..042ba8c0 100644 --- a/database/migrations/20241220072926_create_video.php +++ b/database/migrations/20241220072926_create_video.php @@ -1,5 +1,6 @@ addColumn('link', 'string', ['limit' => 125, 'null' => true, 'default' => null, 'comment' => '外链地址']) ->addColumn('sort', 'integer', ['null' => false, 'default' => 0, 'comment' => '排序']) ->addColumn('recommend', 'boolean', ['null' => false, 'default' => 1, 'comment' => '是否推荐:1是,0否']) + ->addColumn('status', MysqlAdapter::INT_TINY, ['null' => false, 'default' => 1, 'comment' => '状态:1启用,-1禁用']) ->addColumn('seo_title', 'string', ['limit' => 255, 'default' => null, 'comment' => 'SEO标题']) ->addColumn('seo_keywords', 'string', ['limit' => 255, 'default' => null, 'comment' => 'SEO关键字']) ->addColumn('seo_desc', 'string', ['limit' => 255, 'default' => null, 'comment' => 'SEO描述']) ->addColumn('created_at', 'timestamp', ['null' => false, 'default' => 'CURRENT_TIMESTAMP', 'comment' => '创建时间']) + ->addColumn('updated_at', 'timestamp', ['null' => false, 'default' => 'CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP', 'comment' => '更新时间']) ->addColumn('deleted_at', 'timestamp', ['null' => true, 'comment' => '删除时间']) ->create(); } diff --git a/database/migrations/20241220073105_create_video_category.php b/database/migrations/20241220073105_create_video_category.php index 7f1f4a73..65049a63 100644 --- a/database/migrations/20241220073105_create_video_category.php +++ b/database/migrations/20241220073105_create_video_category.php @@ -32,6 +32,8 @@ class CreateVideoCategory extends Migrator ->addColumn('name', 'string', ['limit' => 64 , 'null' => false, 'comment' => '分类名称']) ->addColumn('sort', 'integer', ['null' => false, 'default' => 0, 'comment' => '排序']) ->addColumn('is_show', 'boolean', ['null' => false, 'default' => 1, 'comment' => '是否显示:1是,0否']) + ->addColumn('created_at', 'timestamp', ['null' => false, 'default' => 'CURRENT_TIMESTAMP', 'comment' => '创建时间']) + ->addColumn('updated_at', 'timestamp', ['null' => false, 'default' => 'CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP', 'comment' => '更新时间']) ->create(); } }