title = '资料列表'; $datum_cate = DatumCate::field('id,title')->select()->toArray(); $this->datum_cate = array_column($datum_cate,null,'id'); $sel_where = []; $sel_where[] = ['is_deleted','=',0]; $sel_where[] = ['type','=',1]; if($title = $this->request->get('title')) $sel_where[] = ['title','like','%'.$title.'%']; $query = $this->_query($this->table); $query->where($sel_where)->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['second_id'] = DatumUrl::where('datum_id',$v['id'])->where('is_deleted',0)->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->type = input('get.type',1); $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',1); $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()){ $this->r = input('get.r',0); } if($this->request->isPost()) { } } protected function _form_result($result){ if($this->request->isPost() && in_array($this->request->action(),['add','edit'])) { $datum_info = DatumIntro::where('id',$result)->find()->toArray(); $datum_url = [ 'datum_id' => $result, 'url' => $datum_info['datum_url'], 'sort' => $datum_info['sort'], 'is_deleted' => 0, 'is_vip' => $datum_info['is_vip'], 'source' => 1, 'title' => $datum_info['title'], ]; Data::save('DatumUrl',$datum_url,'datum_id',['datum_id' => $result]); } } }