123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161 |
- <?php
- // +----------------------------------------------------------------------
- // | ThinkAdmin
- // +----------------------------------------------------------------------
- // | 版权所有 2014~2019 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
- // +----------------------------------------------------------------------
- // | 官方网站: http://demo.thinkadmin.top
- // +----------------------------------------------------------------------
- // | 开源协议 ( https://mit-license.org )
- // +----------------------------------------------------------------------
- // | gitee 代码仓库:https://gitee.com/zoujingli/ThinkAdmin
- // | github 代码仓库:https://github.com/zoujingli/ThinkAdmin
- // +----------------------------------------------------------------------
- namespace app\mall\controller;
- use library\Controller;
- use library\service\MenuService;
- use library\tools\Data;
- use think\Db;
- /**
- * 分类管理
- * Class GoodsCate
- * @package app\admin\controller
- */
- class GoodsCate extends Controller
- {
- /**
- * 当前操作数据库
- * @var string
- */
- protected $table = 'GoodsCate';
- /**
- * 分类管理
- * @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)->order('id desc ,id asc')->page(false);
- }
- /**
- * 列表数据处理
- * @param array $data
- */
- protected function _index_page_filter(&$data)
- {
- foreach ($data as &$vo) {
- $vo['ids'] = join(',', Data::getArrSubIds($data, $vo['id']));
- }
- $data = Data::arr2table($data);
- }
- /**
- * 添加分类
- * @auth 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->_form($this->table, 'form');
- }
- /**
- * 编辑分类
- * @auth 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->_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','is_deleted'=>0])->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;
- }else if(isset($vo['id'])){
- $pid = Db::name($this->table)->where('id',$vo['id'])->value('pid');
- $vo['lev'] = Db::name($this->table)->where('id',$pid)->value('lev') + 1;
- }
- }
- }
- /**
- * 启用分类
- * @auth true
- * @throws \think\Exception
- * @throws \think\exception\PDOException
- */
- public function resume()
- {
- $this->_save($this->table, ['status' => '1']);
- }
- /**
- * 禁用分类
- * @auth true
- * @throws \think\Exception
- * @throws \think\exception\PDOException
- */
- public function forbid()
- {
- $this->_save($this->table, ['status' => '0']);
- }
- /**
- * 删除分类
- * @auth true
- * @throws \think\Exception
- * @throws \think\exception\PDOException
- */
- public function remove()
- {
- $this->_delete($this->table);
- }
- }
|