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.

131 lines
4.3 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
  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. $res = $this->goodsService->update($this->request->all());
  85. return $this->success($res);
  86. }
  87. public function info()
  88. {
  89. $goodsId = $this->request->input('goods_id',0);
  90. $goods = $this->goodsService->info($goodsId);
  91. $goods['secend'] = Category::find($goods['category_id']);
  92. $goods['first'] = Category::find($goods['secend']['parent_id']);
  93. if(!empty($goods['goods_category_id'])){
  94. $goods['third'] = GoodsCategory::find($goods['goods_category_id']);
  95. }else{
  96. $goods['third'] = null;
  97. }
  98. $first = $this->categoryService->getByParentId(0);
  99. $secend = $this->categoryService->getByParentId($goods['category_id']);
  100. $third = $this->categoryService->getThird($goods['category_id']);
  101. $tags = $this->goodsService->getTags();
  102. return $this->success([
  103. 'goods' => $goods,
  104. 'first' => $first,
  105. 'secend' => $secend,
  106. 'third' => $third,
  107. 'tags' => $tags
  108. ]);
  109. }
  110. public function create(GoodsEditorRequest $request)
  111. {
  112. $res = $this->goodsService->create($this->request->all());
  113. return $this->success($res);
  114. }
  115. public function getTags()
  116. {
  117. $tags = $this->goodsService->getTags();
  118. return $this->success(['tags' => $tags]);
  119. }
  120. }