title = '文章列表'; $sel_where = []; $sel_where[] = ['is_deleted','=',0]; $sel_where[] = ['type','=',1]; if($title = $this->request->get('title')) $sel_where[] = ['title','like','%'.$title.'%']; $this->is_vip = $is_vip = $this->request->get('is_vip',-1); if($is_vip >= 0) $sel_where[] = ['is_vip','=',$is_vip ]; $in_ids = ''; if($phone = $this->request->get('phone')) $in_ids = \app\common\model\ArticleItem::where('phone','like','%'.$phone.'%')->column('article_id'); $query = $this->_query($this->table); $query->where($sel_where) ->when($in_ids,function ($query)use ($in_ids){ if(!empty($in_ids)) $query->where('id','in',$in_ids); })->order('sort desc,id asc')->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) { foreach ($data as &$v) { $v['item_id'] = \app\common\model\ArticleItem::where(['article_id'=>$v['id']])->value('id'); } } /** * 添加 * @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->all_cate = ArticleCate::field('id,title')->where('is_deleted',0)->select(); $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 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 = ArticleCate::where(['is_deleted'=>0])->order('sort desc ,id desc')->select(); $this->r = input('get.r',0); $this->cate_tree = make_tree($all_cate); // 视频 $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(); $item_info = \app\common\model\ArticleItem::where('article_id',input('id'))->find(); $this->phone = $item_info? $item_info->phone : ''; $this->author = $item_info? $item_info->author : ''; $this->content_type = $item_info? $item_info->content_type : ''; $this->item_info = $item_info; } if($this->request->isPost()) { if(!$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('账号未注册'); } } } protected function _form_result($result){ $article_info = ArticleIntro::where('id',$result)->find()->toArray(); list($data) = [$this->request->post()]; if(!empty($data['phone'])) { $user_id = User::where('phone|email',$data['phone'])->value('id'); }else{ $user_id= ''; } $content_type = isset($data['content_type']) ?$data['content_type']:1; $item = [ 'article_id' => $article_info['id'], 'title' => $article_info['title'], 'cover' => $article_info['cover'], 'content' =>$content_type == 1? $article_info['content'] : '', 'is_vip' => $article_info['is_vip'], 'images' => $article_info['images'], 'video_id' => $data['video_id'], 'video_item' => $data['video_item'], 'datum_id' => isset($data['datum_id']) ?$data['datum_id'] : 0, 'datum_item' => isset($data['datum_item']) ?$data['datum_item']:0, 'phone' => isset($data['phone']) ?$data['phone']:'', 'author' => isset($data['author']) ?$data['author']:'', 'label' => isset($data['label']) ?$data['label']:'', 'read_num' => isset($data['read_num']) ?$data['read_num']:0, 'content_type' => isset($data['content_type']) ?$data['content_type']:1, 'user_id' => $user_id, 'pdf' => isset($data['pdf']) ?$data['pdf']:'', ]; Data::save('ArticleItem',$item,'article_id',['article_id'=>$article_info['id']]); $this->success('操作成功!', 'javascript:history.back()'); } }