StoreProduct.php 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2023 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\outapi\controller;
  12. use app\services\order\StoreCartServices;
  13. use app\services\product\product\StoreCategoryServices;
  14. use app\services\product\product\OutStoreProductServices;
  15. use think\facade\App;
  16. /**
  17. * Class StoreProduct
  18. * @package aapp\outapi\controller
  19. */
  20. class StoreProduct extends AuthController
  21. {
  22. protected $services;
  23. public function __construct(App $app, OutStoreProductServices $services)
  24. {
  25. parent::__construct($app);
  26. $this->services = $services;
  27. }
  28. /**
  29. * 显示资源列表
  30. * @return mixed
  31. */
  32. public function index()
  33. {
  34. $where = $this->request->getMore([
  35. ['cate_id', ''],
  36. ['store_name', ''],
  37. ['type', 1],
  38. ['is_live', 0],
  39. ['is_new', ''],
  40. ['is_virtual', -1],
  41. ['is_presale', -1]
  42. ]);
  43. $where['is_del'] = 0;
  44. /** @var StoreCategoryServices $storeCategoryServices */
  45. $storeCategoryServices = app()->make(StoreCategoryServices::class);
  46. if ($where['cate_id'] !== '') {
  47. if ($storeCategoryServices->value(['id' => $where['cate_id']], 'pid')) {
  48. $where['sid'] = $where['cate_id'];
  49. } else {
  50. $where['cid'] = $where['cate_id'];
  51. }
  52. }
  53. unset($where['cate_id']);
  54. $list = $this->services->searchList($where);
  55. return app('json')->success($list);
  56. }
  57. /**
  58. * 修改状态
  59. * @param string $id
  60. * @param string $is_show
  61. */
  62. public function set_show($id = '', $is_show = '')
  63. {
  64. if ($id == '' || $is_show == '') return app('json')->fail(100100);
  65. $this->services->setShow((int)$id, (int)$is_show);
  66. return app('json')->success($is_show == 1 ? 100003 : 100004);
  67. }
  68. /**
  69. * 获取商品信息
  70. * @param $id
  71. * @throws \think\db\exception\DataNotFoundException
  72. * @throws \think\db\exception\DbException
  73. * @throws \think\db\exception\ModelNotFoundException
  74. */
  75. public function read($id = 0)
  76. {
  77. return app('json')->success($this->services->getInfo((int)$id));
  78. }
  79. /**
  80. * 保存
  81. * @return mixed
  82. * @throws \Exception
  83. */
  84. public function save()
  85. {
  86. $data = $this->request->postMore([
  87. ['cate_id', []],//分类id
  88. ['store_name', ''],//商品名称
  89. ['keyword', ''],//关键字
  90. ['unit_name', '件'],//单位
  91. ['store_info', ''],//商品简介
  92. ['slider_image', []],//轮播图
  93. ['video_open', 0],//是否开启视频
  94. ['video_link', ''],//视频链接
  95. ['spec_type', 0],//单多规格
  96. ['items', []],//规格
  97. ['attrs', []],//规格
  98. ['description', ''],//商品详情
  99. ['description_images', []],//商品详情
  100. ['logistics', []],//物流方式
  101. ['freight', 1],//运费设置
  102. ['postage', 0],//邮费
  103. ['is_sub', 0],//佣金是单独还是默认
  104. ['is_vip', 0],//付费会员价
  105. ['recommend', []],//商品推荐
  106. ['temp_id', 0],//运费模版id
  107. ['give_integral', 0],//赠送积分
  108. ['presale', 0],//预售商品开关
  109. ['presale_time', 0],//预售时间
  110. ['presale_day', 0],//预售发货日
  111. ['vip_product', 0],//是否付费会员商品
  112. ['activity', []],//活动优先级
  113. ['command_word', ''],//商品口令
  114. ['is_show', 0],//是否上架
  115. ['ficti', 0],//虚拟销量
  116. ['sort', 0],//排序
  117. ['recommend_image', ''],//商品推荐图
  118. ['custom_form', []],//自定义表单
  119. ['is_limit', 0],//是否限购
  120. ['limit_type', 0],//限购类型
  121. ['limit_num', 0]//限购数量
  122. ]);
  123. $id = $this->services->save(0, $data);
  124. return app('json')->success(100000, ['id' => $id]);
  125. }
  126. /**
  127. * 更新
  128. * @param $id
  129. * @return mixed
  130. */
  131. public function update($id)
  132. {
  133. $data = $this->request->postMore([
  134. ['cate_id', []],//分类id
  135. ['store_name', ''],//商品名称
  136. ['keyword', ''],//关键字
  137. ['unit_name', '件'],//单位
  138. ['store_info', ''],//商品简介
  139. ['slider_image', []],//轮播图
  140. ['video_open', 0],//是否开启视频
  141. ['video_link', ''],//视频链接
  142. ['spec_type', 0],//单多规格
  143. ['items', []],//规格
  144. ['attrs', []],//规格
  145. ['description', ''],//商品详情
  146. ['description_images', []],//商品详情
  147. ['logistics', []],//物流方式
  148. ['freight', 1],//运费设置
  149. ['postage', 0],//邮费
  150. ['is_sub', 0],//佣金是单独还是默认
  151. ['is_vip', 0],//付费会员价
  152. ['recommend', []],//商品推荐
  153. ['temp_id', 0],//运费模版id
  154. ['give_integral', 0],//赠送积分
  155. ['presale', 0],//预售商品开关
  156. ['presale_time', 0],//预售时间
  157. ['presale_day', 0],//预售发货日
  158. ['vip_product', 0],//是否付费会员商品
  159. ['activity', []],//活动优先级
  160. ['command_word', ''],//商品口令
  161. ['is_show', 0],//是否上架
  162. ['ficti', 0],//虚拟销量
  163. ['sort', 0],//排序
  164. ['recommend_image', ''],//商品推荐图
  165. ['custom_form', []],//自定义表单
  166. ['is_limit', 0],//是否限购
  167. ['limit_type', 0],//限购类型
  168. ['limit_num', 0]//限购数量
  169. ]);
  170. $this->services->save((int)$id, $data);
  171. return app('json')->success(100001);
  172. }
  173. /**
  174. * 删除
  175. * @param int $id
  176. * @return \think\Response
  177. */
  178. public function delete($id)
  179. {
  180. //删除商品检测是否有参与活动
  181. $this->services->checkActivity($id);
  182. $res = $this->services->del($id);
  183. /** @var StoreCartServices $cartService */
  184. $cartService = app()->make(StoreCartServices::class);
  185. $cartService->changeStatus($id, 0);
  186. return app('json')->success($res);
  187. }
  188. /**
  189. * 同步库存
  190. * @return void
  191. */
  192. public function uploadStock()
  193. {
  194. [$items] = $this->request->postMore([['items', []]], true);
  195. foreach ($items as $item) {
  196. if (!isset($item['bar_code']) || !isset($item['qty'])) {
  197. return app('json')->fail(400742);
  198. }
  199. }
  200. if (count($items) > 100) {
  201. return app('json')->fail(400743);
  202. }
  203. $this->services->syncStock($items);
  204. return app('json')->success(100010);
  205. }
  206. }