123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160 |
- <?php
- namespace app\admin\logic;
- use app\model\CommonModel;
- use app\model\VideoGroupModel;
- use think\exception\ValidateException;
- use think\response\Json;
- class VideoGroupLogic extends BaseLogic
- {
- //获取视频分组列表
- public static function list(array $data = []): Json
- {
- $db = VideoGroupModel::alias('a')
- ->leftJoin('company b', 'b.id=a.company_id')
- ->leftJoin('card c', 'c.id=a.card_id')
- ->where('a.is_del', CommonModel::$del_normal);
- if ($data['status'] != '') $db->where('a.status', $data['status']);
- if ($data['company_title'] != '') $db->whereLike('b.title', '%' . $data['company_title'] . '%');
- if ($data['card_title'] != '') $db->whereLike('c.title', '%' . $data['card_title'] . '%');
- $count = $db->count('a.id');
- $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.is_top' => 'desc', 'a.id' => 'desc'])
- ->select()
- ->toArray();
- return json_show(CommonModel::$success, '获取视频分组列表成功', ['count' => $count, 'list' => $list]);
- }
- //添加视频分组
- public static function add(array $data = []): Json
- {
- $rs = VideoGroupModel::field('id')
- ->where([
- 'is_del' => CommonModel::$del_normal,
- 'company_id' => $data['company_id'],
- 'card_id' => $data['card_id']
- ])
- ->findOrEmpty()
- ->isEmpty();
- if (!$rs) return json_show(CommonModel::$error_param, '该分组已存在');
- $res = VideoGroupModel::create(array_merge($data, [
- 'num' => 0,
- 'is_top' => CommonModel::$top_no,
- 'status' => CommonModel::$status_normal,
- 'is_del' => CommonModel::$del_normal,
- 'createrid' => self::$uid,
- 'creater' => self::$uname,
- 'addtime' => date('Y-m-d H:i:s'),
- 'updaterid' => self::$uid,
- 'updater' => self::$uname,
- 'updatetime' => date('Y-m-d H:i:s'),
- ]))->save();
- return $res ? json_show(CommonModel::$success, '添加视频分组成功') : json_show(CommonModel::$success, '添加视频分组失败');
- }
- //获取视频分组详情
- public static function read(int $id = 0): Json
- {
- $res = VideoGroupModel::field(true)
- ->where(['id' => $id, 'is_del' => CommonModel::$del_normal])
- ->findOrEmpty()
- ->toArray();
- if (empty($res)) throw new ValidateException('该视频分组为空');
- return json_show(CommonModel::$success, '获取视频分组详情成功', $res);
- }
- //编辑视频分组
- public static function edit(array $data = []): Json
- {
- $rs = VideoGroupModel::field('id,company_id,card_id')
- ->where([
- 'id' => $data['id'],
- 'is_del' => CommonModel::$del_normal,
- ])
- ->findOrEmpty();
- if ($rs->isEmpty()) return json_show(CommonModel::$error_param, '该视频分组不存在');
- 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) return json_show(CommonModel::$error_param, '该视频分组已存在');
- }
- $res = VideoGroupModel::where(['id' => $data['id'], 'is_del' => CommonModel::$del_normal])
- ->save(array_merge($data, ['updatetime' => date('Y-m-d H:i:s'), 'updaterid' => self::$uid, 'updater' => self::$uid]));
- return $res ? json_show(CommonModel::$success, '编辑视频分组成功') : json_show(CommonModel::$error_param, '编辑视频分组失败');
- }
- //视频分组启禁用
- public static function status(array $data = []): Json
- {
- $res = VideoGroupModel::where('id', $data['id'])
- ->where('status', '<>', $data['status'])
- ->save([
- 'status' => $data['status'],
- 'updatetime' => date('Y-m-d H:i:s'),
- 'updaterid' => self::$uid,
- 'updater' => self::$uid
- ]);
- return $res ? json_show(CommonModel::$success, '操作成功') : json_show(CommonModel::$success, '操作失败,该视频分组不存在或重复操作');
- }
- //删除视频分组
- public static function delete(array $ids = []): Json
- {
- $res = VideoGroupModel::whereIn('id', $ids)
- ->where('is_del', CommonModel::$del_normal)
- ->save([
- 'is_del' => CommonModel::$del_deleted,
- 'updatetime' => date('Y-m-d H:i:s'),
- 'updaterid' => self::$uid,
- 'updater' => self::$uid
- ]);
- return $res ? json_show(CommonModel::$success, '删除成功') : json_show(CommonModel::$error_param, '删除失败,该视频分组不存在');
- }
- //视频分组置顶
- 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'),
- 'updaterid' => self::$uid,
- 'updater' => self::$uid
- ]);
- return $res ? json_show(CommonModel::$success, '操作成功') : json_show(CommonModel::$success, '操作失败,该视频分组不存在或重复操作');
- }
- }
|