feat: 添加新增/更新/设置排序值/删除接口
This commit is contained in:
@@ -5,6 +5,7 @@ declare(strict_types=1);
|
||||
namespace app\admin\controller\v1;
|
||||
|
||||
use app\admin\model\v1\VideoModel;
|
||||
use app\admin\validate\v1\VideoValidate;
|
||||
|
||||
/**
|
||||
* 视频管理控制器
|
||||
@@ -69,4 +70,123 @@ class Video
|
||||
|
||||
return success('获取成功', $video);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加视频信息
|
||||
*/
|
||||
public function save()
|
||||
{
|
||||
$post = request()->post([
|
||||
'name',
|
||||
'category_id',
|
||||
'sort',
|
||||
'recommend',
|
||||
'desc',
|
||||
'image',
|
||||
'video',
|
||||
'link',
|
||||
'status' => 1,
|
||||
'seo_title',
|
||||
'seo_keywords',
|
||||
'seo_desc'
|
||||
]);
|
||||
$data = array_merge($post, ['language_id' => request()->lang_id]);
|
||||
|
||||
$validate = new VideoValidate;
|
||||
if (!$validate->scene('create')->check($data)) {
|
||||
return error($validate->getError());
|
||||
}
|
||||
|
||||
$video = VideoModel::create($data);
|
||||
if ($video->isEmpty()) {
|
||||
return error('操作失败');
|
||||
}
|
||||
|
||||
return success('操作成功');
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新视频信息
|
||||
*/
|
||||
public function update()
|
||||
{
|
||||
$id = request()->param('id');
|
||||
$put = request()->put([
|
||||
'name',
|
||||
'category_id',
|
||||
'sort',
|
||||
'recommend',
|
||||
'desc',
|
||||
'image',
|
||||
'video',
|
||||
'link',
|
||||
'status' => 1,
|
||||
'seo_title',
|
||||
'seo_keywords',
|
||||
'seo_desc'
|
||||
]);
|
||||
|
||||
$validate = new VideoValidate;
|
||||
if (!$validate->scene('update')->check(array_merge($put, ['id' => $id]))) {
|
||||
return error($validate->getError());
|
||||
}
|
||||
|
||||
$video = VideoModel::bypk($id)->find();
|
||||
if (empty($video)) {
|
||||
return error('请确认操作对象是不是存在');
|
||||
}
|
||||
|
||||
if (!$video->save($put)) {
|
||||
return error('操作失败');
|
||||
}
|
||||
return success('操作成功');
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置排序值
|
||||
*/
|
||||
public function sort()
|
||||
{
|
||||
$id = request()->param('id');
|
||||
$sort = request()->post('sort');
|
||||
|
||||
$validate = new VideoValidate;
|
||||
if (!$validate->scene('sort')->check(['id' => $id, 'sort' => $sort])) {
|
||||
return error($validate->getError());
|
||||
}
|
||||
|
||||
$video = VideoModel::bypk($id)->find();
|
||||
if (empty($video)) {
|
||||
return error('请确认操作对象是不是存在');
|
||||
}
|
||||
|
||||
$video->sort = $sort;
|
||||
if (!$video->save()) {
|
||||
return error('操作失败');
|
||||
}
|
||||
return success('操作成功');
|
||||
}
|
||||
|
||||
/**
|
||||
* 视频信息删除
|
||||
*/
|
||||
public function delete()
|
||||
{
|
||||
$id = request()->param('id');
|
||||
|
||||
$validate = new VideoValidate;
|
||||
if (!$validate->scene('delete')->check(['id' => $id])) {
|
||||
return error($validate->getError());
|
||||
}
|
||||
|
||||
$video = VideoModel::bypk($id)->find();
|
||||
if (empty($video)) {
|
||||
return error('请确认操作对象是不存在');
|
||||
}
|
||||
|
||||
if (!$video->delete()) {
|
||||
return error('操作失败');
|
||||
}
|
||||
return success('操作成功');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user