fix: 问题修复

This commit is contained in:
YeMingfei666 2025-10-13 11:19:26 +08:00
parent b4b87218d1
commit cd351be6d0
7 changed files with 80 additions and 65 deletions

View File

@ -1,5 +1,5 @@
import request from "@/utils/request";
const baseURL = "account/admin/";
const baseURL = "/account/admin/";
const AuthAPI = {
/** 登录接口*/

View File

@ -1,5 +1,5 @@
import request from "@/utils/request";
const baseURL = "account/admin/";
const baseURL = "/account/admin/";
const RegisterApi = {
/** 获取当前用户菜单列表*/

View File

@ -1,5 +1,5 @@
import request from "@/utils/request";
const baseURL = "account/admin/role";
const baseURL = "/account/admin/role";
const RoleApi = {
/** 获取当前用户菜单列表*/

View File

@ -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);
}

View File

@ -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); // 加上附加费

View File

@ -36,15 +36,15 @@
<span class="u-font-14">不使用</span>
</el-radio>
<el-radio :value="0" :disabled="!pointsRes.usable">
<span class="u-font-14">全部抵扣</span>
<span class="u-font-14">使用</span>
</el-radio>
<el-radio :value="1" :disabled="!pointsRes.usable">
<!-- <el-radio :value="1" :disabled="!pointsRes.usable">
<span class="u-font-14">部分抵扣</span>
</el-radio>
</el-radio> -->
</el-radio-group>
<el-input-number
class="u-m-l-10"
v-if="score.sel == 1"
v-if="score.sel != -1"
v-model="usePointsNumber"
step-strictly
:step="pointsRes.equivalentPoints"
@ -277,9 +277,6 @@ function refCouponConfirm(e, goodsList) {
};
});
goodsArr = goodsList;
usePointsNumber.value = 0;
pointsDiscountAmount.value = 0;
score.sel = -1;
console.log("refCouponConfirm", e);
carts.setCoupons(e);
@ -399,29 +396,24 @@ const pointsRes = ref({ usable: true, maxUsablePoints: 0, minDeductionPoints: 0
const usePointsNumber = ref(0);
//
const scoreMaxMoney = computed(() => {
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();
});

View File

@ -1,5 +1,5 @@
<template>
<el-dialog width="900px" :title="title" v-model="show" top="20px" @close="reset">
<el-dialog width="1000px" :title="title" v-model="show" top="20px" @close="reset">
<div class="u-p-15">
<div class="">
<el-tabs v-model="activeName" @tab-click="tabClick">
@ -69,6 +69,12 @@
></el-checkbox>
</template>
</el-table-column>
<el-table-column prop="id" width="100" label="ID">
<template v-slot="scope">
{{ scope.row.id }}
</template>
</el-table-column>
<el-table-column type="index" width="50" label="#"></el-table-column>
<el-table-column prop="name" label="券名称"></el-table-column>
@ -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];
}
}