Good.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. namespace app\admin\controller;
  3. use app\admin\logic\GoodLogic;
  4. use app\admin\validate\GoodValidate;
  5. use app\BaseController;
  6. use think\exception\ValidateException;
  7. use think\facade\Config;
  8. use think\facade\Validate;
  9. //商品
  10. class Good extends BaseController
  11. {
  12. //获取商品列表
  13. public function list()
  14. {
  15. $param = $this->request->only([
  16. 'page' => 1,
  17. 'size' => 10,
  18. 'good_code' => '',
  19. 'good_name' => '',
  20. 'status' => '',
  21. ], 'post');
  22. return GoodLogic::list($param);
  23. }
  24. //添加商品
  25. public function add()
  26. {
  27. $param = $this->request->only([
  28. 'good_cover_img',
  29. 'good_name',
  30. 'moq',
  31. 'step',
  32. 'good_banner_img',
  33. 'good_img',
  34. 'good_param',
  35. 'unit_id',
  36. 'good_remark' => '',
  37. ], 'post');
  38. validate(GoodValidate::class)->scene('add')->check($param);
  39. return GoodLogic::add($param);
  40. }
  41. //读取商品详情
  42. public function read()
  43. {
  44. $id = $this->request->post('id/d', 0);
  45. return GoodLogic::read($id);
  46. }
  47. //编辑商品
  48. public function edit()
  49. {
  50. $param = $this->request->only([
  51. 'id',
  52. 'good_cover_img',
  53. 'good_name',
  54. 'moq',
  55. 'step',
  56. 'good_banner_img',
  57. 'good_img',
  58. 'good_param',
  59. 'unit_id',
  60. 'good_remark',
  61. ], 'post');
  62. validate(GoodValidate::class)->scene('edit')->check($param);
  63. return GoodLogic::edit($param);
  64. }
  65. //商品启禁用
  66. public function status()
  67. {
  68. $param = $this->request->only(['id', 'status',], 'post');
  69. $val = Validate::rule(Config::get('validate_rules.status'));
  70. if (!$val->check($param)) throw new ValidateException($val->getError());
  71. return GoodLogic::status($param);
  72. }
  73. //删除商品
  74. public function delete()
  75. {
  76. $id = $this->request->post('id/d', 0);
  77. return GoodLogic::delete($id);
  78. }
  79. }