Files
orico-official-website/app/index/controller/Attachment.php
2025-04-16 14:07:33 +08:00

133 lines
3.5 KiB
PHP

<?php
declare (strict_types = 1);
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;
/**
* 附件控制器
*/
class Attachment extends Common
{
/**
* 分页列表
*/
public function index()
{
$param = request()->param([
'id',
'keyword',
'page/d' => 1,
'size/d' => 12,
]);
// 获取附件分类
$categorys = AttachmentCategoryModel::field([
'id',
'name'
])
->language($this->lang_id)
->parent(0)
->isShow(true)
->order(['sort' => 'asc', 'id' => 'desc'])
->select();
View::assign('categorys', $categorys);
// 获取附件
$attachements = AttachmentModel::field([
'id',
'name',
'desc',
'image',
'applicable_to',
'support_platform',
'attach',
])
->withSearch(['name'], ['name' => $param['keyword']??null])
->language($this->lang_id)
->category($param['id']??null)
->order(['sort' => 'asc', 'id' => 'desc'])
->paginate([
'list_rows' => $param['size'],
'page' => $param['page'],
'query' => [
'id' => $param['id']??null
]
]);
View::assign('attachements', $attachements);
View::assign('page', $attachements->render());
return View::fetch('index');
}
/**
* 视频
*/
public function video()
{
$param = request()->param([
'id',
'keyword',
'page/d' => 1,
'size/d' => 12
]);
// 获取附件分类
$attachment_categorys = AttachmentCategoryModel::field([
'id',
'name'
])
->language($this->lang_id)
->parent(0)
->isShow(true)
->order(['sort' => 'asc', 'id' => 'desc'])
->select();
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'
])
->withSearch(['name'], ['name' => $param['keyword']??null])
->language($this->lang_id)
->category($param['id']??null)
->order(['sort' => 'asc', 'id' => 'desc'])
->paginate([
'list_rows' => $param['size'],
'page' => $param['page'],
'query' => [
'id' => $param['id']??null
]
]);
if (!$videos->isEmpty()) {
$videos->setCollection($videos->getCollection()->chunk(2));
}
View::assign('videos', $videos);
View::assign('page', $videos->render());
return View::fetch('video');
}
}