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.

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