GoodsCategory.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | ThinkAdmin
  4. // +----------------------------------------------------------------------
  5. // | 版权所有 2014~2019 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
  6. // +----------------------------------------------------------------------
  7. // | 官方网站: http://demo.thinkadmin.top
  8. // +----------------------------------------------------------------------
  9. // | 开源协议 ( https://mit-license.org )
  10. // +----------------------------------------------------------------------
  11. // | gitee 代码仓库:https://gitee.com/zoujingli/ThinkAdmin
  12. // | github 代码仓库:https://github.com/zoujingli/ThinkAdmin
  13. // +----------------------------------------------------------------------
  14. namespace app\approve\controller;
  15. use app\common\constant\CommonConstant;
  16. use app\common\service\GoodsCategoryService;
  17. use library\Controller;
  18. use library\tools\Data;
  19. use think\Db;
  20. /**
  21. * 商品分类
  22. */
  23. class GoodsCategory extends Controller
  24. {
  25. /**
  26. * 绑定数据表
  27. * @var string
  28. */
  29. protected $table = 'GoodsCategory';
  30. /**
  31. * 控制器初始化
  32. */
  33. protected function initialize()
  34. {
  35. }
  36. /**
  37. * 列表
  38. * @auth true
  39. * @menu true
  40. * @throws \think\Exception
  41. * @throws \think\db\exception\DataNotFoundException
  42. * @throws \think\db\exception\ModelNotFoundException
  43. * @throws \think\exception\DbException
  44. */
  45. public function index()
  46. {
  47. $this->title = '商品分类列表';
  48. $query = $this->_query($this->table)
  49. ->field('is_deleted', true)
  50. ->where('is_deleted',CommonConstant::IS_DELETED_0)
  51. ->order('sort desc,id asc');
  52. $query->page(false);
  53. }
  54. /**
  55. * 列表数据处理
  56. * @param array $data
  57. * @throws \Exception
  58. */
  59. protected function _index_page_filter(&$data)
  60. {
  61. if($data) {
  62. foreach ($data as &$vo) {
  63. $vo['ids'] = join(',', Data::getArrSubIds($data, $vo['id']));
  64. }
  65. $data = Data::arr2table($data);
  66. }
  67. }
  68. /**
  69. * 添加
  70. * @auth true
  71. * @throws \think\Exception
  72. * @throws \think\db\exception\DataNotFoundException
  73. * @throws \think\db\exception\ModelNotFoundException
  74. * @throws \think\exception\DbException
  75. * @throws \think\exception\PDOException
  76. */
  77. public function add()
  78. {
  79. $this->title = '添加';
  80. $this->_form($this->table, 'form');
  81. }
  82. /**
  83. * 编辑
  84. * @auth true
  85. * @throws \think\Exception
  86. * @throws \think\db\exception\DataNotFoundException
  87. * @throws \think\db\exception\ModelNotFoundException
  88. * @throws \think\exception\DbException
  89. * @throws \think\exception\PDOException
  90. */
  91. public function edit()
  92. {
  93. $this->title = '编辑';
  94. $this->_form($this->table, 'form');
  95. }
  96. /**
  97. * 表单处理
  98. * @param array $data
  99. * @throws \think\db\exception\DataNotFoundException
  100. * @throws \think\db\exception\ModelNotFoundException
  101. * @throws \think\exception\DbException
  102. */
  103. protected function _form_filter(&$data)
  104. {
  105. if ($this->request->isGet()) {
  106. $this->category_list = GoodsCategoryService::get_list([]);
  107. $this->category_list = array_merge([['id' => '0', 'pid' => '-1', 'name' => '顶级']],$this->category_list ? $this->category_list->toArray() : []);
  108. }
  109. if ($this->request->isPost()) {
  110. }
  111. }
  112. /**
  113. * 删除
  114. * @auth true
  115. * @throws \think\Exception
  116. * @throws \think\exception\PDOException
  117. */
  118. public function remove()
  119. {
  120. $this->applyCsrfToken();
  121. $this->_delete($this->table);
  122. }
  123. /**
  124. * 删除结果处理
  125. * @param boolean $result
  126. * @throws \think\Exception
  127. * @throws \think\exception\PDOException
  128. */
  129. protected function _remove_delete_result($result)
  130. {
  131. if ($result) {
  132. list($data) = [$this->request->post()];
  133. if($data['pid'] == 0){
  134. Db::name($this->table)->where('pid',$data['id'])->update(['is_deleted' => CommonConstant::IS_DELETED_1]);
  135. }
  136. $this->success("删除成功!", '');
  137. } else {
  138. $this->error("删除失败,请稍候再试!");
  139. }
  140. }
  141. }