StoreProductParam.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <?php
  2. namespace app\adminapi\controller\v1\product;
  3. use app\adminapi\controller\AuthController;
  4. use app\services\product\product\StoreProductParamServices;
  5. use think\facade\App;
  6. /**
  7. * 商品参数
  8. * @author wuhaotian
  9. * @email 442384644@qq.com
  10. * @date 2024/12/17
  11. */
  12. class StoreProductParam extends AuthController
  13. {
  14. /**
  15. * @param App $app
  16. * @param StoreProductParamServices $services
  17. */
  18. public function __construct(App $app, StoreProductParamServices $services)
  19. {
  20. parent::__construct($app);
  21. $this->services = $services;
  22. }
  23. /**
  24. * 获取参数列表
  25. * @return \think\Response
  26. * @throws \think\db\exception\DataNotFoundException
  27. * @throws \think\db\exception\DbException
  28. * @throws \think\db\exception\ModelNotFoundException
  29. * @author wuhaotian
  30. * @email 442384644@qq.com
  31. * @date 2024/12/17
  32. */
  33. public function getParamList()
  34. {
  35. $where = $this->request->getMore([
  36. ['name', '']
  37. ]);
  38. return app('json')->success($this->services->getParamList($where));
  39. }
  40. /**
  41. * 获取参数详情
  42. * @param $id
  43. * @return \think\Response
  44. * @throws \think\db\exception\DataNotFoundException
  45. * @throws \think\db\exception\DbException
  46. * @throws \think\db\exception\ModelNotFoundException
  47. * @author wuhaotian
  48. * @email 442384644@qq.com
  49. * @date 2024/12/17
  50. */
  51. public function getParamInfo($id)
  52. {
  53. if (!$id) return app('json')->fail('参数错误');
  54. $info = $this->services->getParamInfo($id);
  55. return app('json')->success($info);
  56. }
  57. /**
  58. * 获取参数值
  59. * @param $id
  60. * @return \think\Response
  61. * @author wuhaotian
  62. * @email 442384644@qq.com
  63. * @date 2024/12/17
  64. */
  65. public function getParamValue($id)
  66. {
  67. if (!$id) return app('json')->fail('参数错误');
  68. $info = $this->services->getParamValue($id);
  69. return app('json')->success($info);
  70. }
  71. /**
  72. * 保存参数
  73. * @param $id
  74. * @return \think\Response
  75. * @author wuhaotian
  76. * @email 442384644@qq.com
  77. * @date 2024/12/17
  78. */
  79. public function saveParamData($id)
  80. {
  81. $data = $this->request->postMore([
  82. ['name', ''],
  83. ['value', []],
  84. ['sort', 0],
  85. ['status', 1]
  86. ]);
  87. if (!$data['name']) return app('json')->fail('请输入参数名称');
  88. if (!count($data['value'])) return app('json')->fail('请输入参数值');
  89. $this->services->saveParamData($id, $data);
  90. return app('json')->success('保存成功');
  91. }
  92. /**
  93. * 修改参数状态
  94. * @param $id
  95. * @param $status
  96. * @return \think\Response
  97. * @author wuhaotian
  98. * @email 442384644@qq.com
  99. * @date 2024/12/17
  100. */
  101. public function setParamStatus($id, $status)
  102. {
  103. if (!$id) return app('json')->fail('参数错误');
  104. $this->services->setParamStatus($id, $status);
  105. return app('json')->success('修改成功');
  106. }
  107. /**
  108. * 删除参数
  109. * @param $id
  110. * @return \think\Response
  111. * @author wuhaotian
  112. * @email 442384644@qq.com
  113. * @date 2024/12/17
  114. */
  115. public function delParamData($id)
  116. {
  117. if (!$id) return app('json')->fail('参数错误');
  118. $this->services->delParamData($id);
  119. return app('json')->success('删除成功');
  120. }
  121. }