From 8350701295fd1e405fd762786e0b000136d6105b Mon Sep 17 00:00:00 2001 From: weigang Date: Thu, 24 Sep 2020 13:27:20 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B4=AD=E7=89=A9=E8=BD=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Controller/v3/OrderOnlineController.php | 2 +- app/Service/v3/Implementations/CouponRecService.php | 6 ++++-- app/Service/v3/Implementations/ShopCartService.php | 11 ++++++++--- .../v3/Interfaces/CouponRecServiceInterface.php | 2 +- .../v3/Interfaces/ShopCartServiceInterface.php | 2 +- 5 files changed, 15 insertions(+), 8 deletions(-) diff --git a/app/Controller/v3/OrderOnlineController.php b/app/Controller/v3/OrderOnlineController.php index b068658..ca7a593 100644 --- a/app/Controller/v3/OrderOnlineController.php +++ b/app/Controller/v3/OrderOnlineController.php @@ -142,7 +142,7 @@ class OrderOnlineController extends BaseController $res['store_list'] = $this->shopCartService->getGoodsByShopcartId($shopcartIds); //获取用户优惠券 - $coupons = $this->couponRecService->allForOnlineOrderAvailable($userId, $marketId); + $coupons = $this->couponRecService->allForOnlineOrderAvailable($userId, $marketId, $shopcartIds); $res['coupon'] = [ 'available' => [], 'not_available' => [], diff --git a/app/Service/v3/Implementations/CouponRecService.php b/app/Service/v3/Implementations/CouponRecService.php index 806b5f6..ceeb4e5 100644 --- a/app/Service/v3/Implementations/CouponRecService.php +++ b/app/Service/v3/Implementations/CouponRecService.php @@ -144,11 +144,13 @@ class CouponRecService implements CouponRecServiceInterface * 4、筛选出其中活动商品可用但商品的活动类型不符合优惠券活动使用类型的要求(订单中有活动商品可以用优惠券,但是活动类型type和优惠券中的available活动类型不可用) * @param $userId * @param $marketId + * @param $shopcartIds + * @return array */ - public function allForOnlineOrderAvailable($userId, $marketId) + public function allForOnlineOrderAvailable($userId, $marketId, $shopcartIds) { // 获取购物车数据 - $carts = $this->shopCartService->allForUser($userId, $marketId); + $carts = $this->shopCartService->allForUser($userId, $marketId, $shopcartIds); $totalAmount = $carts['total']; // 获取购物车中商品和店铺的类别 diff --git a/app/Service/v3/Implementations/ShopCartService.php b/app/Service/v3/Implementations/ShopCartService.php index 919e783..6167609 100644 --- a/app/Service/v3/Implementations/ShopCartService.php +++ b/app/Service/v3/Implementations/ShopCartService.php @@ -232,9 +232,10 @@ class ShopCartService implements ShopCartServiceInterface * 获取用户购物车数据 * @param $userId * @param $marketId + * @param array $shopcartIds * @return array */ - public function allForUser($userId, $marketId) + public function allForUser($userId, $marketId, $shopcartIds = []) { bcscale(6); @@ -246,8 +247,12 @@ class ShopCartService implements ShopCartServiceInterface } ]) ->where(['user_id' => $userId]) - ->where(['market_id' => $marketId]) - ->get(); + ->where(['market_id' => $marketId]); + if (!empty($carts)) { + $carts = $carts->whereIn('id', $shopcartIds); + } + + $carts = $carts->get(); $cartList = []; $totalAmount = 0; foreach ($carts as $key => &$cart) { diff --git a/app/Service/v3/Interfaces/CouponRecServiceInterface.php b/app/Service/v3/Interfaces/CouponRecServiceInterface.php index b686672..771824f 100644 --- a/app/Service/v3/Interfaces/CouponRecServiceInterface.php +++ b/app/Service/v3/Interfaces/CouponRecServiceInterface.php @@ -9,7 +9,7 @@ interface CouponRecServiceInterface public function undo(); public function allForOrderOlAvailable($totalAmount,$userId,$marketId,$type,$storeTypeId); public function getListByUser($userId,$type,$page = 1,$pagesize = 5); - public function allForOnlineOrderAvailable($userId, $marketId); + public function allForOnlineOrderAvailable($userId, $marketId, $shopcartIds); /** * 统计用户可使用优惠券数量 * @param $userId diff --git a/app/Service/v3/Interfaces/ShopCartServiceInterface.php b/app/Service/v3/Interfaces/ShopCartServiceInterface.php index 586b2ea..a27dd7f 100644 --- a/app/Service/v3/Interfaces/ShopCartServiceInterface.php +++ b/app/Service/v3/Interfaces/ShopCartServiceInterface.php @@ -16,5 +16,5 @@ interface ShopCartServiceInterface public function getGoodsByShopcartId($shopcartIds); - public function allForUser($userId, $marketId); + public function allForUser($userId, $marketId, $shopcartIds = []); } \ No newline at end of file