title = '视频列表'; $video_cate = VCM::field('id,title')->select()->toArray(); $this->video_cate = array_column($video_cate,null,'id'); $sel_where = []; $sel_where[] = ['is_deleted','=',0]; $sel_where[] = ['type','=',2]; if($title = $this->request->get('title')) $sel_where[] = ['title','like','%'.$title.'%']; $query = $this->_query($this->table); $query->where($sel_where)->order('status desc ,is_top desc ,sort desc,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 add() { $this->title = '添加视频'; $this->type = input('get.type',2); $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 edit() { $this->title = '编辑视频'; $this->type = input('get.type',2); $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' => 1]); } /** * 表单数据处理 * @auth true * @menu true * @param array $data */ protected function _form_filter(&$data) { if($this->request->isGet()){ $all_cate = VCM::where(['is_deleted'=>0])->order('sort desc ,id desc')->select(); $this->cate_tree = make_tree($all_cate); if($this->request->action() == 'add') { $this->video_url = $this->request->get('type',1) == 1 ? '' :[]; }else{ if($this->request->get('type',1) == 1 ) { $this->video_url = VideoUrl::where(['video_id'=>$data['id']])->find()->toArray(); }else{ $this->video_url = VideoUrl::where(['video_id'=>$data['id']])->order('sort desc,id asc')->select()->toArray(); } } } if($this->request->isPost()) { if($data['type'] == 1){ if( !$data['url']) $this->error('请上传视频'); }else{ $item_title = input('post.item_title'); if(empty($item_title)) $this->error('请上传视频'); } if($this->request->action() == 'add') $data['url_num'] = 0; } } protected function _form_result($result){ if($this->request->isPost() && in_array($this->request->action(),['add','edit'])) { $video_info = VideoIntro::where('id',$result)->find()->toArray(); if($this->request->post('type') == 1) { Data::save('VideoUrl',['video_id'=>$result,'url'=>input('post.url'),'cover'=>input('post.url').$this->url_suffix,'is_vip'=>input('post.is_vip'),'title'=>input('post.title')],'video_id',['video_id'=>$result]); VideoIntro::where('id',$result)->update(['video_url'=>input('post.url'),'cover'=>input('post.url').$this->url_suffix]); }else{ $item_title = input('post.item_title'); $item_id = input('post.item_id'); $item_url = input('post.item_url'); $item_sort = input('post.item_sort'); $item_is_vip = input('post.item_is_vip'); VideoUrl::where('id','not in',$item_id)->where('video_id','=',$result)->update(['is_deleted'=>1]);// 删掉关联视频 foreach ($item_title as $k=>$t){ // 修改视频 $item_info = [ 'title' => $t, 'video_id' => $result, 'url' => $item_url[$k], 'cover' => $item_url[$k].$this->url_suffix, 'is_vip' => $item_is_vip[$k], 'sort' => $item_sort[$k], ]; if(isset($item_id[$k]) && $item_id[$k]) { VideoUrl::where('id',$item_id[$k])->update($item_info); }else{// 添加视频 VideoUrl::create($item_info); } } VideoIntro::where('id',$result)->update(['video_url'=>$item_url[0],'cover'=>$item_url[0].$this->url_suffix]); } } } }