|
@@ -0,0 +1,166 @@
|
|
|
+<?php
|
|
|
+namespace app\Nutrition\controller;
|
|
|
+use library\Controller;
|
|
|
+use library\service\MenuService;
|
|
|
+use library\tools\Data;
|
|
|
+use think\Db;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 分类
|
|
|
+ * Class ArticleSeriesCate
|
|
|
+ * @package app\nutrition\controller
|
|
|
+ */
|
|
|
+class ArticleSeriesCate extends Controller
|
|
|
+{
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 绑定数据表
|
|
|
+ * @var string
|
|
|
+ */
|
|
|
+ protected $table = 'SeriesArticleCate';
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 分类列表
|
|
|
+ * @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 = '分类列表';
|
|
|
+ $query = $this->_query($this->table)->where('is_deleted',0)->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)
|
|
|
+ {
|
|
|
+ foreach ($data as &$vo) {
|
|
|
+ $vo['ids'] = join(',', Data::getArrSubIds($data, $vo['id']));
|
|
|
+ }
|
|
|
+ $data = Data::arr2table($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');
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 表单数据处理
|
|
|
+ * @param array $vo
|
|
|
+ * @throws \ReflectionException
|
|
|
+ * @throws \think\db\exception\DataNotFoundException
|
|
|
+ * @throws \think\db\exception\ModelNotFoundException
|
|
|
+ * @throws \think\exception\DbException
|
|
|
+ */
|
|
|
+ protected function _form_filter(&$vo)
|
|
|
+ {
|
|
|
+ if ($this->request->isGet()) {
|
|
|
+ // 读取系统功能节点
|
|
|
+ $this->nodes = MenuService::instance()->getList();
|
|
|
+ // 选择自己的上级分类
|
|
|
+ if (empty($vo['pid']) && $this->request->get('pid', '0')) $vo['pid'] = $this->request->get('pid', '0');
|
|
|
+ // 列出可选上级分类
|
|
|
+ $menus = Db::name($this->table)->where(['status' => '1'])->order('sort desc,id asc')->column('id,pid,title,logo');
|
|
|
+ $this->menus = Data::arr2table(array_merge($menus, [['id' => '0', 'pid' => '-1', 'title' => '顶部分类']]));
|
|
|
+ if (isset($vo['id'])) foreach ($this->menus as $key => $menu) if ($menu['id'] === $vo['id']) $vo = $menu;
|
|
|
+ foreach ($this->menus as $key => &$menu) {
|
|
|
+ if ($menu['spt'] >= 2) unset($this->menus[$key]);
|
|
|
+ if (isset($vo['spt']) && $vo['spt'] <= $menu['spt']) unset($this->menus[$key]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if($this->request->isPost() && in_array($this->request->action(),['add','edit'])){
|
|
|
+ if(!isset($vo['id']) && $vo['pid']){
|
|
|
+ $plev = Db::name($this->table)->where('id',$vo['pid'])->value('lev');
|
|
|
+ $vo['lev'] = $plev + 1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 启用
|
|
|
+ * @auth true
|
|
|
+ * @menu true
|
|
|
+ * @throws \think\Exception
|
|
|
+ * @throws \think\exception\PDOException
|
|
|
+ */
|
|
|
+ public function resume()
|
|
|
+ {
|
|
|
+ $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 forbid()
|
|
|
+ {
|
|
|
+ $this->_save($this->table, ['status' => '0']);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除
|
|
|
+ * @auth true
|
|
|
+ * @menu true
|
|
|
+ * @throws \think\Exception
|
|
|
+ * @throws \think\exception\PDOException
|
|
|
+ */
|
|
|
+ public function remove()
|
|
|
+ {
|
|
|
+ $this->_save($this->table, ['is_deleted' => 1]);
|
|
|
+ }
|
|
|
+
|
|
|
+}
|
|
|
+
|