|
@@ -0,0 +1,165 @@
|
|
|
+<?php
|
|
|
+namespace app\Nutrition\controller;
|
|
|
+use app\common\model\DatumIntro;
|
|
|
+use library\Controller;
|
|
|
+use app\common\model\DatumCate;
|
|
|
+/**
|
|
|
+ * 资料管理
|
|
|
+ * Class OneDatum
|
|
|
+ * @package app\Nutrition\controller
|
|
|
+ */
|
|
|
+class DatumUrl extends Controller
|
|
|
+{
|
|
|
+ /**
|
|
|
+ * 绑定数据表
|
|
|
+ * @var string
|
|
|
+ */
|
|
|
+ protected $table = 'DatumUrl';
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 列表
|
|
|
+ * @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 index()
|
|
|
+ {
|
|
|
+ $this->title = '资料列表';
|
|
|
+ $this->datum_id = input('datum_id');
|
|
|
+ $sel_where = [];
|
|
|
+ $sel_where[] = ['is_deleted','=',0];
|
|
|
+ $sel_where[] = ['datum_id','=',$this->datum_id];
|
|
|
+ $query = $this->_query($this->table);
|
|
|
+ $query->where($sel_where)->order('status desc ,is_top desc ,sort desc,id desc')->select();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 数据列表处理
|
|
|
+ * @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->datum_id = 0;
|
|
|
+ $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->datum_id = input('datum_id');
|
|
|
+ $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()
|
|
|
+ {
|
|
|
+ $this->_save($this->table, ['is_deleted' => 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 add_datum()
|
|
|
+ {
|
|
|
+ $this->title = '添加资料';
|
|
|
+ $this->type = input('get.type',2);
|
|
|
+ if($this->request->isGet()) {
|
|
|
+ $id = input('get.id');
|
|
|
+ $datum_info = DatumIntro::where('id',$id)->find()->toArray();
|
|
|
+ $cate_name = DatumCate::where('id',$datum_info['datum_cate'])->value('title');
|
|
|
+ $this->fetch('add_datum',['datum_info'=>$datum_info,'cate_name'=>$cate_name]);
|
|
|
+ }else{
|
|
|
+ list($post) = [$this->request->post()];
|
|
|
+ if(empty($post['url'])) $this->error('请上传文件');
|
|
|
+ $item_info = [
|
|
|
+ 'datum_id'=>$post['datum_id'],
|
|
|
+ 'url'=>$post['url'],
|
|
|
+ 'sort'=>$post['sort'],
|
|
|
+ ];
|
|
|
+ $this->success('添加成功');
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 表单数据处理
|
|
|
+ * @auth true
|
|
|
+ * @menu true
|
|
|
+ * @param array $data
|
|
|
+ */
|
|
|
+ protected function _form_filter(&$data)
|
|
|
+ {
|
|
|
+ if($this->request->isGet()){
|
|
|
+ $this->datum_cate = DatumCate::column('id,title,is_vip','id');
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ if($this->request->isPost()) {
|
|
|
+ if($this->request->action() == 'add') $data['url_num'] = 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ protected function _form_result($result){
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+}
|