title = '资讯列表'; $sel_where = []; $sel_where[] = ['is_deleted','=',0]; if($title = $this->request->get('title')) $sel_where[] = ['title','like','%'.$title.'%']; if($type = $this->request->get('type')) $sel_where[] = ['type','=',$type]; $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->all_cate = NTC::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 = NTC::where(['is_deleted'=>0])->order('sort desc ,id desc')->select(); $this->cate_tree = make_tree($all_cate); //选中的标签 $this->label_arr = isset($data['label']) ? explode('|',trim($data['label'],'|')) : []; $this->case = NutritionCase::column('title','id'); $this->news_channel = NewsChannel::where(['is_deleted'=>0,'status'=>1])->order('sort desc ,id desc')->column('title','id'); } if($this->request->isPost()) { if($data['type'] == 1 && !$data['cover']){ $this->error('请上传封面'); $data['video_url'] = ''; } if($data['type'] == 2 && !$data['video_url']){ $this->error('请上传视频'); $data['detail'] = ''; } // 服务标签 $label_sever = []; if(isset($data['label']) && !empty($data['label'])){ foreach ($data['label'] as $key=>$value){ if($value) $label_sever[] = $key; } } $data['label'] = '|'.implode('|',$label_sever).'|'; } } protected function _form_result($result){ $this->success('商品编辑成功!', 'javascript:history.back()'); } }