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.

69 lines
2.3 KiB

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\Service\v3\Interfaces\ShopCartServiceInterface;
  5. use App\Service\v3\Implementations\GoodsActivityService;
  6. use App\Service\v3\Interfaces\CollectStoreServiceInterface;
  7. use Hyperf\Di\Annotation\Inject;
  8. use App\Service\v3\Interfaces\GoodsServiceInterface;
  9. use App\Service\v3\Interfaces\GoodsActivityServiceInterface;
  10. use App\Constants\v3\Goods;
  11. use App\Request\v3\GoodsRequest;
  12. class GoodsController extends BaseController
  13. {
  14. /**
  15. * @Inject
  16. * @var GoodsServiceInterface
  17. */
  18. protected $goodsService;
  19. /**
  20. * @Inject
  21. * @var GoodsActivityServiceInterface
  22. */
  23. protected $goodsActivityService;
  24. /**
  25. * @Inject
  26. * @var CollectStoreServiceInterface
  27. */
  28. protected $collectService;
  29. /**
  30. * @Inject
  31. * @var ShopCartServiceInterface
  32. */
  33. protected $shopCartService;
  34. public function detail(GoodsRequest $request)
  35. {
  36. $params = $this->request->all();
  37. $activity = $this->request->input('activity',1);
  38. $goodsId = $this->request->input('goods_id',0);
  39. $marketId = $this->request->input('market_id',0);
  40. //判断是普通商品还是特价商品
  41. if($activity == Goods::IS_ACTIVITY){
  42. $res['detail'] = $this->goodsActivityService->detail($goodsId);
  43. $res['banner'] = $this->goodsActivityService->getBanner($goodsId);
  44. }else{
  45. $res['detail'] = $this->goodsService->detail($goodsId);
  46. $res['banner'] = $this->goodsService->getBanner($goodsId);
  47. }
  48. //如果没有banner数据,使用商品cover图
  49. if(count($res['banner']) == 0){
  50. $res['banner'] = [$res['detail']['cover_img']];
  51. }
  52. //如果存在用户ID则请求 购物车和收藏店铺信息
  53. if(isset($params['user_id'])) {
  54. $res['shopcart']['count'] = $this->shopCartService->countGoods($params['user_id'],$marketId);
  55. $res['shopcart']['total'] = $this->shopCartService->getTotal($params['user_id'],$marketId);
  56. $res['detail']->store->is_collected = (bool)$this->collectService->check($params['user_id'], $res['detail']->store->id);
  57. }else{
  58. $res['shopcart'] = '';
  59. $res['detail']->store->is_collected = '';
  60. }
  61. return $this->success($res);
  62. }
  63. }