|
@@ -4,6 +4,9 @@ namespace app\admin\logic;
|
|
|
|
|
|
use app\model\CommonModel;
|
|
|
use app\model\VideoGroupModel;
|
|
|
+use think\Exception;
|
|
|
+use think\exception\ValidateException;
|
|
|
+use think\facade\Db;
|
|
|
use think\response\Json;
|
|
|
|
|
|
class VideoGroupLogic extends BaseLogic
|
|
@@ -25,7 +28,7 @@ class VideoGroupLogic extends BaseLogic
|
|
|
|
|
|
$list = $db->field('a.id,b.title company_title,c.title card_title,a.num,a.status,a.addtime,a.is_top')
|
|
|
->page($data['page'], $data['size'])
|
|
|
- ->order(['a.addtime' => 'desc'])
|
|
|
+ ->order(['a.is_top' => 'desc', 'a.id' => 'desc'])
|
|
|
->select()
|
|
|
->toArray();
|
|
|
|
|
@@ -35,32 +38,192 @@ class VideoGroupLogic extends BaseLogic
|
|
|
//添加视频分组
|
|
|
public static function add(array $data = []): Json
|
|
|
{
|
|
|
- return json_show(CommonModel::$success, '');
|
|
|
+ Db::startTrans();
|
|
|
+ try {
|
|
|
+
|
|
|
+ $rs = VideoGroupModel::field('id')
|
|
|
+ ->where([
|
|
|
+ 'is_del' => CommonModel::$del_normal,
|
|
|
+ 'company_id' => $data['company_id'],
|
|
|
+ 'card_id' => $data['card_id']
|
|
|
+ ])
|
|
|
+ ->findOrEmpty()
|
|
|
+ ->isEmpty();
|
|
|
+ if (!$rs) throw new Exception('该分组已存在');
|
|
|
+
|
|
|
+ $date = date('Y-m-d H:i:s');
|
|
|
+
|
|
|
+ $video_group_id = Db::name('video_group')
|
|
|
+ ->strict(false)
|
|
|
+ ->insertGetId(array_merge($data, [
|
|
|
+ 'num' => count($data['video_list']),
|
|
|
+ 'is_top' => CommonModel::$top_no,
|
|
|
+ 'status' => CommonModel::$status_normal,
|
|
|
+ 'is_del' => CommonModel::$del_normal,
|
|
|
+ 'createrid' => self::$uid,
|
|
|
+ 'creater' => self::$uname,
|
|
|
+ 'addtime' => $date,
|
|
|
+ 'updaterid' => self::$uid,
|
|
|
+ 'updater' => self::$uname,
|
|
|
+ 'updatetime' => $date,
|
|
|
+ ]));
|
|
|
+
|
|
|
+ $da = [];
|
|
|
+ foreach ($data['video_list'] as $item) {
|
|
|
+ $da[] = [
|
|
|
+ 'video_group_id' => $video_group_id,
|
|
|
+ 'video_id' => $item['video_id'],
|
|
|
+ 'is_top' => $item['is_top'],
|
|
|
+ 'is_del' => CommonModel::$del_normal,
|
|
|
+ 'addtime' => $date,
|
|
|
+ 'updatetime' => $date,
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
+ Db::name('video_group_item')->insertAll($da);
|
|
|
+
|
|
|
+ Db::commit();
|
|
|
+
|
|
|
+ return json_show(CommonModel::$success, '添加视频分组成功');
|
|
|
+
|
|
|
+ } catch (Exception $exception) {
|
|
|
+ Db::rollback();
|
|
|
+ return json_show(CommonModel::$error_param, '添加视频分组失败,' . $exception->getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
//获取视频分组详情
|
|
|
- public static function read(array $data = []): Json
|
|
|
+ public static function read(int $id = 0): Json
|
|
|
{
|
|
|
- return json_show(CommonModel::$success, '');
|
|
|
+ $res = VideoGroupModel::field(true)
|
|
|
+ ->where(['id' => $id, 'is_del' => CommonModel::$del_normal])
|
|
|
+ ->findOrEmpty()
|
|
|
+ ->toArray();
|
|
|
+
|
|
|
+ if (empty($res)) throw new ValidateException('该视频分组为空');
|
|
|
+
|
|
|
+ $res['child'] = Db::name('video_group_item')
|
|
|
+ ->field(true)
|
|
|
+ ->where(['is_del' => CommonModel::$del_normal, 'video_group_id' => $id])
|
|
|
+ ->order(['is_top' => 'desc', 'id' => 'desc'])
|
|
|
+ ->select()
|
|
|
+ ->toArray();
|
|
|
+
|
|
|
+ return json_show(CommonModel::$success, '获取视频分组详情成功', $res);
|
|
|
}
|
|
|
|
|
|
//编辑视频分组
|
|
|
public static function edit(array $data = []): Json
|
|
|
{
|
|
|
- return json_show(CommonModel::$success, '');
|
|
|
+ Db::startTrans();
|
|
|
+ try {
|
|
|
+
|
|
|
+ $rs = VideoGroupModel::field('id,company_id,card_id')
|
|
|
+ ->where([
|
|
|
+ 'is_del' => CommonModel::$del_normal,
|
|
|
+ 'id' => $data['id']
|
|
|
+ ])
|
|
|
+ ->findOrEmpty();
|
|
|
+ if ($rs->isEmpty()) throw new Exception('该视频分组不存在');
|
|
|
+
|
|
|
+ if (($rs->company_id != $data['company_id']) || ($rs->card_id != $data['card_id'])) {
|
|
|
+
|
|
|
+ $temp = VideoGroupModel::field('id')
|
|
|
+ ->where([
|
|
|
+ 'is_del' => CommonModel::$del_normal,
|
|
|
+ 'company_id' => $data['company_id'],
|
|
|
+ 'card_id' => $data['card_id']
|
|
|
+ ])
|
|
|
+ ->findOrEmpty()
|
|
|
+ ->isEmpty();
|
|
|
+ if (!$temp) throw new Exception('该分组已存在');
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ $date = date('Y-m-d H:i:s');
|
|
|
+
|
|
|
+ VideoGroupModel::where(['id' => $data['id'], 'is_del' => CommonModel::$del_normal])
|
|
|
+ ->strict(false)
|
|
|
+ ->save(array_merge($data, ['updatetime' => $date]));
|
|
|
+
|
|
|
+ $del = $ins = [];
|
|
|
+
|
|
|
+ foreach ($data['video_list'] as $item) {
|
|
|
+ if (isset($item['id']) && $item['id'] != 0) {
|
|
|
+ if ($item['is_del'] == CommonModel::$del_deleted) $del[] = $item['id'];
|
|
|
+ else Db::name('video_group_item')->where('is_del', CommonModel::$del_normal)->where('id', $item['id'])->save($item);
|
|
|
+ } else $ins[] = [
|
|
|
+ 'video_group_id' => $data['id'],
|
|
|
+ 'video_id' => $item['video_id'],
|
|
|
+ 'is_top' => $item['is_top'],
|
|
|
+ 'is_del' => CommonModel::$del_normal,
|
|
|
+ 'addtime' => $date,
|
|
|
+ 'updatetime' => $date,
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($del) Db::name('video_group_item')
|
|
|
+ ->whereIn('id', $del)
|
|
|
+ ->where('is_del', CommonModel::$del_normal)
|
|
|
+ ->update([
|
|
|
+ 'is_del' => CommonModel::$del_deleted,
|
|
|
+ 'updatetime' => $date,
|
|
|
+ ]);
|
|
|
+
|
|
|
+ if ($ins) Db::name('video_group_item')->insertAll($ins);
|
|
|
+
|
|
|
+ Db::commit();
|
|
|
+
|
|
|
+ return json_show(CommonModel::$success, '编辑视频分组成功');
|
|
|
+
|
|
|
+ } catch (Exception $exception) {
|
|
|
+ Db::rollback();
|
|
|
+ return json_show(CommonModel::$error_param, '编辑视频分组失败,' . $exception->getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
//视频分组启禁用
|
|
|
public static function status(array $data = []): Json
|
|
|
{
|
|
|
- return json_show(CommonModel::$success, '');
|
|
|
+ $res = VideoGroupModel::where('id', $data['id'])
|
|
|
+ ->where('status', '<>', $data['status'])
|
|
|
+ ->save([
|
|
|
+ 'status' => $data['status'],
|
|
|
+ 'updatetime' => date('Y-m-d H:i:s'),
|
|
|
+ ]);
|
|
|
+
|
|
|
+ return $res ? json_show(CommonModel::$success, '操作成功') : json_show(CommonModel::$success, '操作失败');
|
|
|
+
|
|
|
}
|
|
|
|
|
|
//删除视频分组
|
|
|
- public static function delete(array $data = []): Json
|
|
|
+ public static function delete(int $id = 0): Json
|
|
|
{
|
|
|
- return json_show(CommonModel::$success, '');
|
|
|
+ $res = VideoGroupModel::where('id', $id)
|
|
|
+ ->where('is_del', CommonModel::$del_normal)
|
|
|
+ ->save([
|
|
|
+ 'is_del' => CommonModel::$del_deleted,
|
|
|
+ 'updatetime' => date('Y-m-d H:i:s'),
|
|
|
+ ]);
|
|
|
+
|
|
|
+ return $res ? json_show(CommonModel::$success, '删除成功') : json_show(CommonModel::$success, '删除失败');
|
|
|
+
|
|
|
}
|
|
|
|
|
|
+ //视频分组置顶
|
|
|
+ public static function top(array $data = []): Json
|
|
|
+ {
|
|
|
+ $res = VideoGroupModel::where('id', $data['id'])
|
|
|
+ ->where('is_top', '<>', $data['is_top'])
|
|
|
+ ->save([
|
|
|
+ 'is_top' => $data['is_top'],
|
|
|
+ 'updatetime' => date('Y-m-d H:i:s'),
|
|
|
+ ]);
|
|
|
+
|
|
|
+ return $res ? json_show(CommonModel::$success, '操作成功') : json_show(CommonModel::$success, '操作失败');
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
}
|