From d6cc5a00cc50786fd1629209490ec4189ad5230a Mon Sep 17 00:00:00 2001 From: YeMingfei666 <1619116647@qq.com> Date: Fri, 10 Oct 2025 15:24:34 +0800 Subject: [PATCH 1/3] =?UTF-8?q?fix:=20=E4=BB=A3=E5=AE=A2=E4=B8=8B=E5=8D=95?= =?UTF-8?q?=E4=BC=98=E6=83=A0=E5=88=B8=E6=98=BE=E7=A4=BA=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env.development | 8 +- src/store/modules/carts.ts | 1 + src/utils/coupon-utils.js | 49 ++-- src/views/tool/Instead/components/order.vue | 10 +- .../tool/Instead/components/popup-coupon.vue | 261 +++++++++++------- 5 files changed, 207 insertions(+), 122 deletions(-) diff --git a/.env.development b/.env.development index 75a9f88..edb49a4 100644 --- a/.env.development +++ b/.env.development @@ -7,14 +7,14 @@ VITE_APP_BASE_API=/dev-api # 接口地址 # VITE_APP_API_URL=https://tapi.cashier.sxczgkj.cn/ # 测试 -VITE_APP_API_URL=https://cashier.sxczgkj.com/ # 正式 -# VITE_APP_API_URL=http://192.168.1.42/ # 本地 +# VITE_APP_API_URL=https://cashier.sxczgkj.com/ # 正式 +VITE_APP_API_URL=http://192.168.1.42/ # 本地 # WebSocket 端点(不配置则关闭),线上 ws://api.youlai.tech/ws ,本地 ws://localhost:8989/ws # VITE_APP_WS_ENDPOINT=wss://sockets.sxczgkj.com/wss -VITE_APP_WS_ENDPOINT=wss://czgeatws.sxczgkj.com/wss # 正式 -# VITE_APP_WS_ENDPOINT=ws://192.168.1.42:2348 # 本地 +# VITE_APP_WS_ENDPOINT=wss://czgeatws.sxczgkj.com/wss # 正式 +VITE_APP_WS_ENDPOINT=ws://192.168.1.42:2348 # 本地 # 启用 Mock 服务 diff --git a/src/store/modules/carts.ts b/src/store/modules/carts.ts index 8bbcb5c..d102570 100644 --- a/src/store/modules/carts.ts +++ b/src/store/modules/carts.ts @@ -31,6 +31,7 @@ interface PointDeductionRule { maxDeductionAmount: number; } + export const useCartsStore = defineStore("carts", () => { // ------------------------------ 1. 移到内部的工具函数(核心修复) ------------------------------ // 适配工具库 BaseCartItem 接口的商品数据转换函数(原外部函数,现在内部) diff --git a/src/utils/coupon-utils.js b/src/utils/coupon-utils.js index 4a2b1ce..8fa73f9 100644 --- a/src/utils/coupon-utils.js +++ b/src/utils/coupon-utils.js @@ -77,7 +77,6 @@ export function returnCanDikouGoodsArr(canDikouGoodsArr, selCoupon, user) { prev.push(...goodsWithType); return prev; }, []); - const arr = _.cloneDeep(canDikouGoodsArr) .map((v) => { const findCart = goodsCouponGoods.find((carts) => carts.id == v.id); @@ -116,19 +115,17 @@ export function returnCanDikouGoodsArr(canDikouGoodsArr, selCoupon, user) { */ export function returnCouponCanUse(args) { let { canDikouGoodsArr, coupon, goodsOrderPrice, user, selCoupon, shopInfo } = args; - // 优惠券未启用 if (!coupon.use) { return { canUse: false, - reason: "优惠券未启用", + reason: coupon.noUseRestrictions || "不在可用时间段内", }; } // 计算门槛金额 let fullAmount = goodsOrderPrice; canDikouGoodsArr = returnCanDikouGoodsArr(canDikouGoodsArr, selCoupon, user, shopInfo); - //优惠券指定门槛商品列表 let canCalcGoodsArr = [...canDikouGoodsArr]; //部分商品参与门槛计算 @@ -187,7 +184,13 @@ export function returnCouponCanUse(args) { // 商品兑换券,第二件半价和买一送一判断是否有可用商品 if ([2, 4, 5].includes(coupon.type)) { // 没有符合条件的商品 - if (!isDikouAll && canCalcGoodsArr.length === 0) { + if (isDikouAll && canDikouGoodsArr.length === 0) { + return { + canUse: false, + reason: "没有符合条件的商品", + }; + } + if (!isDikouAll && canUseGoodsArr.length === 0) { return { canUse: false, reason: "没有符合条件的商品", @@ -289,7 +292,8 @@ export function returnCouponDiscount(arr, coupon, user, goodsOrderPrice, selCoup return returnCouponProductDiscount(canDikouGoodsArr, coupon, user, shopInfo); } if (coupon.type == 6) { - return returnCouponBuyOneGiveOneDiscount(canDikouGoodsArr, coupon, user, shopInfo); + const result = returnCouponBuyOneGiveOneDiscount(canDikouGoodsArr, coupon, user, shopInfo); + return result; } if (coupon.type == 4) { return returnSecoendDiscount(canDikouGoodsArr, coupon, user, shopInfo); @@ -403,7 +407,7 @@ function returnCouponBuyOneGiveOneDiscount(canDikouGoodsArr, coupon, user, shopI if (useRule == "price_asc") { discountGoods = canUseGoods[canUseGoods.length - 1]; } else { - discountGoods = canUseGoods.slice(0, 1); + discountGoods = canUseGoods[0]; } } else { //符合抵扣条件的商品 @@ -411,13 +415,18 @@ function returnCouponBuyOneGiveOneDiscount(canDikouGoodsArr, coupon, user, shopI if (useRule == "price_asc") { discountGoods = canUseGoods1[canUseGoods1.length - 1]; } else { - discountGoods = canUseGoods1.slice(0, 1); + discountGoods = canUseGoods1[0]; } } - const discountPrice = returnGoodsPrice(discountGoods, user, shopInfo); - const hasDiscountGoodsArr = [discountGoods]; + let discountPrice = 0; + let hasDiscountGoodsArr = []; + console.log("returnCouponBuyOneGiveOneDiscount:discountGoods", discountGoods); + if (discountGoods) { + discountPrice = returnGoodsPrice(discountGoods, user, shopInfo); + hasDiscountGoodsArr = [discountGoods]; + } return { - discountPrice, + discountPrice: discountPrice <= 0 ? 0 : discountPrice, hasDiscountGoodsArr, }; } @@ -433,14 +442,14 @@ function returnSecoendDiscount(canDikouGoodsArr, coupon, user, shopInfo) { const { useFoods, useRule } = coupon; //抵扣商品 let discountGoods = undefined; - //符合买一送一条件的商品 + //符合条件的商品 const canUseGoods = canDikouGoodsArr.filter((v) => v.num >= 2); //抵扣全部商品 if (useFoods.length === 0) { if (useRule == "price_asc") { discountGoods = canUseGoods[canUseGoods.length - 1]; } else { - discountGoods = canUseGoods.slice(0, 1); + discountGoods = canUseGoods[0]; } } else { //符合抵扣条件的商品 @@ -448,16 +457,18 @@ function returnSecoendDiscount(canDikouGoodsArr, coupon, user, shopInfo) { if (useRule == "price_asc") { discountGoods = canUseGoods1[canUseGoods1.length - 1]; } else { - discountGoods = canUseGoods1.slice(0, 1); + discountGoods = canUseGoods1[0]; } } - console.log("returnSecoendDiscount:discountGoods", discountGoods); - const discountPrice = returnGoodsPrice(discountGoods[0], user, shopInfo); - console.log("returnSecoendDiscount:discountPrice", discountPrice); - const hasDiscountGoodsArr = [discountGoods]; + let discountPrice = 0; + let hasDiscountGoodsArr = []; + if (discountGoods) { + discountPrice = returnGoodsPrice(discountGoods, user, shopInfo); + hasDiscountGoodsArr = [discountGoods]; + } //返回半价价格 return { - discountPrice: new BigNumber(discountPrice).dividedBy(2).toNumber(), + discountPrice: discountPrice <= 0 ? 0 : new BigNumber(discountPrice).dividedBy(2).toNumber(), hasDiscountGoodsArr, }; } diff --git a/src/views/tool/Instead/components/order.vue b/src/views/tool/Instead/components/order.vue index 01809ad..b72370e 100644 --- a/src/views/tool/Instead/components/order.vue +++ b/src/views/tool/Instead/components/order.vue @@ -81,15 +81,14 @@ - {{ carts.orderCostSummary }} -
+
已选优惠券
- + @@ -232,6 +231,8 @@