123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174 |
- <?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\approve\controller;
- use app\common\constant\CommonConstant;
- use app\common\model\Goods;
- use app\common\model\GoodsCategory as model;
- use app\common\service\GoodsCategoryService;
- use library\Controller;
- use library\tools\Data;
- /**
- * 商品分类
- */
- class GoodsCategory extends Controller
- {
- /**
- * 绑定数据表
- * @var string
- */
- protected $table = 'GoodsCategory';
- /**
- * 控制器初始化
- */
- protected function initialize()
- {
- }
- /**
- * 列表
- * @auth true
- * @menu true
- * @throws \think\Exception
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function index()
- {
- $this->title = '商品分类列表';
- $query = $this->_query($this->table)
- ->field('is_deleted', true)
- ->where('is_deleted', CommonConstant::IS_DELETED_0)
- ->order('sort desc,id asc');
- $query->page(false);
- }
- /**
- * 列表数据处理
- * @param array $data
- * @throws \Exception
- */
- protected function _index_page_filter(&$data)
- {
- if ($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->title = '添加';
- $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->title = '编辑';
- $this->_form($this->table, 'form');
- }
- /**
- * 表单处理
- * @param array $data
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- protected function _form_filter(&$data)
- {
- if ($this->request->isGet()) {
- $this->category_list = GoodsCategoryService::get_list([]);
- $this->category_list = array_merge([['id' => '0', 'pid' => '-1', 'name' => '顶级']], $this->category_list ? $this->category_list->toArray() : []);
- }
- if ($this->request->isPost()) {
- }
- }
- /**
- * 删除
- * @auth true
- * @throws \think\Exception
- * @throws \think\exception\PDOException
- */
- public function remove()
- {
- $this->applyCsrfToken();
- list($data) = [$this->request->post()];
- $is_goods = Goods::field('id')
- ->where('is_deleted', CommonConstant::IS_DELETED_0)
- ->when($data, function ($query) use ($data) {
- if ($data['pid'] == 0) {
- $query->where('goods_category_first', $data['id']);
- } else {
- $query->where('goods_category_id', $data['id']);
- }
- })
- ->find();
- if ($is_goods) {
- $this->error("该分类下有商品,不能删除!");
- }
- $this->_delete($this->table);
- }
- /**
- * 删除结果处理
- * @param boolean $result
- * @throws \think\Exception
- * @throws \think\exception\PDOException
- */
- protected function _remove_delete_result($result)
- {
- if ($result) {
- list($data) = [$this->request->post()];
- if ($data['pid'] == 0) {
- model::where('pid', $data['id'])->update(['is_deleted' => CommonConstant::IS_DELETED_1]);
- }
- $this->success("删除成功!", '');
- } else {
- $this->error("删除失败,请稍候再试!");
- }
- }
- }
|