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.

173 lines
6.8 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
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
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. return $this->success($res);
  104. }
  105. public function info()
  106. {
  107. $goodsId = $this->request->input('goods_id',0);
  108. $goods = $this->goodsService->info($goodsId);
  109. $goods['secend'] = Category::find($goods['category_id']);
  110. $goods['first'] = Category::find($goods['secend']['parent_id']);
  111. if(!empty($goods['goods_category_id'])){
  112. $goods['third'] = GoodsCategory::find($goods['goods_category_id']);
  113. }else{
  114. $goods['third'] = null;
  115. }
  116. $first = $this->categoryService->getByParentId(0);
  117. $secend = $this->categoryService->getByParentId($goods['first']['id']);
  118. $third = $this->categoryService->getThird($goods['category_id']);
  119. $tags = $this->goodsService->getTags();
  120. return $this->success([
  121. 'goods' => $goods,
  122. 'first' => $first,
  123. 'secend' => $secend,
  124. 'third' => $third,
  125. 'tags' => $tags
  126. ]);
  127. }
  128. public function create(GoodsEditorRequest $request)
  129. {
  130. $data['id'] = $this->request->input('id',0);
  131. $data['market_id'] = $this->request->input('market_id',0);
  132. $data['store_id'] = $this->request->input('store_id',0);
  133. $data['name'] = $this->request->input('name','');
  134. $data['category_id'] = $this->request->input('category_id',0);
  135. $data['goods_category_id'] = $this->request->input('goods_category_id',0);
  136. $data['goods_unit'] = $this->request->input('goods_unit','');
  137. $data['price'] = $this->request->input('price',0);
  138. $data['original_price'] = $this->request->input('original_price',0);
  139. $data['inventory'] = $this->request->input('inventory',0);
  140. $data['restrict_num'] = $this->request->input('restrict_num',0);
  141. $data['start_num'] = $this->request->input('start_num',0);
  142. $data['spec'] = $this->request->input('spec');
  143. $data['tags'] = $this->request->input('tags');
  144. $data['remark'] = $this->request->input('remark','');
  145. $data['on_sale'] = $this->request->input('on_sale',0);
  146. $data['is_infinite'] = $this->request->input('is_infinite',0);
  147. $data['user_id'] = $this->request->input('user_id',0);
  148. $res = $this->goodsService->create($data);
  149. return $this->success($res);
  150. }
  151. public function getTags()
  152. {
  153. $tags = $this->goodsService->getTags();
  154. return $this->success(['tags' => $tags]);
  155. }
  156. public function updateOnSale()
  157. {
  158. $goodsId = $this->request->input('id',0);
  159. return $this->success($this->goodsService->updateOnSale($goodsId));
  160. }
  161. }