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.

92 lines
3.0 KiB

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\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. $res['banner'] = [[
  52. 'banner_url' => $res['detail']['cover_img'],
  53. 'goods_id' => $goodsId,
  54. 'type' => 1,
  55. 'path' => $res['detail']['cover_img'],
  56. 'created_at' => '',
  57. 'updated_at' => '',
  58. 'deleted_at' => '',
  59. 'sort' => '',
  60. ]];
  61. }
  62. //如果存在用户ID则请求 购物车和收藏店铺信息
  63. if(isset($params['user_id'])) {
  64. $res['shopcart']['count'] = $this->shopCartService->countGoods($params['user_id'],$marketId);
  65. $res['shopcart']['total'] = $this->shopCartService->getTotal($params['user_id'],$marketId);
  66. $res['detail']->store->is_collected = (bool)$this->collectService->check($params['user_id'], $res['detail']->store->id);
  67. }else{
  68. $res['shopcart'] = '';
  69. $res['detail']->store->is_collected = '';
  70. }
  71. return $this->success($res);
  72. }
  73. public function update()
  74. {
  75. $res = $this->goodsService->update($this->request->all());
  76. return $this->success($res);
  77. }
  78. public function info()
  79. {
  80. $goodsId = $this->request->input('goods_id',0);
  81. $res = $this->goodsService->info($goodsId);
  82. return $this->success($res);
  83. }
  84. }