diff --git a/src/api/account/login.ts b/src/api/account/login.ts index 86bef30..ca786a8 100644 --- a/src/api/account/login.ts +++ b/src/api/account/login.ts @@ -1,5 +1,5 @@ import request from "@/utils/request"; -const baseURL = "account/admin/"; +const baseURL = "/account/admin/"; const AuthAPI = { /** 登录接口*/ diff --git a/src/api/account/register.ts b/src/api/account/register.ts index a366cd4..b9428ad 100644 --- a/src/api/account/register.ts +++ b/src/api/account/register.ts @@ -1,5 +1,5 @@ import request from "@/utils/request"; -const baseURL = "account/admin/"; +const baseURL = "/account/admin/"; const RegisterApi = { /** 获取当前用户菜单列表*/ diff --git a/src/api/account/role.ts b/src/api/account/role.ts index b51a900..a88409d 100644 --- a/src/api/account/role.ts +++ b/src/api/account/role.ts @@ -1,5 +1,5 @@ import request from "@/utils/request"; -const baseURL = "account/admin/role"; +const baseURL = "/account/admin/role"; const RoleApi = { /** 获取当前用户菜单列表*/ diff --git a/src/utils/coupon-utils.js b/src/utils/coupon-utils.js index 8fa73f9..9ce937a 100644 --- a/src/utils/coupon-utils.js +++ b/src/utils/coupon-utils.js @@ -181,8 +181,15 @@ export function returnCouponCanUse(args) { }; } } + // 商品兑换券,第二件半价和买一送一判断是否有可用商品 if ([2, 4, 5].includes(coupon.type)) { + if (coupon.type == 2 && fullAmount < coupon.fullAmount) { + return { + canUse: false, + reason: `满${coupon.fullAmount}元可用,当前可参与金额${fullAmount}元`, + }; + } // 没有符合条件的商品 if (isDikouAll && canDikouGoodsArr.length === 0) { return { @@ -265,12 +272,14 @@ export function calcDiscountGoodsArrPrice(discountGoodsArr, discountNum, user, s const shengyuNum = discountNum - hasCountNum; const num = Math.min(goods.num, shengyuNum); discountPrice += returnGoodsPrice(goods, user, shopInfo) * num; + hasCountNum += num; hasDiscountGoodsArr.push({ ...goods, num, }); } + return { discountPrice, hasDiscountGoodsArr, @@ -330,7 +339,6 @@ export function returnCouponZhekouDiscount( // 将商品订单价格转换为BigNumber并减去优惠券折扣 const adjustedGoodsOrderPrice = new BigNumber(goodsOrderPrice).minus(goodsCouponDiscount); - console.log("adjustedGoodsOrderPrice", adjustedGoodsOrderPrice.toNumber()); // 计算优惠比例:(100 - 折扣率) / 100 const discountAmountRatio = new BigNumber(100).minus(discountRate).dividedBy(100); @@ -366,9 +374,7 @@ export function returnCouponProductDiscount(canDikouGoodsArr, coupon, user, shop //抵扣全部商品 if (useFoods.length === 0) { if (useRule == "price_asc") { - discountGoodsArr = canDikouGoodsArr - .slice(canDikouGoodsArr.length - discountNum, canDikouGoodsArr.length) - .reverse(); + discountGoodsArr = canDikouGoodsArr.slice(discountNum * -1).reverse(); } else { discountGoodsArr = canDikouGoodsArr.slice(0, discountNum); } @@ -378,9 +384,7 @@ export function returnCouponProductDiscount(canDikouGoodsArr, coupon, user, shop useFoods.find((food) => food.id == v.productId) ); if (useRule == "price_asc") { - discountGoodsArr = discountSelGoodsArr - .slice(discountSelGoodsArr.length - discountNum, discountSelGoodsArr.length) - .reverse(); + discountGoodsArr = discountSelGoodsArr.slice(discountNum * -1).reverse(); } else { discountGoodsArr = discountSelGoodsArr.slice(0, discountNum); } diff --git a/src/utils/goods.ts b/src/utils/goods.ts index 0c50174..b9f436b 100644 --- a/src/utils/goods.ts +++ b/src/utils/goods.ts @@ -1707,12 +1707,17 @@ export function calculateOrderCostSummary( } // 5. 最终实付金额计算(整合所有费用) - const finalPayAmount = new BigNumber(goodsOriginalAmount) // 商品原价总和 + // 先计算减去所有折扣后的金额,并确保最小值为0 + const discountedAmount = new BigNumber(goodsOriginalAmount) // 商品原价总和 .minus(goodsDiscountAmount) // 减去商品折扣 .minus(couponDeductionAmount) // 减去优惠券抵扣 .minus(newUserDiscount) // 新客立减 .minus(pointDeductionAmount) // 减去积分抵扣 - .minus(merchantReductionActualAmount) // 减去商家实际减免金额 + .minus(merchantReductionActualAmount); // 减去商家实际减免金额 + + // 确保折扣后金额不小于0,再加上后续费用 + const nonNegativeAmount = discountedAmount.gt(0) ? discountedAmount : new BigNumber(0); + const finalPayAmount = nonNegativeAmount .plus(seatFee) // 加上餐位费(不参与减免) .plus(packFee) // 加上打包费(不参与减免) .plus(additionalFee); // 加上附加费 diff --git a/src/views/tool/Instead/components/order.vue b/src/views/tool/Instead/components/order.vue index 3713253..17f2f5d 100644 --- a/src/views/tool/Instead/components/order.vue +++ b/src/views/tool/Instead/components/order.vue @@ -36,15 +36,15 @@ 不使用 - 全部抵扣 + 使用 - + { - return carts.orderCostSummary.finalPayAmount - carts.orderCostSummary.pointDeductionAmount; + return carts.orderCostSummary.finalPayAmount + carts.orderCostSummary.pointDeductionAmount; }); -const pointsDiscountAmount = ref(0); watch( () => scoreMaxMoney.value, - (newval) => { - pointsInit(); + (newval, oldval) => { + if (newval != oldval) { + pointsInit(); + } } ); -// 返回积分抵扣前金额 -function returnPointsDiscountAmount() { - const total = currentpayMoney.value * 1 + carts.orderCostSummary.pointDeductionAmount * 1; - return total <= 0 ? 0 : total; -} - async function pointsInit() { if (!props.user.id) { return; } const res = await PointsApi.calcOrderUsablePoints({ shopUserId: props.user.id, - orderAmount: returnPointsDiscountAmount(), + orderAmount: scoreMaxMoney.value, }); pointsRes.value = res; carts.pointDeductionRule.pointsPerYuan = res.equivalentPoints; @@ -431,29 +423,12 @@ async function pointsInit() { usePointsNumber.value = res.usable ? res.maxUsablePoints : 0; if (res.usable) { - pointsToMoney(); } else { score.sel = -1; } return res; } -// 根据积分计算可抵扣金额 -async function pointsToMoney() { - try { - const res = await PointsApi.calcPointsToMoney({ - shopUserId: props.user.id, - orderAmount: returnPointsDiscountAmount(), - points: usePointsNumber.value, - }); - if (!res) { - score.sel = -1; - return; - } - pointsDiscountAmount.value = res; - } catch (e) { - score.sel = -1; - } -} + const emits = defineEmits(["chooseUser", "paysuccess"]); function chooseUser() { emits("chooseUser"); @@ -480,7 +455,6 @@ watch( (newval) => { console.log(newval); usePointsNumber.value = 0; - pointsDiscountAmount.value = 0; pointsInit(); } ); @@ -667,16 +641,6 @@ const productCouponDiscountAmount = computed(() => { // 优先从 Store 扩展字段取,若无则用 props 数据(过渡方案) return carts.orderCostSummary.productCouponDeduction; }); -//除开客座费,打包费总金额 -const totalMoney = computed(() => { - return ( - carts.goodsTotal - - productCouponDiscountAmount.value - - discountAmount.value - - fullCouponDiscountAmount.value - - pointsDiscountAmount.value - ).toFixed(2); -}); const totalPrice = computed(() => { // 使用bignumber.js处理高精度计算 @@ -693,7 +657,10 @@ const totalPrice = computed(() => { .minus(merchantReduction) .minus(pointDeduction) .decimalPlaces(2, BigNumber.ROUND_DOWN); // 保持与工具库一致的舍入策略 - + const n = total.toNumber(); + if (n <= 0) { + return 0; + } return total.toNumber(); }); diff --git a/src/views/tool/Instead/components/popup-coupon.vue b/src/views/tool/Instead/components/popup-coupon.vue index a5f462b..c16af28 100644 --- a/src/views/tool/Instead/components/popup-coupon.vue +++ b/src/views/tool/Instead/components/popup-coupon.vue @@ -1,5 +1,5 @@ + + + + @@ -280,6 +286,7 @@ async function getcoup() { let noUseGoodsCoupon = []; let noUseDiscountCoupon = []; + console.log("orderPrice", orderPrice.value); for (let i = 0; i < couponList.length; i++) { const coupon = couponList[i]; const selCoupon = @@ -289,7 +296,7 @@ async function getcoup() { const canuseResult = UTILS.returnCouponCanUse({ canDikouGoodsArr, coupon, - orderPrice: orderPrice.value, + goodsOrderPrice: orderPrice.value, user: props.user, selCoupon, shopInfo: shopUser.userInfo, @@ -323,7 +330,7 @@ async function getcoup() { v, props.user, orderPrice.value, - quansSelArr.value, + quansSelArr.value.filter((v) => v.type != 2), shopUser.userInfo ); return { @@ -339,7 +346,7 @@ async function getcoup() { v, props.user, orderPrice.value, - quansSelArr.value, + quansSelArr.value.filter((v) => v.type == 2), shopUser.userInfo ); return { @@ -426,6 +433,15 @@ function updateSelCoupon() { }; }); otherCoupon = otherCoupon.map((v) => { + const canuseResult = UTILS.returnCouponCanUse({ + canDikouGoodsArr, + coupon: v, + orderPrice: orderPrice.value, + user: props.user, + selCoupon: goodsCoupon, + shopInfo: shopUser.userInfo, + }); + const discount = UTILS.returnCouponDiscount( canDikouGoodsArr, v, @@ -436,12 +452,35 @@ function updateSelCoupon() { ); return { ...v, + canuseResult, discount, discountAmount: discount ? discount.discountPrice : v.discountAmount, }; }); - couponSel.value = otherCoupon[0]; + if (!otherCoupon[0].canuseResult.canUse) { + couponSel.value = { id: "" }; + ElMessageBox.confirm( + `选择该券后优惠券${otherCoupon[0].name}不可用,不可用原因:${otherCoupon[0].canuseResult.reason}`, + "提示", + { + type: "warning", + showCancelButton: true, + cancelButtonText: "取消当前券的选择", + confirmButtonText: "剔除不可用的优惠券", + } + ) + .then(() => { + couponSel.value = { id: "" }; + goodsCouponSel.value = goodsCoupon[0]; + }) + .catch(() => { + goodsCouponSel.value = { id: "" }; + couponSel.value = otherCoupon[0]; + }); + return; + } goodsCouponSel.value = goodsCoupon[0]; + couponSel.value = otherCoupon[0]; } }