From 99e7a702454a40f80984b8abcba05c1496322460 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=B4=E6=98=8A=E5=A4=A9?= <442384644@qq.com> Date: Tue, 27 Oct 2026 13:09:31 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E4=BC=9A=E5=91=98=E5=95=86=E5=93=81):=20?= =?UTF-8?q?=E5=8A=A0=E8=B4=AD=E5=89=8D=E5=88=B7=E6=96=B0=E8=BF=87=E6=9C=9F?= =?UTF-8?q?=E4=BC=9A=E5=91=98=E7=8A=B6=E6=80=81=EF=BC=8C=E5=86=8D=E6=AC=A1?= =?UTF-8?q?=E8=B4=AD=E4=B9=B0=E5=90=8C=E6=AD=A5=E6=A0=A1=E9=AA=8C=E4=B8=93?= =?UTF-8?q?=E5=B1=9E=E5=8F=AF=E4=B9=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Cursor --- .../app/services/order/StoreCartServices.php | 26 +++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/backend/app/services/order/StoreCartServices.php b/backend/app/services/order/StoreCartServices.php index 54c2e1e1d..7e4d24f9c 100644 --- a/backend/app/services/order/StoreCartServices.php +++ b/backend/app/services/order/StoreCartServices.php @@ -346,6 +346,13 @@ class StoreCartServices extends BaseService if ($type == 0) { //检查限购 $this->checkLimit($uid, $product_id, $cart_num, $new); + // 普通商品:付费会员专属需校验(含再次购买 againOrder→setCart,不经加购接口) + /** @var UserServices $userServices */ + $userServices = app()->make(UserServices::class); + $userInfo = $userServices->getUserInfo($uid); + if ($userInfo) { + $this->checkVipGoodsBuy(is_object($userInfo) ? $userInfo->toArray() : $userInfo, $product_id); + } } //检测库存限量 [$attrInfo, $product_attr_unique, $bargainPriceMin, $cart_num, $productInfo] = $this->checkProductStock($uid, $cart_num, $product_attr_unique, $type, $product_id, $seckill_id, $bargain_id, $combination_id, $advance_id); @@ -1053,9 +1060,24 @@ class StoreCartServices extends BaseService */ public function checkVipGoodsBuy($user, $pid) { - $is_vip_product = app()->make(CenterProductServices::class)->value(['id' => $pid], 'vip_product'); + $user = is_object($user) ? $user->toArray() : (array)$user; + $uid = (int)($user['uid'] ?? 0); + // 先按 overdue_time 落库刷新会员状态,避免会话/库内 is_money_level 仍为有效会员 + if ($uid > 0) { + /** @var UserServices $userServices */ + $userServices = app()->make(UserServices::class); + $stillMember = $userServices->offMemberLevel($uid, $user); + if ($stillMember === false) { + $user['is_money_level'] = 0; + } else { + $user = is_object($stillMember) ? $stillMember->toArray() : (array)$stillMember; + } + } + $is_vip_product = (int)app()->make(CenterProductServices::class)->value(['id' => $pid], 'vip_product'); // 1=仅会员可见可买,2=所有人可见仅会员可买,非付费会员均无权购买 - if (in_array($is_vip_product, [1, 2]) && $user['is_money_level'] == 0) throw new ApiException('此商品为付费会员专属,您无权购买'); + if (in_array($is_vip_product, [1, 2], true) && (int)($user['is_money_level'] ?? 0) === 0) { + throw new ApiException('此商品为付费会员专属,您无权购买'); + } return true; } }