title = '视频列表'; $video_cate = VCM::field('id,title')->select()->toArray(); $this->video_cate = array_column($video_cate,null,'id'); $sel_where = []; $sel_where[] = ['v.is_deleted','in','0,1']; if($title = $this->request->get('title')) $sel_where[] = ['v.title','like','%'.$title.'%']; if($phone = $this->request->get('phone')) $sel_where[] = ['m.phone','like','%'.$phone.'%']; $this->status = $this->request->get('status',-1); if( $this->status >= 0 ) $sel_where[] = ['v.status','=', $this->status ]; $query = $this->_query($this->table)->field('v.*,m.phone,m.name user_name, m.headimg')->alias('v') ->leftJoin('StoreMember m','m.id = v.user_id'); $arr = ['is_new' => 0]; \app\common\model\UserVideo::alias('f')->where('is_new',1)->update($arr); $query->where($sel_where)->order('v.id desc')->page(); } /** * 数据列表处理 * @auth true * @menu true * @param array $data * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ protected function _index_page_filter(&$data) { } /** * 编辑 * @auth true * @menu true * @throws \think\Exception * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException * @throws \think\exception\PDOException */ public function edit() { $this->title = '编辑视频'; $this->_form($this->table, 'form'); } /** * 禁用 * @auth true * @menu true * @throws \think\Exception * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException * @throws \think\exception\PDOException */ public function forbidden() { $this->_save($this->table, ['status' => '0']); } /** * 启用 * @auth true * @menu true * @throws \think\Exception * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException * @throws \think\exception\PDOException */ public function enable() { $this->_save($this->table, ['status' => 1]); } /** * 删除视频 * @auth true * @menu true * @throws \think\Exception * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException * @throws \think\exception\PDOException */ public function del() { $this->_save($this->table, ['is_deleted' =>2]); } /** * 表单数据处理 * @auth true * @menu true * @param array $data */ protected function _form_filter(&$data) { if($this->request->isGet() && in_array($this->request->action(),['add','edit'])){ $all_cate = VCM::where(['is_deleted'=>0])->order('sort desc ,id desc')->select(); $this->cate_tree = make_tree($all_cate); } if($this->request->isPost() && in_array($this->request->action(),['add','edit'])) { if($data['status'] > 0 ) UserMessage::sendUserMessage($data['user_id'],'video',2,$data['status']-1,0,$data['id']); } } protected function _form_result($result){ } /** * 视频添加到系列 * @auth true * @throws \think\Exception * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException * @throws \think\exception\PDOException */ public function series() { if ($this->request->isGet()) { $id = $this->request->get('id'); $has_series = VideoUrl::where('rel_id',$id)->column('video_id'); $user_video = \app\common\model\UserVideo::where(['id' => $id])->find()->toArray(); $series_list = VideoIntro::where(['is_deleted'=>0,'type'=>2])->where('id','not in',$has_series)->column('title','id'); $this->fetch('', ['vo' => $user_video,'series_list'=>$series_list]); } else { $id = input('post.id'); $series_id = input('post.series_id'); $sort = input('post.sort'); $is_vip = input('post.is_vip'); $user_video = \app\common\model\UserVideo::where(['id' => $id])->find()->toArray(); $user_info = User::where('id',$user_video['user_id'])->find()->toArray(); VideoUrl::create([ 'video_id'=>$series_id, 'cover'=>$user_video['cover'], 'url'=>$user_video['video_url'], 'sort'=>$sort, 'is_vip'=>$is_vip, 'source'=>2, 'rel_id'=>$id, 'title'=>$user_video['title'], 'user_id'=>$user_video['user_id'], 'phone'=>$user_info['phone'] ? $user_info['phone']:$user_info['email'], ]); VideoIntro::where('id',$series_id)->setInc('url_num'); $this->success('添加成功!'); } } public function new_video(){ if($this->request->isGet()) { $user_video = \app\common\model\UserVideo::where('id',input('id'))->find()->toArray(); $all_cate = \app\common\model\VideoCate::where(['is_deleted'=>0])->order('sort desc ,id desc')->select(); $cate_tree = make_tree($all_cate); $this->cate_tree = $cate_tree; $this->fetch('',['vo'=>$user_video,'cate_tree '=>$cate_tree]); }else{ $user_video_id= input('user_video_id'); $user_video = \app\common\model\UserVideo::where('id',$user_video_id)->find()->toArray(); $user_info = User::where('id',$user_video['user_id'])->find()->toArray(); $new_video = [ 'title' => $user_video['title'], 'content' => $user_video['desc'], 'cover' => $user_video['cover'], 'video_url' => $user_video['video_url'], 'first_classify' => input('first_classify'), 'second_classify' => input('second_classify'), 'type' => 1, 'is_over' => 1, 'label' => $user_video['label'], 'is_vip' => input('is_vip'), ]; $result = VideoIntro::create($new_video); $video_item = [ 'video_id' => $result->id, 'cover' => $new_video['cover'], 'url' => $new_video['video_url'], 'is_vip' => $new_video['is_vip'], 'source' => 2, 'title' => $new_video['title'], 'rel_id' => $user_video_id, 'user_id'=>$user_video['user_id'], 'phone'=>$user_info['phone'] ? $user_info['phone']:$user_info['email'], ]; Data::save('VideoUrl',$video_item,'video_id',['video_id' => $result->id]); $this->success('创建成功'); } } }