GoodsController.php 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  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 PhpOffice\PhpSpreadsheet\IOFactory;
  29. use app\common\enum\GoodsEnum;
  30. /**
  31. * 商品控制器
  32. * Class GoodsController
  33. * @package app\adminapi\controller\goods
  34. */
  35. class GoodsController extends BaseAdminController
  36. {
  37. public function commonLists()
  38. {
  39. return $this->dataLists(new GoodsCommonLists());
  40. }
  41. /**
  42. * @notes 商品列表
  43. * @return \think\response\Json
  44. * @author cjhao
  45. * @date 2021/7/16 16:51
  46. */
  47. public function lists()
  48. {
  49. return $this->dataLists();
  50. }
  51. /**
  52. * @notes 添加商品
  53. * @return \think\response\Json
  54. * @author cjhao
  55. * @date 2021/7/13 15:05
  56. */
  57. public function add()
  58. {
  59. $params = $this->request->post();
  60. if (GoodsEnum::SEPC_TYPE_MORE == $params['spec_type']) {
  61. $params['server_spec_value_list'] = cartesian_product(array_converting(array_column($params['spec_value'],'spec_list')));
  62. }
  63. (new GoodsValidate())->post()->goCheck('add'); //商品基础信息验证
  64. (new GoodsItemValidate())->post()->goCheck('', $params); //商品规格验证
  65. $res = (new GoodsLogic)->add($params);
  66. if (true === $res) {
  67. return $this->success('添加商品成功',[],1,1);
  68. }
  69. return $this->fail($res);
  70. }
  71. /**
  72. * @notes 编辑商品
  73. * @return \think\response\Json
  74. * @author cjhao
  75. * @date 2021/7/14 17:54
  76. */
  77. public function edit()
  78. {
  79. $params = $this->request->post();
  80. if (GoodsEnum::SEPC_TYPE_MORE == $params['spec_type']) {
  81. $params['server_spec_value_list'] = cartesian_product(array_converting(array_column($params['spec_value'],'spec_list')));
  82. }
  83. (new GoodsValidate())->post()->goCheck('edit', $params); //商品基础信息验证
  84. (new GoodsItemValidate())->post()->goCheck('', $params); //商品规格验证
  85. $res = (new GoodsLogic)->edit($params);
  86. if (true === $res['status'] && $res['is_distribution_goods']) {
  87. // 分销商品
  88. return $this->success('商品信息修改成功,该商品属于分销商品,请重新设置分销信息',[],1,1);
  89. }
  90. if (true === $res['status'] && !$res['is_distribution_goods']) {
  91. // 非分销商品
  92. return $this->success('修改成功',[],1,1);
  93. }
  94. return $this->fail($res['err']);
  95. }
  96. /**
  97. * @notes 获取商品
  98. * @return \think\response\Json
  99. * @author cjhao
  100. * @date 2021/7/15 14:16
  101. */
  102. public function detail(){
  103. $params = (new GoodsValidate())->goCheck('detail');
  104. $detail = (new GoodsLogic)->detail($params['id']);
  105. return $this->success('获取成功',$detail);
  106. }
  107. /**
  108. * @notes 设置商品状态
  109. * @return \think\response\Json
  110. * @author cjhao
  111. * @date 2021/7/17 17:10
  112. */
  113. public function status()
  114. {
  115. $params = (new GoodsValidate())->post()->goCheck('status');
  116. (new GoodsLogic)->status($params);
  117. return $this->success('操作成功',[],1,1);
  118. }
  119. /**
  120. * @notes 设置商品排序
  121. * @return \think\response\Json
  122. * @author cjhao
  123. * @date 2021/7/17 17:16
  124. */
  125. public function sort(){
  126. $params = (new GoodsValidate())->post()->goCheck('sort');
  127. (new GoodsLogic)->sort($params);
  128. return $this->success('操作成功');
  129. }
  130. /**
  131. * @notes 删除商品
  132. * @return \think\response\Json
  133. * @author cjhao
  134. * @date 2021/7/17 18:55
  135. */
  136. public function del(){
  137. $params = (new GoodsValidate())->post()->goCheck('del');
  138. (new GoodsLogic)->del($params['ids']);
  139. return $this->success('删除成功',[],1,1);
  140. }
  141. /**
  142. * @notes 其他列表
  143. * @return \think\response\Json
  144. * @throws \think\db\exception\DataNotFoundException
  145. * @throws \think\db\exception\DbException
  146. * @throws \think\db\exception\ModelNotFoundException
  147. * @author cjhao
  148. * @date 2021/7/22 15:50
  149. */
  150. public function otherList(){
  151. $type = $this->request->get('type','list');
  152. $list = (new GoodsLogic())->otherList($type);
  153. return $this->success('',$list);
  154. }
  155. /**
  156. * @notes 修改商品名称
  157. * @return \think\response\Json
  158. * @author cjhao
  159. * @date 2021/7/29 16:12
  160. */
  161. public function rename(){
  162. $params = (new GoodsValidate())->post()->goCheck('rename');
  163. (new GoodsLogic)->rename($params);
  164. return $this->success('修改成功',[],1,1);
  165. }
  166. /**
  167. * @notes 移动分类
  168. * @return \think\response\Json
  169. * @throws \Exception
  170. * @author ljj
  171. * @date 2023/5/6 2:24 下午
  172. */
  173. pubLic function changeCategory()
  174. {
  175. $params = (new GoodsValidate())->post()->goCheck('changeCategory');
  176. (new GoodsLogic)->changeCategory($params);
  177. return $this->success('修改成功',[],1,1);
  178. }
  179. /**
  180. * @notes 商品规格价格导出
  181. * @return \think\response\Json
  182. * @author
  183. * @date 2024/01/01 00:00
  184. */
  185. public function exportSpecPrice()
  186. {
  187. return $this->dataLists(new \app\adminapi\lists\goods\GoodsSpecPriceLists());
  188. }
  189. /**
  190. * @notes 商品规格价格导入
  191. * @return \think\response\Json
  192. * @author
  193. * @date 2024/01/01 00:00
  194. */
  195. public function importSpecPrice()
  196. {
  197. $lists = IOFactory::load($_FILES['file']['tmp_name'])->getActiveSheet()->toArray(null, true, true, true);
  198. $validate = $this->validate(['lists' => $lists], \app\adminapi\validate\goods\GoodsSpecPriceImport::class);
  199. if ($validate !== true) {
  200. return $this->fail($validate);
  201. }
  202. $result = (new GoodsLogic)->importSpecPriceLists($lists, $_FILES['file']['name']);
  203. if (!is_array($result)) {
  204. return $this->fail($result);
  205. }
  206. return $this->success('导入成功', $result);
  207. }
  208. }