GoodsController.php 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | likeshop100%开源免费商用商城系统
  4. // +----------------------------------------------------------------------
  5. // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
  6. // | 开源版本可自由商用,可去除界面版权logo
  7. // | 商业版本务必购买商业授权,以免引起法律纠纷
  8. // | 禁止对系统程序代码以任何目的,任何形式的再发布
  9. // | gitee下载:https://gitee.com/likeshop_gitee
  10. // | github下载:https://github.com/likeshop-github
  11. // | 访问官网:https://www.likeshop.cn
  12. // | 访问社区:https://home.likeshop.cn
  13. // | 访问手册:http://doc.likeshop.cn
  14. // | 微信公众号:likeshop技术社区
  15. // | likeshop团队 版权所有 拥有最终解释权
  16. // +----------------------------------------------------------------------
  17. // | author: likeshopTeam
  18. // +----------------------------------------------------------------------
  19. namespace app\adminapi\controller\goods;
  20. use app\common\model\DistributionGoods;
  21. use app\adminapi\{
  22. logic\goods\GoodsLogic,
  23. validate\goods\GoodsValidate,
  24. lists\goods\GoodsCommonLists,
  25. controller\BaseAdminController,
  26. validate\goods\GoodsItemValidate,
  27. };
  28. use app\common\enum\GoodsEnum;
  29. /**
  30. * 商品控制器
  31. * Class GoodsController
  32. * @package app\adminapi\controller\goods
  33. */
  34. class GoodsController extends BaseAdminController
  35. {
  36. public function commonLists()
  37. {
  38. return $this->dataLists(new GoodsCommonLists());
  39. }
  40. /**
  41. * @notes 商品列表
  42. * @return \think\response\Json
  43. * @author cjhao
  44. * @date 2021/7/16 16:51
  45. */
  46. public function lists()
  47. {
  48. return $this->dataLists();
  49. }
  50. /**
  51. * @notes 添加商品
  52. * @return \think\response\Json
  53. * @author cjhao
  54. * @date 2021/7/13 15:05
  55. */
  56. public function add()
  57. {
  58. $params = $this->request->post();
  59. if (GoodsEnum::SEPC_TYPE_MORE == $params['spec_type']) {
  60. $params['server_spec_value_list'] = cartesian_product(array_converting(array_column($params['spec_value'],'spec_list')));
  61. }
  62. (new GoodsValidate())->post()->goCheck('add'); //商品基础信息验证
  63. (new GoodsItemValidate())->post()->goCheck('', $params); //商品规格验证
  64. $res = (new GoodsLogic)->add($params);
  65. if (true === $res) {
  66. return $this->success('添加商品成功',[],1,1);
  67. }
  68. return $this->fail($res);
  69. }
  70. /**
  71. * @notes 编辑商品
  72. * @return \think\response\Json
  73. * @author cjhao
  74. * @date 2021/7/14 17:54
  75. */
  76. public function edit()
  77. {
  78. $params = $this->request->post();
  79. if (GoodsEnum::SEPC_TYPE_MORE == $params['spec_type']) {
  80. $params['server_spec_value_list'] = cartesian_product(array_converting(array_column($params['spec_value'],'spec_list')));
  81. }
  82. (new GoodsValidate())->post()->goCheck('edit', $params); //商品基础信息验证
  83. (new GoodsItemValidate())->post()->goCheck('', $params); //商品规格验证
  84. $res = (new GoodsLogic)->edit($params);
  85. if (true === $res['status'] && $res['is_distribution_goods']) {
  86. // 分销商品
  87. return $this->success('商品信息修改成功,该商品属于分销商品,请重新设置分销信息',[],1,1);
  88. }
  89. if (true === $res['status'] && !$res['is_distribution_goods']) {
  90. // 非分销商品
  91. return $this->success('修改成功',[],1,1);
  92. }
  93. return $this->fail($res['err']);
  94. }
  95. /**
  96. * @notes 获取商品
  97. * @return \think\response\Json
  98. * @author cjhao
  99. * @date 2021/7/15 14:16
  100. */
  101. public function detail(){
  102. $params = (new GoodsValidate())->goCheck('detail');
  103. $detail = (new GoodsLogic)->detail($params['id']);
  104. return $this->success('获取成功',$detail);
  105. }
  106. /**
  107. * @notes 设置商品状态
  108. * @return \think\response\Json
  109. * @author cjhao
  110. * @date 2021/7/17 17:10
  111. */
  112. public function status()
  113. {
  114. $params = (new GoodsValidate())->post()->goCheck('status');
  115. (new GoodsLogic)->status($params);
  116. return $this->success('操作成功',[],1,1);
  117. }
  118. /**
  119. * @notes 设置商品排序
  120. * @return \think\response\Json
  121. * @author cjhao
  122. * @date 2021/7/17 17:16
  123. */
  124. public function sort(){
  125. $params = (new GoodsValidate())->post()->goCheck('sort');
  126. (new GoodsLogic)->sort($params);
  127. return $this->success('操作成功');
  128. }
  129. /**
  130. * @notes 删除商品
  131. * @return \think\response\Json
  132. * @author cjhao
  133. * @date 2021/7/17 18:55
  134. */
  135. public function del(){
  136. $params = (new GoodsValidate())->post()->goCheck('del');
  137. (new GoodsLogic)->del($params['ids']);
  138. return $this->success('删除成功',[],1,1);
  139. }
  140. /**
  141. * @notes 其他列表
  142. * @return \think\response\Json
  143. * @throws \think\db\exception\DataNotFoundException
  144. * @throws \think\db\exception\DbException
  145. * @throws \think\db\exception\ModelNotFoundException
  146. * @author cjhao
  147. * @date 2021/7/22 15:50
  148. */
  149. public function otherList(){
  150. $type = $this->request->get('type','list');
  151. $list = (new GoodsLogic())->otherList($type);
  152. return $this->success('',$list);
  153. }
  154. /**
  155. * @notes 修改商品名称
  156. * @return \think\response\Json
  157. * @author cjhao
  158. * @date 2021/7/29 16:12
  159. */
  160. public function rename(){
  161. $params = (new GoodsValidate())->post()->goCheck('rename');
  162. (new GoodsLogic)->rename($params);
  163. return $this->success('修改成功',[],1,1);
  164. }
  165. /**
  166. * @notes 移动分类
  167. * @return \think\response\Json
  168. * @throws \Exception
  169. * @author ljj
  170. * @date 2023/5/6 2:24 下午
  171. */
  172. pubLic function changeCategory()
  173. {
  174. $params = (new GoodsValidate())->post()->goCheck('changeCategory');
  175. (new GoodsLogic)->changeCategory($params);
  176. return $this->success('修改成功',[],1,1);
  177. }
  178. /**
  179. * @notes 商品规格价格导出
  180. * @return \think\response\Json
  181. * @author
  182. * @date 2024/01/01 00:00
  183. */
  184. public function exportSpecPrice()
  185. {
  186. return $this->dataLists(new \app\adminapi\lists\goods\GoodsSpecPriceLists());
  187. }
  188. /**
  189. * @notes 商品规格价格导入
  190. * @return \think\response\Json
  191. * @author
  192. * @date 2024/01/01 00:00
  193. */
  194. public function importSpecPrice()
  195. {
  196. $params = (new \app\adminapi\validate\goods\GoodsSpecPriceValidate())->post()->goCheck('import');
  197. $result = (new GoodsLogic)->importSpecPrice($params);
  198. if ($result === true) {
  199. return $this->success('导入成功', [], 1, 1);
  200. }
  201. return $this->fail($result);
  202. }
  203. }