Good.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. 'type' => ''
  22. ], 'post');
  23. return GoodLogic::list($param);
  24. }
  25. //添加商品
  26. public function add()
  27. {
  28. $param = $this->request->only([
  29. 'good_cover_img',
  30. 'good_name',
  31. 'moq',
  32. 'step',
  33. 'good_banner_img',
  34. 'good_img',
  35. 'good_param',
  36. 'unit_id',
  37. 'type',
  38. 'price' => 0,
  39. 'good_remark' => '',
  40. ], 'post');
  41. validate(GoodValidate::class)->scene('add')->check($param);
  42. return GoodLogic::add($param);
  43. }
  44. //读取商品详情
  45. public function read()
  46. {
  47. $id = $this->request->post('id/d', 0);
  48. validate(GoodValidate::class)->scene('read')->check(['id' => $id]);
  49. return GoodLogic::read($id);
  50. }
  51. //编辑商品
  52. public function edit()
  53. {
  54. $param = $this->request->only([
  55. 'id',
  56. 'good_cover_img',
  57. 'good_name',
  58. 'moq',
  59. 'step',
  60. 'price',
  61. 'good_banner_img',
  62. 'good_img',
  63. 'good_param',
  64. 'unit_id',
  65. 'good_remark',
  66. ], 'post');
  67. validate(GoodValidate::class)->scene('edit')->check($param);
  68. return GoodLogic::edit($param);
  69. }
  70. //商品启禁用
  71. public function status()
  72. {
  73. $param = $this->request->only(['id', 'status',], 'post');
  74. $val = Validate::rule(Config::get('validate_rules.status'));
  75. if (!$val->check($param)) throw new ValidateException($val->getError());
  76. return GoodLogic::status($param);
  77. }
  78. //删除商品
  79. public function delete()
  80. {
  81. $id = $this->request->post('id/d', 0);
  82. return GoodLogic::delete($id);
  83. }
  84. }