GoodsTwoCate.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <?php
  2. namespace app\mall\controller;
  3. use library\Controller;
  4. use library\service\MenuService;
  5. use library\tools\Data;
  6. use think\Db;
  7. /**
  8. * 二级分类管理
  9. * Class GoodsCate
  10. * @package app\admin\controller
  11. */
  12. class GoodsTwoCate extends Controller
  13. {
  14. /**
  15. * 当前操作数据库
  16. * @var string
  17. */
  18. protected $table = 'GoodsCate';
  19. /**
  20. * 二级分类管理
  21. * @auth true
  22. * @menu true
  23. * @throws \think\Exception
  24. * @throws \think\db\exception\DataNotFoundException
  25. * @throws \think\db\exception\ModelNotFoundException
  26. * @throws \think\exception\DbException
  27. * @throws \think\exception\PDOException
  28. */
  29. public function index()
  30. {
  31. $this->title = '二级分类管理';
  32. $id = input('id');
  33. if(empty($id)){
  34. $this->error('非法操作');
  35. }
  36. $this->app->session->set('pid',$id);
  37. $query = $this->_query($this->table)->like('title');
  38. $query->where('level',2)->where('pid',$id)->where('is_deleted',0)->order('id asc')->page();
  39. }
  40. /**
  41. * 列表数据处理
  42. * @param array $data
  43. */
  44. protected function _index_page_filter(&$data)
  45. {
  46. }
  47. /**
  48. * 添加分类
  49. * @auth true
  50. * @menu true
  51. * @throws \think\Exception
  52. * @throws \think\db\exception\DataNotFoundException
  53. * @throws \think\db\exception\ModelNotFoundException
  54. * @throws \think\exception\DbException
  55. * @throws \think\exception\PDOException
  56. */
  57. public function add()
  58. {
  59. $this->_form($this->table, 'form');
  60. }
  61. /**
  62. * 编辑分类
  63. * @auth true
  64. * @menu true
  65. * @throws \think\Exception
  66. * @throws \think\db\exception\DataNotFoundException
  67. * @throws \think\db\exception\ModelNotFoundException
  68. * @throws \think\exception\DbException
  69. * @throws \think\exception\PDOException
  70. */
  71. public function edit()
  72. {
  73. $this->_form($this->table, 'form');
  74. }
  75. /**
  76. * 表单数据处理
  77. * @param array $data
  78. * @throws \ReflectionException
  79. * @throws \think\db\exception\DataNotFoundException
  80. * @throws \think\db\exception\ModelNotFoundException
  81. * @throws \think\exception\DbException
  82. */
  83. protected function _form_filter(&$data)
  84. {
  85. if ($this->request->isGet()) {
  86. }
  87. if($this->request->isPost() && in_array($this->request->action(),['add','edit'])){
  88. $data['pid'] = $this->app->session->get('pid');
  89. $data['level'] = 2;
  90. }
  91. }
  92. /**
  93. * 启用
  94. * @auth true
  95. * @menu true
  96. * @throws \ReflectionException
  97. * @throws \think\db\exception\DataNotFoundException
  98. * @throws \think\db\exception\ModelNotFoundException
  99. * @throws \think\exception\DbException
  100. */
  101. public function enable()
  102. {
  103. $this->_save($this->table, ['status' => '1']);
  104. }
  105. /**
  106. * 禁用
  107. * @auth true
  108. * @menu true
  109. * @throws \ReflectionException
  110. * @throws \think\db\exception\DataNotFoundException
  111. * @throws \think\db\exception\ModelNotFoundException
  112. * @throws \think\exception\DbExceptionn
  113. */
  114. public function forbidden()
  115. {
  116. $this->_save($this->table, ['status' => '0']);
  117. }
  118. /**
  119. * 删除
  120. * @auth true
  121. * @menu true
  122. * @throws \ReflectionException
  123. * @throws \think\db\exception\DataNotFoundException
  124. * @throws \think\db\exception\ModelNotFoundException
  125. * @throws \think\exception\DbException
  126. */
  127. public function remove()
  128. {
  129. $this->_delete($this->table);
  130. }
  131. }