From f582a304789d1b2bd5b23088cc7a1ebf69dae955 Mon Sep 17 00:00:00 2001 From: jsasg <735273025@qq.com> Date: Tue, 15 Apr 2025 18:07:42 +0800 Subject: [PATCH] =?UTF-8?q?refacotr:=20=E8=A7=86=E9=A2=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/index/controller/Attachment.php | 41 ++++++++++++++++++++- app/index/model/VideoCategoryModel.php | 23 ++++++++++-- app/index/model/VideoModel.php | 22 ++++++++++- app/index/view/attachment/video.html | 51 +++++++++----------------- 4 files changed, 97 insertions(+), 40 deletions(-) diff --git a/app/index/controller/Attachment.php b/app/index/controller/Attachment.php index 219a5983..91309b0a 100644 --- a/app/index/controller/Attachment.php +++ b/app/index/controller/Attachment.php @@ -5,6 +5,8 @@ namespace app\index\controller; use app\index\model\AttachmentCategoryModel; use app\index\model\AttachmentModel; +use app\index\model\VideoCategoryModel; +use app\index\model\VideoModel; use think\facade\View; /** @@ -63,16 +65,51 @@ class Attachment extends Common */ public function video() { + $param = request()->param([ + 'page/d' => 1, + 'size/d' => 12 + ]); + // 获取附件分类 - $categorys = AttachmentCategoryModel::field([ + $attachment_categorys = AttachmentCategoryModel::field([ 'id', 'name' ]) ->language($this->lang_id) ->parent(0) ->isShow(true) + ->order(['sort' => 'asc', 'id' => 'desc']) ->select(); - View::assign('categorys', $categorys); + View::assign('attachment_categorys', $attachment_categorys); + + // 获取视频分类 + $video_categorys = VideoCategoryModel::field([ + 'id', + 'name' + ]) + ->language($this->lang_id) + ->isShow(true) + ->order(['sort' => 'asc', 'id' => 'desc']) + ->select(); + View::assign('video_categorys', $video_categorys); + + // 获取视频 + $videos = VideoModel::field([ + 'id', + 'name', + 'desc', + 'image', + 'video', + 'link' + ]) + ->language($this->lang_id) + ->order(['sort' => 'asc', 'id' => 'desc']) + ->paginate([ + 'list_rows' => $param['size'], + 'page' => $param['page'], + ]); + View::assign('videos', $videos); + View::assign('page', $videos->render()); return View::fetch('video'); } diff --git a/app/index/model/VideoCategoryModel.php b/app/index/model/VideoCategoryModel.php index 78a4b038..70a08cc0 100644 --- a/app/index/model/VideoCategoryModel.php +++ b/app/index/model/VideoCategoryModel.php @@ -3,12 +3,29 @@ declare (strict_types = 1); namespace app\index\model; -use think\Model; +use app\common\model\VideoCategoryBaseModel; +use think\model\concern\SoftDelete; /** + * 视频分类模型 * @mixin \think\Model */ -class VideoCategoryModel extends Model +class VideoCategoryModel extends VideoCategoryBaseModel { - // + // 启用软删除 + use SoftDelete; + // 软删除字段 + protected $deleteTime = 'deleted_at'; + + // 所属语言范围查询 + public function scopeLanguage($query, $language) + { + $query->where('language_id', '=', $language); + } + + // 是否显示状态范围查询 + public function scopeIsShow($query, bool $is_show) + { + $query->where('is_show', '=', (int)$is_show); + } } diff --git a/app/index/model/VideoModel.php b/app/index/model/VideoModel.php index 3062f5db..dce62a1f 100644 --- a/app/index/model/VideoModel.php +++ b/app/index/model/VideoModel.php @@ -3,12 +3,30 @@ declare (strict_types = 1); namespace app\index\model; +use app\common\model\VideoBaseModel; use think\Model; +use think\model\concern\SoftDelete; /** + * 视频模型 * @mixin \think\Model */ -class VideoModel extends Model +class VideoModel extends VideoBaseModel { - // + // 启用软删除 + use SoftDelete; + // 软删除字段 + protected $deleteTime = 'deleted_at'; + + // 所属语言范围查询 + public function scopeLanguage($query, $language) + { + $query->where('language_id', '=', $language); + } + + // 推荐状态范围查询 + public function scopeRecommend($query, bool $recommend) + { + $query->where('recommend', '=', (int)$recommend); + } } diff --git a/app/index/view/attachment/video.html b/app/index/view/attachment/video.html index e3754999..05ff143d 100644 --- a/app/index/view/attachment/video.html +++ b/app/index/view/attachment/video.html @@ -20,8 +20,8 @@
- {notempty name="categorys"} - {volist name="categorys" id="ca"} + {notempty name="attachment_categorys"} + {volist name="attachment_categorys" id="ca"}
{$ca.name} @@ -33,57 +33,42 @@
+ {notempty name="video_categorys"} + {/notempty} + {notempty name="videos"}
    + {volist name="videos" id="vo"}
    -
    -
    ORICO RP1 Headphones
    -
    ORICO RP1 in-ear music headphones, skin-friendly and - comfortable for long time wearing; black, white, red and blue, four - colors for you to choose. ORICO 2169U3 full mesh 2.5 inch hard drive - enclosure, all-round heat-dissipation; compatible with SATA HDD below - 9.5mm.
    -
    -
    -
    -
    - -
    -
    -
    ORICO BS16 Bluetooth Speaker
    -
    ORICO BS16 unique and delicate pocket Bluetooth speaker, - bring you beautiful music; smaller size, unprecedented endurance. ORICO - 2169U3 full mesh 2.5 inch hard drive enclosure, all-round - heat-dissipation; compatible with SATA HDD below 9.5mm.
    +
    {$vo.name}
    +
    {$vo.desc}
    + {/volist}
    -
    - - -
    +
    {$page|raw}
+ {/notempty}
-