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 desc')->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'); \app\common\model\ArticleItem::where('id',input('id'))->update(['is_deleted'=>1]); \app\common\model\ArticleItem::esAdd(input('id')); \app\common\model\TopSearch::saveData(input('id'),'article'); $this->success('已删除!'); } /** * 批量删除图文 * @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 remove() { $ids = input('id'); foreach (explode(',',$ids) as $id) { $article_id = \app\common\model\ArticleItem::where('id',$id)->value('article_id'); ArticleIntro::where('id',$article_id)->setDec('item_num'); \app\common\model\ArticleItem::where('id',$id)->update(['is_deleted'=>1]); \app\common\model\ArticleItem::esAdd($id); \app\common\model\TopSearch::saveData($id,'article'); } $this->success('已删除!'); } /** * 表单数据处理 * @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(); $this->supplier_goods = SupplierGoods::getSupplierGoodsList($this->request->action() == 'add' ? ['s.is_deleted'=>0]: []); } 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(!$data['release_time']) $data['release_time'] = date("Y-m-d H:i:s"); if($data['hot_num'] != $data['hot_num_old']) $data['hot_time'] = date("Y-m-d H:i:s"); 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); \app\common\model\ArticleItem::esAdd($result); \app\common\model\TopSearch::saveData($result,'article'); if($this->request->action() == 'add') PlatformSwitch::followMsg(3,$this->request->post('article_id'),$article_info['title'],$this->request->post('title'),$result); $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() { \app\common\model\ArticleItem::where('id',input('id'))->update(['status'=>0]); \app\common\model\ArticleItem::esAdd(input('id')); \app\common\model\TopSearch::saveData(input('id'),'article'); $this->success('已禁用!'); } /** * 启用 * @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() { \app\common\model\ArticleItem::where('id',input('id'))->update(['status'=>1]); \app\common\model\ArticleItem::esAdd(input('id')); \app\common\model\TopSearch::saveData(input('id'),'article'); $this->success('已启用!'); } /** * 富文本 * @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 content() { $this->title = '编辑富文本'; $this->_form($this->table, 'content') ; } }