123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- <?php
- namespace app\data\controller\shop;
- use app\data\model\ShopGoodsCate;
- use think\admin\Controller;
- use think\admin\extend\DataExtend;
- /**
- * 商品分类管理
- * Class Cate
- * @package app\data\controller\shop
- */
- class Cate extends Controller
- {
- /**
- * 商品分类管理
- * @auth true
- * @menu true
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function index()
- {
- $this->title = "商品分类管理";
- $query = ShopGoodsCate::mQuery()->like('name')->dateBetween('create_at');
- $query->equal('status')->where(['deleted' => 0])->order('sort desc,id desc')->page(false);
- }
- /**
- * 列表数据处理
- * @param array $data
- */
- protected function _index_page_filter(array &$data)
- {
- foreach ($data as &$vo) {
- $vo['ids'] = join(',', DataExtend::getArrSubIds($data, $vo['id']));
- }
- $data = DataExtend::arr2table($data);
- }
- /**
- * 添加商品分类
- * @auth true
- */
- public function add()
- {
- ShopGoodsCate::mForm('form');
- }
- /**
- * 编辑商品分类
- * @auth true
- */
- public function edit()
- {
- ShopGoodsCate::mForm('form');
- }
- /**
- * 表单数据处理
- * @param array $data
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- protected function _form_filter(array &$data)
- {
- if ($this->request->isGet()) {
- $data['pid'] = intval($data['pid'] ?? input('pid', '0'));
- $cates = ShopGoodsCate::mk()->where(['deleted' => 0])->order('sort desc,id desc')->select()->toArray();
- $this->cates = DataExtend::arr2table(array_merge($cates, [['id' => '0', 'pid' => '-1', 'name' => '顶部分类']]));
- if (isset($data['id'])) foreach ($this->cates as $cate) if ($cate['id'] === $data['id']) $data = $cate;
- foreach ($this->cates as $key => $cate) if ((isset($data['spt']) && $data['spt'] <= $cate['spt'])) {
- unset($this->cates[$key]);
- }
- }
- }
- /**
- * 修改商品分类状态
- * @auth true
- */
- public function state()
- {
- ShopGoodsCate::mSave($this->_vali([
- 'status.in:0,1' => '状态值范围异常!',
- 'status.require' => '状态值不能为空!',
- ]));
- }
- /**
- * 删除商品分类
- * @auth true
- */
- public function remove()
- {
- ShopGoodsCate::mDelete();
- }
- }
|