site_api/app/admin/controller/Home/HomeVideo/HomeVideo.php
2024-05-02 21:48:35 +08:00

108 lines
3.2 KiB
PHP

<?php
namespace app\admin\controller\Home\HomeVideo;
use app\BaseController;
use app\common\model\Home\HomeVideo\HomeVideo as ModelHomeVideo;
use app\Request;
use think\Validate;
use think\exception\ValidateException;
use think\facade\Filesystem;
use app\common\arw\adjfut\src\Excel;
use app\common\arw\adjfut\src\UploadFile;
use app\common\exception\Tool;
use think\facade\Db;
use think\facade\Env;
class HomeVideo extends BaseController
{
/**
* 获取首页视频列表
*/
public function getHomeVideoList(Request $request, $isExport = false): array
{
$params = $request->param();
$con = [];
$con = Tool::getOptionalQuery(['i18n_lang_type_guid', '='],);
$query = ModelHomeVideo::where($con)
->alias('a')
->leftjoin('i18n_lang_type c', 'a.i18n_lang_type_guid = c.i18n_lang_type_guid')
->field([
'a.home_video_id',
'a.home_video_guid',
'c.i18n_lang_type_code',
'a.i18n_lang_type_guid',
'a.home_video_cover',
'a.home_video_url'
])
->order('home_video_create_time', 'desc');
return $isExport ? $query->select()->toArray() : msg("获取首页视频列表成功!", $query);
}
/**
* 添加首页视频
*/
public function addHomeVideo(Request $request): array
{
$params = $request->param();
$this->validate($params, [
'i18n_lang_type_guid|语言类型guid' => 'require',
'home_video_url|视频' => 'require'
]);
$model = ModelHomeVideo::where('i18n_lang_type_guid', $params['i18n_lang_type_guid'])->find();
if ($model) throwErrorMsg("视频同语言只能添加一条", 1);
$model = ModelHomeVideo::create($params, [
'i18n_lang_type_guid',
'home_video_url',
'home_video_cover',
'home_video_guid',
'home_video_create_user_guid',
'home_video_update_user_guid'
]);
return msg('添加成功!');
}
/**
* 编辑首页视频
*/
public function editHomeVideo(Request $request): array
{
$params = $request->param();
$this->validate($params, [
'i18n_lang_type_guid|语言类型guid' => 'require',
'home_video_url|视频' => 'require'
]);
$model = ModelHomeVideo::where('home_video_guid', $params['home_video_guid'])->find();
if (!$model) throwErrorMsg("该首页视频不存在", 1);
$model->allowField([
'i18n_lang_type_guid',
'home_video_cover',
'home_video_url',
'home_video_update_user_guid'
])->save($params);
return msg('编辑成功!');
}
/**
* 删除首页视频
*/
public function deleteHomeVideo(Request $request): array
{
$params = $request->param();
$this->validate($params, [
'home_video_guid' => 'require',
]);
$home_video = ModelHomeVideo::where([
'home_video_guid' => explode(',', $params['home_video_guid'])
])->select();
$home_video->delete();
return msg('删除成功!');
}
}