|
@@ -0,0 +1,106 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace app\admin\logic;
|
|
|
+
|
|
|
+use app\model\AccountModel;
|
|
|
+use app\model\CommonModel;
|
|
|
+use app\model\GroupModel;
|
|
|
+use app\model\VideoGroupModel;
|
|
|
+use app\model\VideoModel;
|
|
|
+use think\Exception;
|
|
|
+use think\exception\ValidateException;
|
|
|
+use think\facade\Db;
|
|
|
+use think\response\Json;
|
|
|
+
|
|
|
+class VideoGroupLogic extends BaseLogic
|
|
|
+{
|
|
|
+ //列表
|
|
|
+ public static function List(array $data = []): Json
|
|
|
+ {
|
|
|
+ $db = VideoGroupModel::alias('a')
|
|
|
+ ->leftJoin('group b', 'b.id=a.group_id AND b.is_del=' . CommonModel::$del_normal)
|
|
|
+ ->leftJoin('company c', 'c.id=b.company_id AND c.is_del=' . CommonModel::$del_normal)
|
|
|
+ ->leftJoin('card d', 'd.id=b.card_id AND d.is_del=' . CommonModel::$del_normal)
|
|
|
+ ->where('a.is_del', CommonModel::$del_normal);
|
|
|
+
|
|
|
+ if ($data['company_title'] !== '') $db->whereLike('c.title', '%' . $data['company_title'] . '%');
|
|
|
+ if ($data['card_title']) $db->whereLike('d.title', '%' . $data['card_title'] . '%');
|
|
|
+ if ($data['code']) $db->where('a.code', $data['code']);
|
|
|
+ if (($data['start_date'] != '') && ($data['end_date' != ''])) $db->whereBetween('a.addtime', [$data['start_date'], $data['end_date']]);
|
|
|
+
|
|
|
+ $count = $db->count('a.id');
|
|
|
+
|
|
|
+ $video = $db
|
|
|
+ ->field('a.id,a.code,a.video_ids,a.addtime,c.title company_title,d.title card_title')
|
|
|
+ ->page($data['page'], $data['size'])
|
|
|
+ ->order('a.addtime', 'desc')
|
|
|
+ ->append(['video_name'])
|
|
|
+ ->withAttr('video_name', function ($val, $da) {
|
|
|
+ return VideoModel::where(['is_del' => CommonModel::$del_normal, 'status' => CommonModel::$status_normal])
|
|
|
+ ->whereIn('id', $da['video_ids'])->column('video_name');
|
|
|
+ })
|
|
|
+ ->select()
|
|
|
+ ->toArray();
|
|
|
+
|
|
|
+ return json_show(CommonModel::$success, '获取成功', ['list' => $video, 'count' => $count]);
|
|
|
+ }
|
|
|
+
|
|
|
+ //添加
|
|
|
+ public static function Add(array $data = []): Json
|
|
|
+ {
|
|
|
+
|
|
|
+ Db::startTrans();
|
|
|
+
|
|
|
+ try {
|
|
|
+
|
|
|
+ $rs = GroupModel::field('id,company_id,card_id,status')
|
|
|
+ ->where(['is_del' => CommonModel::$del_normal, 'id' => $data['group_id']])
|
|
|
+ ->findOrEmpty();
|
|
|
+
|
|
|
+ if ($rs->isEmpty()) throw new Exception('该分组不存在');
|
|
|
+ if ($rs->status == CommonModel::$status_disable) throw new Exception('该分组已禁用');
|
|
|
+
|
|
|
+ //添加记录
|
|
|
+ $video_ids = VideoModel::where(['is_del' => CommonModel::$del_normal, 'status' => CommonModel::$status_normal])
|
|
|
+ ->whereIn('id', $data['video_ids'])
|
|
|
+ ->column('id');
|
|
|
+ if (empty($video_ids)) throw new Exception('视频不存在或已禁用');
|
|
|
+
|
|
|
+ $date = date('Y-m-d H:i:s');
|
|
|
+
|
|
|
+ $data = [
|
|
|
+ 'group_id' => $data['group_id'],
|
|
|
+ 'code' => makeNo('VG'),
|
|
|
+ 'video_ids' => implode(',', $video_ids),
|
|
|
+ 'is_del' => CommonModel::$del_normal,
|
|
|
+ 'addtime' => $date,
|
|
|
+ 'updatetime' => $date,
|
|
|
+ ];
|
|
|
+
|
|
|
+ $res = VideoGroupModel::create($data)->save();
|
|
|
+
|
|
|
+ //更新对应的账户关联视频
|
|
|
+ AccountModel::where([
|
|
|
+ 'is_del' => CommonModel::$del_normal,
|
|
|
+ 'company_id' => $rs->company_id,
|
|
|
+ 'card_id' => $rs->card_id
|
|
|
+ ])->save([
|
|
|
+ 'video_ids' => implode(',', $video_ids),
|
|
|
+ 'updaterid' => self::$uid,
|
|
|
+ 'updater' => self::$uname,
|
|
|
+ 'updatetime' => $date
|
|
|
+ ]);
|
|
|
+
|
|
|
+ Db::commit();
|
|
|
+
|
|
|
+ if ($res) return json_show(CommonModel::$success, '批量设置视频添加成功');
|
|
|
+ else throw new Exception();
|
|
|
+
|
|
|
+ } catch (Exception $exception) {
|
|
|
+ Db::rollback();
|
|
|
+ return json_show(CommonModel::$error_param, '批量视频添加失败,' . $exception->getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|