diff --git a/app/Controller/v3/GoodsController.php b/app/Controller/v3/GoodsController.php index 1bd246d..b7fbcf2 100644 --- a/app/Controller/v3/GoodsController.php +++ b/app/Controller/v3/GoodsController.php @@ -39,23 +39,26 @@ class GoodsController extends BaseController public function detail() { $params = $this->request->all(); + $activity = $this->request->input('activity',1); + $goodsId = $this->request->input('goods_id',0); + $marketId = $this->request->input('market_id',0); //判断是普通商品还是特价商品 - if(isset($params['activity']) && $params['activity'] == Goods::IS_ACTIVITY){ - $res['detail'] = $this->goodsActivityService->detail($params['goods_id']); - $res['banner'] = $this->goodsActivityService->getBanner($params['goods_id']); + if($activity == Goods::IS_ACTIVITY){ + $res['detail'] = $this->goodsActivityService->detail($goodsId); + $res['banner'] = $this->goodsActivityService->getBanner($goodsId); }else{ - $res['detail'] = $this->goodsService->detail($params['goods_id']); - $res['banner'] = $this->goodsService->getBanner($params['goods_id']); + $res['detail'] = $this->goodsService->detail($goodsId); + $res['banner'] = $this->goodsService->getBanner($goodsId); } //如果没有banner数据,使用商品cover图 if(count($res['banner']) == 0){ $res['banner'] = [$res['detail']['cover_img']]; } - + //如果存在用户ID则请求 购物车和收藏店铺信息 if(isset($params['user_id'])) { - $res['shopcart']['count'] = $this->shopCartService->check($params['user_id'],$params['goods_id']); - $res['shopcart']['total'] = $this->shopCartService->getTotal($params['user_id'],$params['market_id']); + $res['shopcart']['count'] = $this->shopCartService->countGoods($params['user_id'],$marketId); + $res['shopcart']['total'] = $this->shopCartService->getTotal($params['user_id'],$marketId); $res['detail']->store->is_collected = (bool)$this->collectService->check($params['user_id'], $res['detail']->store->id); }else{ $res['shopcart'] = ''; diff --git a/app/Model/v3/Goods.php b/app/Model/v3/Goods.php index e872542..219022e 100644 --- a/app/Model/v3/Goods.php +++ b/app/Model/v3/Goods.php @@ -101,7 +101,7 @@ class Goods extends Model public function getCartNumAttribute() { $userId = $this->request->user->id ?? 0; - return $userId ? (integer)$this->shopCartService->check($userId, $this->id) : 0; + return $userId ? (integer)$this->shopCartService->check($userId, $this->id,1) : 0; } public function getIsEffectiveAttribute() diff --git a/app/Model/v3/GoodsActivity.php b/app/Model/v3/GoodsActivity.php index 705a4c6..f6050e3 100644 --- a/app/Model/v3/GoodsActivity.php +++ b/app/Model/v3/GoodsActivity.php @@ -2,6 +2,7 @@ namespace App\Model\v3; +use App\Constants\v3\Goods; use App\Constants\v3\Goods as GoodsConstants; use App\Constants\v3\SsdbKeys; use App\Model\Model; @@ -69,7 +70,7 @@ class GoodsActivity extends Model public function getCartNumAttribute() { $userId = $this->request->user->id ?? 0; - return $userId ? (integer)$this->shopCartService->check($userId, $this->id) : 0; + return $userId ? (integer)$this->shopCartService->check($userId, $this->id,Goods::IS_ACTIVITY) : 0; } public function getIsEffectiveAttribute() diff --git a/app/Service/v3/Implementations/ShopCartService.php b/app/Service/v3/Implementations/ShopCartService.php index b145fb7..3310060 100644 --- a/app/Service/v3/Implementations/ShopCartService.php +++ b/app/Service/v3/Implementations/ShopCartService.php @@ -76,11 +76,12 @@ class ShopCartService implements ShopCartServiceInterface return $storeArr; } - public function check($userId,$goodsId) + public function check($userId,$goodsId,$activityType = 1) { $ShoppingCart = ShoppingCart::query()->where([ ['user_id','=',$userId], ['goods_id','=',$goodsId], + ['activity_type','=',$activity], ]) ->select('num') ->first(); diff --git a/app/Service/v3/Interfaces/ShopCartServiceInterface.php b/app/Service/v3/Interfaces/ShopCartServiceInterface.php index 5f636ce..586b2ea 100644 --- a/app/Service/v3/Interfaces/ShopCartServiceInterface.php +++ b/app/Service/v3/Interfaces/ShopCartServiceInterface.php @@ -6,7 +6,7 @@ interface ShopCartServiceInterface { public function do($userId,$marketId); - public function check($userId,$goodsId); + public function check($userId,$goodsId,$activityType = 1); public function undo($userId,$marketId);