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.

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