GoodsCate.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <?php
  2. namespace app\store\controller;
  3. use library\Controller;
  4. use think\Db;
  5. /**
  6. * 分类管理
  7. * Class Goods
  8. * @package app\store\controller
  9. */
  10. class GoodsCate extends Controller
  11. {
  12. /**
  13. * 绑定数据表
  14. * @var string
  15. */
  16. protected $table = 'StoreGoodsCate';
  17. /**
  18. * 分类管理
  19. * @auth true
  20. * @menu true
  21. * @throws \think\Exception
  22. * @throws \think\db\exception\DataNotFoundException
  23. * @throws \think\db\exception\ModelNotFoundException
  24. * @throws \think\exception\DbException
  25. * @throws \think\exception\PDOException
  26. */
  27. public function index()
  28. {
  29. $this->title = '分类管理';
  30. $query = $this->_query($this->table)->where('is_deleted',0)->where('pid',0)->like('title');
  31. $query->dateBetween('create_at')->order('status desc ,sort desc , id desc')->page();
  32. }
  33. /**
  34. * 数据列表处理
  35. * @auth true
  36. * @menu true
  37. * @param array $data
  38. * @throws \think\db\exception\DataNotFoundException
  39. * @throws \think\db\exception\ModelNotFoundException
  40. * @throws \think\exception\DbException
  41. */
  42. protected function _index_page_filter(&$data)
  43. {
  44. foreach ($data as $k=>&$v){
  45. $v['children'] = Db::table('store_goods_cate')->where(['pid'=>$v['id'],'is_deleted'=>0])
  46. ->order('status desc ,sort desc , id desc')
  47. ->select();
  48. }
  49. }
  50. /**
  51. * 添加分类
  52. * @auth true
  53. * @menu true
  54. * @throws \think\Exception
  55. * @throws \think\db\exception\DataNotFoundException
  56. * @throws \think\db\exception\ModelNotFoundException
  57. * @throws \think\exception\DbException
  58. * @throws \think\exception\PDOException
  59. */
  60. public function add()
  61. {
  62. $this->title = '添加分类';
  63. $this->all_cate = Db::table('store_goods_cate')->field('id,title')->where('is_deleted',0)->select();
  64. $this->_form($this->table, 'form');
  65. }
  66. /**
  67. * 编辑分类
  68. * @auth true
  69. * @menu 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 edit()
  77. {
  78. $this->title = '编辑分类';
  79. $this->_form($this->table, 'form');
  80. }
  81. /**
  82. * 禁用
  83. * @auth true
  84. * @menu true
  85. * @throws \think\Exception
  86. * @throws \think\exception\PDOException
  87. */
  88. public function forbidden()
  89. {
  90. $this->_save($this->table, ['status' => '0']);
  91. }
  92. /**
  93. * 启用
  94. * @auth true
  95. * @menu true
  96. * @throws \think\Exception
  97. * @throws \think\exception\PDOException
  98. */
  99. public function enable()
  100. {
  101. $this->_save($this->table, ['status' => 1]);
  102. }
  103. /**
  104. * 删除
  105. * @auth true
  106. * @menu true
  107. * @throws \think\Exception
  108. * @throws \think\exception\PDOException
  109. */
  110. public function del()
  111. {
  112. $this->_save($this->table, ['is_deleted' => 1]);
  113. }
  114. /**
  115. * 表单数据处理
  116. * @auth true
  117. * @menu true
  118. * @param array $data
  119. */
  120. protected function _form_filter(&$data)
  121. {
  122. if ($this->request->isPost()) {
  123. if(!isset($data['id'])){
  124. }
  125. }else{
  126. $this->pid = input('pid',0);
  127. $this->pname = Db::table('store_goods_cate')->where(['id'=>$this->pid])->value('title');
  128. }
  129. }
  130. }