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.

195 lines
7.6 KiB

6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 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. $data['cover_img'] = $this->request->input('cover_img',0);
  103. $banners = $this->request->input('banner',0);
  104. $res = $this->goodsService->update($data);
  105. if(!empty($banners)){
  106. $banners = explode(',',$banners);
  107. foreach ($banners as $banner){
  108. $this->goodsService->bannerCreate($data['id'],$banner,1);
  109. }
  110. }
  111. return $this->success($res);
  112. }
  113. public function info()
  114. {
  115. $goodsId = $this->request->input('goods_id',0);
  116. $goods = $this->goodsService->info($goodsId);
  117. $goods['secend'] = Category::find($goods['category_id']);
  118. $goods['first'] = Category::find($goods['secend']['parent_id']);
  119. if(!empty($goods['goods_category_id'])){
  120. $goods['third'] = GoodsCategory::find($goods['goods_category_id']);
  121. }else{
  122. $goods['third'] = null;
  123. }
  124. $first = $this->categoryService->getByParentId(0);
  125. $secend = $this->categoryService->getByParentId($goods['first']['id']);
  126. $third = $this->categoryService->getThird($goods['category_id']);
  127. $tags = $this->goodsService->getTags();
  128. return $this->success([
  129. 'goods' => $goods,
  130. 'first' => $first,
  131. 'secend' => $secend,
  132. 'third' => $third,
  133. 'tags' => $tags
  134. ]);
  135. }
  136. public function create(GoodsEditorRequest $request)
  137. {
  138. $data['id'] = $this->request->input('id',0);
  139. $data['market_id'] = $this->request->input('market_id',0);
  140. $data['store_id'] = $this->request->input('store_id',0);
  141. $data['name'] = $this->request->input('name','');
  142. $data['category_id'] = $this->request->input('category_id',0);
  143. $data['goods_category_id'] = $this->request->input('goods_category_id',0);
  144. $data['goods_unit'] = $this->request->input('goods_unit','');
  145. $data['price'] = $this->request->input('price',0);
  146. $data['original_price'] = $this->request->input('original_price',0);
  147. $data['inventory'] = $this->request->input('inventory',0);
  148. $data['restrict_num'] = $this->request->input('restrict_num',0);
  149. $data['start_num'] = $this->request->input('start_num',0);
  150. $data['spec'] = $this->request->input('spec');
  151. $data['tags'] = $this->request->input('tags');
  152. $data['remark'] = $this->request->input('remark','');
  153. $data['on_sale'] = $this->request->input('on_sale',0);
  154. $data['is_infinite'] = $this->request->input('is_infinite',0);
  155. $data['user_id'] = $this->request->input('user_id',0);
  156. $data['cover_img'] = $this->request->input('cover_img',0);
  157. $banners = $this->request->input('banner',0);
  158. $res = $this->goodsService->create($data);
  159. if(!empty($banners)){
  160. $banners = explode(',',$banners);
  161. foreach ($banners as $banner){
  162. $this->goodsService->bannerCreate($res['id'],$banner,1);
  163. }
  164. }
  165. return $this->success($res);
  166. }
  167. public function getTags()
  168. {
  169. $tags = $this->goodsService->getTags();
  170. return $this->success(['tags' => $tags]);
  171. }
  172. public function updateOnSale()
  173. {
  174. $goodsId = $this->request->input('id',0);
  175. return $this->success($this->goodsService->updateOnSale($goodsId));
  176. }
  177. public function bannerDelete()
  178. {
  179. $bannerId = $this->request->input('banner_id',0);
  180. return $this->success($this->goodsService->bannerDelete($bannerId));
  181. }
  182. }