GoodsCategory.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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. /**
  20. * 商品分类
  21. */
  22. class GoodsCategory extends Controller
  23. {
  24. /**
  25. * 绑定数据表
  26. * @var string
  27. */
  28. protected $table = 'GoodsCategory';
  29. /**
  30. * 控制器初始化
  31. */
  32. protected function initialize()
  33. {
  34. }
  35. /**
  36. * 列表
  37. * @auth true
  38. * @menu true
  39. * @throws \think\Exception
  40. * @throws \think\db\exception\DataNotFoundException
  41. * @throws \think\db\exception\ModelNotFoundException
  42. * @throws \think\exception\DbException
  43. */
  44. public function index()
  45. {
  46. $this->title = '商品分类列表';
  47. $query = $this->_query($this->table)
  48. ->field('is_deleted', true)
  49. ->where('is_deleted',CommonConstant::IS_DELETED_0)
  50. ->order('sort desc,id asc');
  51. $query->page(false);
  52. }
  53. /**
  54. * 列表数据处理
  55. * @param array $data
  56. * @throws \Exception
  57. */
  58. protected function _index_page_filter(&$data)
  59. {
  60. if($data) {
  61. foreach ($data as &$vo) {
  62. $vo['ids'] = join(',', Data::getArrSubIds($data, $vo['id']));
  63. }
  64. $data = Data::arr2table($data);
  65. }
  66. }
  67. /**
  68. * 添加
  69. * @auth true
  70. * @throws \think\Exception
  71. * @throws \think\db\exception\DataNotFoundException
  72. * @throws \think\db\exception\ModelNotFoundException
  73. * @throws \think\exception\DbException
  74. * @throws \think\exception\PDOException
  75. */
  76. public function add()
  77. {
  78. $this->title = '添加';
  79. $this->_form($this->table, 'form');
  80. }
  81. /**
  82. * 编辑
  83. * @auth true
  84. * @throws \think\Exception
  85. * @throws \think\db\exception\DataNotFoundException
  86. * @throws \think\db\exception\ModelNotFoundException
  87. * @throws \think\exception\DbException
  88. * @throws \think\exception\PDOException
  89. */
  90. public function edit()
  91. {
  92. $this->title = '编辑';
  93. $this->_form($this->table, 'form');
  94. }
  95. /**
  96. * 表单处理
  97. * @param array $data
  98. * @throws \think\db\exception\DataNotFoundException
  99. * @throws \think\db\exception\ModelNotFoundException
  100. * @throws \think\exception\DbException
  101. */
  102. protected function _form_filter(&$data)
  103. {
  104. if ($this->request->isGet()) {
  105. $category_list = GoodsCategoryService::get_list([]);
  106. $this->category_list = array_merge([['id' => '0', 'pid' => '-1', 'name' => '顶级']],$category_list ? $category_list->toArray() : []);
  107. }
  108. if ($this->request->isPost()) {
  109. }
  110. }
  111. /**
  112. * 删除
  113. * @auth true
  114. * @throws \think\Exception
  115. * @throws \think\exception\PDOException
  116. */
  117. public function remove()
  118. {
  119. $this->applyCsrfToken();
  120. $this->_delete($this->table);
  121. }
  122. }