title = '图文列表'; $this->article_id = input('article_id'); $sel_where = []; $sel_where[] = ['is_deleted','=',0]; $sel_where[] = ['article_id','=',$this->article_id]; $query = $this->_query($this->table); $query->where($sel_where)->order('sort desc,id asc')->page(false); } /** * 数据列表处理 * @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->_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->_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 del() { $article_id = \app\common\model\ArticleItem::where('id',input('id'))->value('article_id'); ArticleIntro::where('id',$article_id)->setDec('item_num'); $this->_save($this->table, ['is_deleted' => 1]); } /** * 表单数据处理 * @auth true * @menu true * @param array $data */ protected function _form_filter(&$data) { if($this->request->isGet()){ $this->article_id = input('article_id'); $this->article_info = ArticleIntro::where('id',$this->article_id)->find()->toArray(); // 视频 $this->video_list = \app\common\model\VideoIntro::with('videoArr') ->where(['is_deleted'=>0])->order('id desc') ->select()->toArray(); // 资料 $this->datum_list = DatumIntro::with('urlArr') ->where(['is_deleted'=>0])->order('id desc') ->select()->toArray(); } if($this->request->isPost()){ $is_vip = ArticleIntro::where('id',$this->request->post('article_id'))->value('is_vip'); if($is_vip) $data['is_vip'] = 1; if(empty($data['images'])) $this->error('请上传图片'); $data['cover'] = explode('|',$data['images'])[0]; if(!empty($data['phone'])) { $user_id = User::where('phone|email',$data['phone'])->value('id'); if(!$user_id) $this->error('账号未注册'); $data['user_id'] = $user_id; }else{ $data['user_id'] = ''; } if($data['content_type'] == 2) $data['content']=''; } } protected function _form_result($result) { $article_num = \app\common\model\ArticleItem::field('id,read_num')->where(['article_id'=>$this->request->post('article_id'),'is_deleted'=>0])->select()->toArray(); $article_info = ArticleIntro::where('id',$this->request->post('article_id'))->find()->toArray(); $up = []; $up['item_num'] = count($article_num); if(!$article_info['cover']) $up['cover'] = explode('|',$this->request->post('images'))[0]; if(!$article_info['video_id']) { $up['video_id'] = $this->request->post('video_id'); $up['video_item'] = $this->request->post('video_item'); $up['datum_id'] = $this->request->post('datum_id'); $up['datum_item'] = $this->request->post('datum_item'); } $up['read_num'] = array_sum(array_column($article_num,'read_num')); ArticleIntro::where('id',$this->request->post('article_id'))->update($up); $this->success('操作成功', 'javascript:history.back()'); } /** * 禁用 * @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 forbid() { $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 resume() { $this->_save($this->table, ['status' => 1]); } }