浏览代码

Merge branch 'dev_wf' of wufeng/fuse into version1.5

wufeng 2 年之前
父节点
当前提交
f2f4b98ffd

+ 8 - 0
app/admin/config/validate_rules.php

@@ -133,4 +133,12 @@ return [
         'new_password|新密码' => 'require|min:6|max:255',
     ],
 
+    //【视频分组】
+    //添加
+    'VideoGroupAdd'=>[
+        'company_id|企业id'=>'require|number|gt:0',
+        'card_id|卡类型id'=>'require|number|gt:0',
+        'video_list|视频集合'=>'require|array|min:1|max:100',
+    ],
+
 ];

+ 44 - 5
app/admin/controller/VideoGroup.php

@@ -4,6 +4,10 @@ namespace app\admin\controller;
 
 use app\admin\logic\VideoGroupLogic;
 use app\BaseController;
+use app\model\CommonModel;
+use think\exception\ValidateException;
+use think\facade\Config;
+use think\facade\Validate;
 
 //【视频分组】
 class VideoGroup extends BaseController
@@ -19,31 +23,66 @@ class VideoGroup extends BaseController
     //添加视频分组
     public function add()
     {
-        return VideoGroupLogic::add();
+        $param = $this->request->only(['company_id', 'card_id', 'video_list', 'remark' => ''], 'post');
+
+        $val = Validate::rule(Config::get('validate_rules.VideoGroupAdd'));
+
+        if (!$val->check($param)) throw new ValidateException($val->getError());
+
+        return VideoGroupLogic::add($param);
     }
 
     //获取视频分组详情
     public function read()
     {
-        return VideoGroupLogic::read();
+        $id = $this->request->post('id/d', 0);
+        return VideoGroupLogic::read($id);
     }
 
     //编辑视频分组
     public function edit()
     {
-        return VideoGroupLogic::edit();
+        $param = $this->request->only(['id', 'company_id', 'card_id', 'video_list', 'remark' => ''], 'post');
+
+        $val = Validate::rule(array_merge(Config::get('validate_rules.VideoGroupAdd'), ['id|视频分组id' => 'require|number|gt:0']));
+
+        if (!$val->check($param)) throw new ValidateException($val->getError());
+
+        return VideoGroupLogic::edit($param);
     }
 
     //视频分组启禁用
     public function status()
     {
-        return VideoGroupLogic::status();
+        $param = $this->request->only(['id','status'],'post');
+
+        $val = Validate::rule(Config::get('validate_rules.status'));
+
+        if (!$val->check($param)) throw new ValidateException($val->getError());
+
+        return VideoGroupLogic::status($param);
     }
 
     //删除视频分组
     public function delete()
     {
-        return VideoGroupLogic::delete();
+        $id = $this->request->post('id/d', 0);
+        return VideoGroupLogic::delete($id);
+    }
+
+    //视频分组置顶
+    public function top()
+    {
+        $param = $this->request->only(['id','is_top'],'post');
+
+        $val = Validate::rule([
+            'id' => 'require|number|gt:0',
+            'is_top|是否置顶' => 'require|number|in:' . CommonModel::$top_no . ',' . CommonModel::$top_yes,
+        ]);
+
+        if (!$val->check($param)) throw new ValidateException($val->getError());
+
+        return VideoGroupLogic::top($param);
     }
 
 }

+ 171 - 8
app/admin/logic/VideoGroupLogic.php

@@ -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, '操作失败');
+
+    }
 
 }

+ 2 - 1
app/admin/route/app.php

@@ -77,4 +77,5 @@ Route::rule('videoGroupAdd', 'admin/VideoGroup/add');//添加视频分组
 Route::rule('videoGroupRead', 'admin/VideoGroup/read');//获取视频分组详情
 Route::rule('videoGroupEdit', 'admin/VideoGroup/edit');//编辑视频分组
 Route::rule('videoGroupChange', 'admin/VideoGroup/status');//视频分组启禁用
-Route::rule('videoGroupDelete', 'admin/VideoGroup/delete');//删除视频分组
+Route::rule('videoGroupDelete', 'admin/VideoGroup/delete');//删除视频分组
+Route::rule('videoGroupTop', 'admin/VideoGroup/top');//视频分组置顶

+ 4 - 1
app/model/CommonModel.php

@@ -16,9 +16,12 @@ class CommonModel
     public static $del_normal=0;//未删除
     public static $del_deleted=1;//已删除
 
-
     //状态
     public static $status_normal=1;//启用
     public static $status_disable=0;//禁用
 
+    //置顶
+    public static $top_yes = 1;//置顶
+    public static $top_no = 0;//不置顶
+
 }

+ 1 - 0
app/model/VideoGroupModel.php

@@ -8,4 +8,5 @@ class VideoGroupModel extends Model
 {
     protected $table = 'fc_video_group';
     protected $pk = 'id';
+
 }