You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

193 lines
7.5 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
6 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. <?php
  2. namespace App\Controller\v3;
  3. use App\Controller\BaseController;
  4. use App\Model\v3\Category;
  5. use App\Model\v3\GoodsCategory;
  6. use App\Request\v3\GoodsEditorRequest;
  7. use App\Service\v3\Interfaces\CategoryServiceInterface;
  8. use App\Service\v3\Interfaces\ShopCartServiceInterface;
  9. use App\Service\v3\Implementations\GoodsActivityService;
  10. use App\Service\v3\Interfaces\CollectStoreServiceInterface;
  11. use Hyperf\Di\Annotation\Inject;
  12. use App\Service\v3\Interfaces\GoodsServiceInterface;
  13. use App\Service\v3\Interfaces\GoodsActivityServiceInterface;
  14. use App\Constants\v3\Goods;
  15. use App\Request\v3\GoodsRequest;
  16. class GoodsController extends BaseController
  17. {
  18. /**
  19. * @Inject
  20. * @var GoodsServiceInterface
  21. */
  22. protected $goodsService;
  23. /**
  24. * @Inject
  25. * @var GoodsActivityServiceInterface
  26. */
  27. protected $goodsActivityService;
  28. /**
  29. * @Inject
  30. * @var CollectStoreServiceInterface
  31. */
  32. protected $collectService;
  33. /**
  34. * @Inject
  35. * @var ShopCartServiceInterface
  36. */
  37. protected $shopCartService;
  38. /**
  39. * @Inject
  40. * @var CategoryServiceInterface
  41. */
  42. protected $categoryService;
  43. public function detail(GoodsRequest $request)
  44. {
  45. $params = $this->request->all();
  46. $activity = $this->request->input('activity',1);
  47. $goodsId = $this->request->input('goods_id',0);
  48. $marketId = $this->request->input('market_id',0);
  49. //判断是普通商品还是特价商品
  50. if($activity == Goods::IS_ACTIVITY){
  51. $res['detail'] = $this->goodsActivityService->detail($goodsId);
  52. $res['banner'] = $this->goodsActivityService->getBanner($goodsId);
  53. }else{
  54. $res['detail'] = $this->goodsService->detail($goodsId);
  55. $res['banner'] = $this->goodsService->getBanner($goodsId);
  56. }
  57. //如果没有banner数据,使用商品cover图
  58. if(count($res['banner']) == 0){
  59. // $res['banner'] = [$res['detail']['cover_img']];
  60. $res['banner'] = [[
  61. 'banner_url' => $res['detail']['cover_img'],
  62. 'goods_id' => $goodsId,
  63. 'type' => 1,
  64. 'path' => $res['detail']['cover_img'],
  65. 'created_at' => '',
  66. 'updated_at' => '',
  67. 'deleted_at' => '',
  68. 'sort' => '',
  69. ]];
  70. }
  71. //如果存在用户ID则请求 购物车和收藏店铺信息
  72. if(isset($params['user_id'])) {
  73. $res['shopcart']['count'] = $this->shopCartService->countGoods($params['user_id'],$marketId);
  74. $res['shopcart']['total'] = $this->shopCartService->getTotal($params['user_id'],$marketId);
  75. $res['detail']->store->is_collected = (bool)$this->collectService->check($params['user_id'], $res['detail']->store->id);
  76. }else{
  77. $res['shopcart'] = '';
  78. $res['detail']->store->is_collected = '';
  79. }
  80. return $this->success($res);
  81. }
  82. public function update(GoodsEditorRequest $request)
  83. {
  84. $data['id'] = $this->request->input('id',0);
  85. $data['market_id'] = $this->request->input('market_id',0);
  86. $data['store_id'] = $this->request->input('store_id',0);
  87. $data['name'] = $this->request->input('name','');
  88. $data['category_id'] = $this->request->input('category_id',0);
  89. $data['goods_category_id'] = $this->request->input('goods_category_id',0);
  90. $data['goods_unit'] = $this->request->input('goods_unit','');
  91. $data['price'] = $this->request->input('price',0);
  92. $data['original_price'] = $this->request->input('original_price',0);
  93. $data['inventory'] = $this->request->input('inventory',0);
  94. $data['restrict_num'] = $this->request->input('restrict_num',0);
  95. $data['start_num'] = $this->request->input('start_num',0);
  96. $data['spec'] = $this->request->input('spec');
  97. $data['tags'] = $this->request->input('tags');
  98. $data['remark'] = $this->request->input('remark','');
  99. $data['on_sale'] = $this->request->input('on_sale',0);
  100. $data['is_infinite'] = $this->request->input('is_infinite',0);
  101. $data['user_id'] = $this->request->input('user_id',0);
  102. $res = $this->goodsService->update($data);
  103. $banners = $this->request->input('banner',0);
  104. if(!empty($banners)){
  105. $banners = explode(',',$banners);
  106. foreach ($banners as $banner){
  107. $this->goodsService->bannerCreate($data['id'],$banner,1);
  108. }
  109. }
  110. return $this->success($res);
  111. }
  112. public function info()
  113. {
  114. $goodsId = $this->request->input('goods_id',0);
  115. $goods = $this->goodsService->info($goodsId);
  116. $goods['secend'] = Category::find($goods['category_id']);
  117. $goods['first'] = Category::find($goods['secend']['parent_id']);
  118. if(!empty($goods['goods_category_id'])){
  119. $goods['third'] = GoodsCategory::find($goods['goods_category_id']);
  120. }else{
  121. $goods['third'] = null;
  122. }
  123. $first = $this->categoryService->getByParentId(0);
  124. $secend = $this->categoryService->getByParentId($goods['first']['id']);
  125. $third = $this->categoryService->getThird($goods['category_id']);
  126. $tags = $this->goodsService->getTags();
  127. return $this->success([
  128. 'goods' => $goods,
  129. 'first' => $first,
  130. 'secend' => $secend,
  131. 'third' => $third,
  132. 'tags' => $tags
  133. ]);
  134. }
  135. public function create(GoodsEditorRequest $request)
  136. {
  137. $data['id'] = $this->request->input('id',0);
  138. $data['market_id'] = $this->request->input('market_id',0);
  139. $data['store_id'] = $this->request->input('store_id',0);
  140. $data['name'] = $this->request->input('name','');
  141. $data['category_id'] = $this->request->input('category_id',0);
  142. $data['goods_category_id'] = $this->request->input('goods_category_id',0);
  143. $data['goods_unit'] = $this->request->input('goods_unit','');
  144. $data['price'] = $this->request->input('price',0);
  145. $data['original_price'] = $this->request->input('original_price',0);
  146. $data['inventory'] = $this->request->input('inventory',0);
  147. $data['restrict_num'] = $this->request->input('restrict_num',0);
  148. $data['start_num'] = $this->request->input('start_num',0);
  149. $data['spec'] = $this->request->input('spec');
  150. $data['tags'] = $this->request->input('tags');
  151. $data['remark'] = $this->request->input('remark','');
  152. $data['on_sale'] = $this->request->input('on_sale',0);
  153. $data['is_infinite'] = $this->request->input('is_infinite',0);
  154. $data['user_id'] = $this->request->input('user_id',0);
  155. $res = $this->goodsService->create($data);
  156. $banners = $this->request->input('banner',0);
  157. if(!empty($banners)){
  158. $banners = explode(',',$banners);
  159. foreach ($banners as $banner){
  160. $this->goodsService->bannerCreate($res['id'],$banner,1);
  161. }
  162. }
  163. return $this->success($res);
  164. }
  165. public function getTags()
  166. {
  167. $tags = $this->goodsService->getTags();
  168. return $this->success(['tags' => $tags]);
  169. }
  170. public function updateOnSale()
  171. {
  172. $goodsId = $this->request->input('id',0);
  173. return $this->success($this->goodsService->updateOnSale($goodsId));
  174. }
  175. public function bannerDelete()
  176. {
  177. $bannerId = $this->request->input('banner_id',0);
  178. return $this->success($this->goodsService->bannerDelete($bannerId));
  179. }
  180. }