EntityGoodsController.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <?php
  2. namespace app\admin\controller\goods;
  3. use app\admin\service\goods\GoodsService;
  4. use app\admin\validate\goods\GoodsValidate;
  5. use app\model\GoodsDetail;
  6. use support\Request;
  7. use support\Response;
  8. class EntityGoodsController
  9. {
  10. /**
  11. * @Desc 列表
  12. * @Author Gorden
  13. * @Date 2024/3/28 10:08
  14. *
  15. * @param Request $request
  16. * @return Response
  17. */
  18. public function select(Request $request)
  19. {
  20. return GoodsService::select($request, 'GOODS');
  21. }
  22. public function selectAll(Request $request)
  23. {
  24. $goodsIds = $request->get('goods_id', '');
  25. return GoodsService::selectAll($goodsIds);
  26. }
  27. public function selectAllByGoodsName(Request $request)
  28. {
  29. $goodsName = $request->get('goods_name', '');
  30. if (!$goodsName) {
  31. return json_fail("请输入要搜索的产品");
  32. }
  33. return GoodsService::selectAllByGoodsName($goodsName);
  34. }
  35. public function selectAllByCategoryForRuleAddComponent(Request $request)
  36. {
  37. $category = $request->get('category', 'GOODS');
  38. return GoodsService::selectAllByCategoryForRuleAddComponent($category);
  39. }
  40. public function selectPremisesByGoodsId(Request $request)
  41. {
  42. return GoodsService::selectPremisesByGoodsId($request->get('goods_id'));
  43. }
  44. /**
  45. * @Desc 商品详情
  46. * @Author Gorden
  47. * @Date 2024/3/28 10:25
  48. *
  49. * @param Request $request
  50. * @return Response
  51. */
  52. public function info(Request $request)
  53. {
  54. $validate = new GoodsValidate();
  55. if (!$validate->scene('info')->check($request->get())) {
  56. return json_fail($validate->getError());
  57. }
  58. return GoodsService::info($request->get('goods_id'));
  59. }
  60. /**
  61. * @Desc 添加商品
  62. * @Author Gorden
  63. * @Date 2024/3/11 10:21
  64. *
  65. * @param Request $request
  66. * @return Response
  67. */
  68. public function insert(Request $request): Response
  69. {
  70. $params = $request->post();
  71. $validate = new GoodsValidate();
  72. if (!$validate->scene('add')->check($params)) {
  73. return json_fail($validate->getError());
  74. }
  75. $params['goods_classify'] = $params['goods_classify'] ?? 'GOODS';
  76. return GoodsService::insert($params);
  77. }
  78. /**
  79. * @Desc 修改商品
  80. * @Author Gorden
  81. * @Date 2024/3/28 13:22
  82. *
  83. * @param Request $request
  84. * @return Response
  85. */
  86. public function update(Request $request): Response
  87. {
  88. $validate = new GoodsValidate();
  89. if (!$validate->scene('update')->check($request->post())) {
  90. return json_fail($validate->getError());
  91. }
  92. return GoodsService::update($request->post());
  93. }
  94. /**
  95. * @Desc 删除商品
  96. * @Author Gorden
  97. * @Date 2024/3/28 13:22
  98. *
  99. * @param Request $request
  100. * @return Response
  101. */
  102. public function delete(Request $request)
  103. {
  104. $ids = $request->post('goods_id');
  105. return GoodsService::delete($ids);
  106. }
  107. }