StoreProductParam.php 4.0 KB

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