WashCate.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <?php
  2. namespace app\mall\controller;
  3. use library\Controller;
  4. /**
  5. * 分类管理
  6. * Class WashCate
  7. * @package app\mall\controller
  8. */
  9. class WashCate extends Controller
  10. {
  11. /**
  12. * 当前操作数据库
  13. * @var string
  14. */
  15. protected $table = 'WashCate';
  16. /**
  17. * 分类管理
  18. * @auth true
  19. * @menu true
  20. * @throws \think\Exception
  21. * @throws \think\db\exception\DataNotFoundException
  22. * @throws \think\db\exception\ModelNotFoundException
  23. * @throws \think\exception\DbException
  24. * @throws \think\exception\PDOException
  25. */
  26. public function index()
  27. {
  28. $this->title = '分类管理';
  29. $query = $this->_query($this->table)->where('is_deleted',0)->page(false);
  30. }
  31. /**
  32. * 列表数据处理
  33. * @param array $data
  34. */
  35. protected function _index_page_filter(&$data)
  36. {
  37. }
  38. /**
  39. * 添加分类
  40. * @auth true
  41. * @throws \think\Exception
  42. * @throws \think\db\exception\DataNotFoundException
  43. * @throws \think\db\exception\ModelNotFoundException
  44. * @throws \think\exception\DbException
  45. * @throws \think\exception\PDOException
  46. */
  47. public function add()
  48. {
  49. $this->_form($this->table, 'form');
  50. }
  51. /**
  52. * 编辑分类
  53. * @auth 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 edit()
  61. {
  62. $this->_form($this->table, 'form');
  63. }
  64. /**
  65. * 表单数据处理
  66. * @param array $vo
  67. * @throws \ReflectionException
  68. * @throws \think\db\exception\DataNotFoundException
  69. * @throws \think\db\exception\ModelNotFoundException
  70. * @throws \think\exception\DbException
  71. */
  72. protected function _form_filter(&$data)
  73. {
  74. if($this->request->isGet()) {
  75. $this->ladder_set = !empty($data['ladder_set']) ? json_decode($data['ladder_set'],true):[];
  76. }
  77. if($this->request->isPost()) {
  78. // 价格设置
  79. $title_arr= input('post.title');
  80. $price_arr= input('post.price');
  81. $price_param = [];
  82. if(empty($price_arr) || empty($title_arr)) $this->error('请设置价格');
  83. foreach ($title_arr as $k=>$t){
  84. $price_param[] = ['title'=>$t,'price'=>bcadd($price_arr[$k],0,2),'ladder_key'=>$k];
  85. }
  86. $data['ladder_set'] = json_encode($price_param);
  87. }
  88. }
  89. /**
  90. * 启用分类
  91. * @auth true
  92. * @throws \think\Exception
  93. * @throws \think\exception\PDOException
  94. */
  95. public function resume()
  96. {
  97. $this->_save($this->table, ['status' => '1']);
  98. }
  99. /**
  100. * 禁用分类
  101. * @auth true
  102. * @throws \think\Exception
  103. * @throws \think\exception\PDOException
  104. */
  105. public function forbid()
  106. {
  107. $this->_save($this->table, ['status' => '0']);
  108. }
  109. /**
  110. * 删除分类
  111. * @auth true
  112. * @throws \think\Exception
  113. * @throws \think\exception\PDOException
  114. */
  115. public function remove()
  116. {
  117. $this->_delete($this->table);
  118. }
  119. }