fix: 问题修复
This commit is contained in:
parent
b4b87218d1
commit
cd351be6d0
|
|
@ -1,5 +1,5 @@
|
||||||
import request from "@/utils/request";
|
import request from "@/utils/request";
|
||||||
const baseURL = "account/admin/";
|
const baseURL = "/account/admin/";
|
||||||
|
|
||||||
const AuthAPI = {
|
const AuthAPI = {
|
||||||
/** 登录接口*/
|
/** 登录接口*/
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import request from "@/utils/request";
|
import request from "@/utils/request";
|
||||||
const baseURL = "account/admin/";
|
const baseURL = "/account/admin/";
|
||||||
|
|
||||||
const RegisterApi = {
|
const RegisterApi = {
|
||||||
/** 获取当前用户菜单列表*/
|
/** 获取当前用户菜单列表*/
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import request from "@/utils/request";
|
import request from "@/utils/request";
|
||||||
const baseURL = "account/admin/role";
|
const baseURL = "/account/admin/role";
|
||||||
|
|
||||||
const RoleApi = {
|
const RoleApi = {
|
||||||
/** 获取当前用户菜单列表*/
|
/** 获取当前用户菜单列表*/
|
||||||
|
|
|
||||||
|
|
@ -181,8 +181,15 @@ export function returnCouponCanUse(args) {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 商品兑换券,第二件半价和买一送一判断是否有可用商品
|
// 商品兑换券,第二件半价和买一送一判断是否有可用商品
|
||||||
if ([2, 4, 5].includes(coupon.type)) {
|
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) {
|
if (isDikouAll && canDikouGoodsArr.length === 0) {
|
||||||
return {
|
return {
|
||||||
|
|
@ -265,12 +272,14 @@ export function calcDiscountGoodsArrPrice(discountGoodsArr, discountNum, user, s
|
||||||
const shengyuNum = discountNum - hasCountNum;
|
const shengyuNum = discountNum - hasCountNum;
|
||||||
const num = Math.min(goods.num, shengyuNum);
|
const num = Math.min(goods.num, shengyuNum);
|
||||||
discountPrice += returnGoodsPrice(goods, user, shopInfo) * num;
|
discountPrice += returnGoodsPrice(goods, user, shopInfo) * num;
|
||||||
|
|
||||||
hasCountNum += num;
|
hasCountNum += num;
|
||||||
hasDiscountGoodsArr.push({
|
hasDiscountGoodsArr.push({
|
||||||
...goods,
|
...goods,
|
||||||
num,
|
num,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
discountPrice,
|
discountPrice,
|
||||||
hasDiscountGoodsArr,
|
hasDiscountGoodsArr,
|
||||||
|
|
@ -330,7 +339,6 @@ export function returnCouponZhekouDiscount(
|
||||||
|
|
||||||
// 将商品订单价格转换为BigNumber并减去优惠券折扣
|
// 将商品订单价格转换为BigNumber并减去优惠券折扣
|
||||||
const adjustedGoodsOrderPrice = new BigNumber(goodsOrderPrice).minus(goodsCouponDiscount);
|
const adjustedGoodsOrderPrice = new BigNumber(goodsOrderPrice).minus(goodsCouponDiscount);
|
||||||
console.log("adjustedGoodsOrderPrice", adjustedGoodsOrderPrice.toNumber());
|
|
||||||
|
|
||||||
// 计算优惠比例:(100 - 折扣率) / 100
|
// 计算优惠比例:(100 - 折扣率) / 100
|
||||||
const discountAmountRatio = new BigNumber(100).minus(discountRate).dividedBy(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 (useFoods.length === 0) {
|
||||||
if (useRule == "price_asc") {
|
if (useRule == "price_asc") {
|
||||||
discountGoodsArr = canDikouGoodsArr
|
discountGoodsArr = canDikouGoodsArr.slice(discountNum * -1).reverse();
|
||||||
.slice(canDikouGoodsArr.length - discountNum, canDikouGoodsArr.length)
|
|
||||||
.reverse();
|
|
||||||
} else {
|
} else {
|
||||||
discountGoodsArr = canDikouGoodsArr.slice(0, discountNum);
|
discountGoodsArr = canDikouGoodsArr.slice(0, discountNum);
|
||||||
}
|
}
|
||||||
|
|
@ -378,9 +384,7 @@ export function returnCouponProductDiscount(canDikouGoodsArr, coupon, user, shop
|
||||||
useFoods.find((food) => food.id == v.productId)
|
useFoods.find((food) => food.id == v.productId)
|
||||||
);
|
);
|
||||||
if (useRule == "price_asc") {
|
if (useRule == "price_asc") {
|
||||||
discountGoodsArr = discountSelGoodsArr
|
discountGoodsArr = discountSelGoodsArr.slice(discountNum * -1).reverse();
|
||||||
.slice(discountSelGoodsArr.length - discountNum, discountSelGoodsArr.length)
|
|
||||||
.reverse();
|
|
||||||
} else {
|
} else {
|
||||||
discountGoodsArr = discountSelGoodsArr.slice(0, discountNum);
|
discountGoodsArr = discountSelGoodsArr.slice(0, discountNum);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1707,12 +1707,17 @@ export function calculateOrderCostSummary(
|
||||||
}
|
}
|
||||||
|
|
||||||
// 5. 最终实付金额计算(整合所有费用)
|
// 5. 最终实付金额计算(整合所有费用)
|
||||||
const finalPayAmount = new BigNumber(goodsOriginalAmount) // 商品原价总和
|
// 先计算减去所有折扣后的金额,并确保最小值为0
|
||||||
|
const discountedAmount = new BigNumber(goodsOriginalAmount) // 商品原价总和
|
||||||
.minus(goodsDiscountAmount) // 减去商品折扣
|
.minus(goodsDiscountAmount) // 减去商品折扣
|
||||||
.minus(couponDeductionAmount) // 减去优惠券抵扣
|
.minus(couponDeductionAmount) // 减去优惠券抵扣
|
||||||
.minus(newUserDiscount) // 新客立减
|
.minus(newUserDiscount) // 新客立减
|
||||||
.minus(pointDeductionAmount) // 减去积分抵扣
|
.minus(pointDeductionAmount) // 减去积分抵扣
|
||||||
.minus(merchantReductionActualAmount) // 减去商家实际减免金额
|
.minus(merchantReductionActualAmount); // 减去商家实际减免金额
|
||||||
|
|
||||||
|
// 确保折扣后金额不小于0,再加上后续费用
|
||||||
|
const nonNegativeAmount = discountedAmount.gt(0) ? discountedAmount : new BigNumber(0);
|
||||||
|
const finalPayAmount = nonNegativeAmount
|
||||||
.plus(seatFee) // 加上餐位费(不参与减免)
|
.plus(seatFee) // 加上餐位费(不参与减免)
|
||||||
.plus(packFee) // 加上打包费(不参与减免)
|
.plus(packFee) // 加上打包费(不参与减免)
|
||||||
.plus(additionalFee); // 加上附加费
|
.plus(additionalFee); // 加上附加费
|
||||||
|
|
|
||||||
|
|
@ -36,15 +36,15 @@
|
||||||
<span class="u-font-14">不使用</span>
|
<span class="u-font-14">不使用</span>
|
||||||
</el-radio>
|
</el-radio>
|
||||||
<el-radio :value="0" :disabled="!pointsRes.usable">
|
<el-radio :value="0" :disabled="!pointsRes.usable">
|
||||||
<span class="u-font-14">全部抵扣</span>
|
<span class="u-font-14">使用</span>
|
||||||
</el-radio>
|
</el-radio>
|
||||||
<el-radio :value="1" :disabled="!pointsRes.usable">
|
<!-- <el-radio :value="1" :disabled="!pointsRes.usable">
|
||||||
<span class="u-font-14">部分抵扣</span>
|
<span class="u-font-14">部分抵扣</span>
|
||||||
</el-radio>
|
</el-radio> -->
|
||||||
</el-radio-group>
|
</el-radio-group>
|
||||||
<el-input-number
|
<el-input-number
|
||||||
class="u-m-l-10"
|
class="u-m-l-10"
|
||||||
v-if="score.sel == 1"
|
v-if="score.sel != -1"
|
||||||
v-model="usePointsNumber"
|
v-model="usePointsNumber"
|
||||||
step-strictly
|
step-strictly
|
||||||
:step="pointsRes.equivalentPoints"
|
:step="pointsRes.equivalentPoints"
|
||||||
|
|
@ -277,9 +277,6 @@ function refCouponConfirm(e, goodsList) {
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
goodsArr = goodsList;
|
goodsArr = goodsList;
|
||||||
usePointsNumber.value = 0;
|
|
||||||
pointsDiscountAmount.value = 0;
|
|
||||||
score.sel = -1;
|
|
||||||
console.log("refCouponConfirm", e);
|
console.log("refCouponConfirm", e);
|
||||||
carts.setCoupons(e);
|
carts.setCoupons(e);
|
||||||
|
|
||||||
|
|
@ -399,29 +396,24 @@ const pointsRes = ref({ usable: true, maxUsablePoints: 0, minDeductionPoints: 0
|
||||||
const usePointsNumber = ref(0);
|
const usePointsNumber = ref(0);
|
||||||
//积分可抵扣最大金额
|
//积分可抵扣最大金额
|
||||||
const scoreMaxMoney = computed(() => {
|
const scoreMaxMoney = computed(() => {
|
||||||
return carts.orderCostSummary.finalPayAmount - carts.orderCostSummary.pointDeductionAmount;
|
return carts.orderCostSummary.finalPayAmount + carts.orderCostSummary.pointDeductionAmount;
|
||||||
});
|
});
|
||||||
const pointsDiscountAmount = ref(0);
|
|
||||||
watch(
|
watch(
|
||||||
() => scoreMaxMoney.value,
|
() => scoreMaxMoney.value,
|
||||||
(newval) => {
|
(newval, oldval) => {
|
||||||
pointsInit();
|
if (newval != oldval) {
|
||||||
|
pointsInit();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
// 返回积分抵扣前金额
|
|
||||||
function returnPointsDiscountAmount() {
|
|
||||||
const total = currentpayMoney.value * 1 + carts.orderCostSummary.pointDeductionAmount * 1;
|
|
||||||
return total <= 0 ? 0 : total;
|
|
||||||
}
|
|
||||||
|
|
||||||
async function pointsInit() {
|
async function pointsInit() {
|
||||||
if (!props.user.id) {
|
if (!props.user.id) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const res = await PointsApi.calcOrderUsablePoints({
|
const res = await PointsApi.calcOrderUsablePoints({
|
||||||
shopUserId: props.user.id,
|
shopUserId: props.user.id,
|
||||||
orderAmount: returnPointsDiscountAmount(),
|
orderAmount: scoreMaxMoney.value,
|
||||||
});
|
});
|
||||||
pointsRes.value = res;
|
pointsRes.value = res;
|
||||||
carts.pointDeductionRule.pointsPerYuan = res.equivalentPoints;
|
carts.pointDeductionRule.pointsPerYuan = res.equivalentPoints;
|
||||||
|
|
@ -431,29 +423,12 @@ async function pointsInit() {
|
||||||
|
|
||||||
usePointsNumber.value = res.usable ? res.maxUsablePoints : 0;
|
usePointsNumber.value = res.usable ? res.maxUsablePoints : 0;
|
||||||
if (res.usable) {
|
if (res.usable) {
|
||||||
pointsToMoney();
|
|
||||||
} else {
|
} else {
|
||||||
score.sel = -1;
|
score.sel = -1;
|
||||||
}
|
}
|
||||||
return res;
|
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"]);
|
const emits = defineEmits(["chooseUser", "paysuccess"]);
|
||||||
function chooseUser() {
|
function chooseUser() {
|
||||||
emits("chooseUser");
|
emits("chooseUser");
|
||||||
|
|
@ -480,7 +455,6 @@ watch(
|
||||||
(newval) => {
|
(newval) => {
|
||||||
console.log(newval);
|
console.log(newval);
|
||||||
usePointsNumber.value = 0;
|
usePointsNumber.value = 0;
|
||||||
pointsDiscountAmount.value = 0;
|
|
||||||
pointsInit();
|
pointsInit();
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
@ -667,16 +641,6 @@ const productCouponDiscountAmount = computed(() => {
|
||||||
// 优先从 Store 扩展字段取,若无则用 props 数据(过渡方案)
|
// 优先从 Store 扩展字段取,若无则用 props 数据(过渡方案)
|
||||||
return carts.orderCostSummary.productCouponDeduction;
|
return carts.orderCostSummary.productCouponDeduction;
|
||||||
});
|
});
|
||||||
//除开客座费,打包费总金额
|
|
||||||
const totalMoney = computed(() => {
|
|
||||||
return (
|
|
||||||
carts.goodsTotal -
|
|
||||||
productCouponDiscountAmount.value -
|
|
||||||
discountAmount.value -
|
|
||||||
fullCouponDiscountAmount.value -
|
|
||||||
pointsDiscountAmount.value
|
|
||||||
).toFixed(2);
|
|
||||||
});
|
|
||||||
|
|
||||||
const totalPrice = computed(() => {
|
const totalPrice = computed(() => {
|
||||||
// 使用bignumber.js处理高精度计算
|
// 使用bignumber.js处理高精度计算
|
||||||
|
|
@ -693,7 +657,10 @@ const totalPrice = computed(() => {
|
||||||
.minus(merchantReduction)
|
.minus(merchantReduction)
|
||||||
.minus(pointDeduction)
|
.minus(pointDeduction)
|
||||||
.decimalPlaces(2, BigNumber.ROUND_DOWN); // 保持与工具库一致的舍入策略
|
.decimalPlaces(2, BigNumber.ROUND_DOWN); // 保持与工具库一致的舍入策略
|
||||||
|
const n = total.toNumber();
|
||||||
|
if (n <= 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
return total.toNumber();
|
return total.toNumber();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
<template>
|
<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="u-p-15">
|
||||||
<div class="">
|
<div class="">
|
||||||
<el-tabs v-model="activeName" @tab-click="tabClick">
|
<el-tabs v-model="activeName" @tab-click="tabClick">
|
||||||
|
|
@ -69,6 +69,12 @@
|
||||||
></el-checkbox>
|
></el-checkbox>
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</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 type="index" width="50" label="#"></el-table-column>
|
||||||
<el-table-column prop="name" label="券名称"></el-table-column>
|
<el-table-column prop="name" label="券名称"></el-table-column>
|
||||||
|
|
||||||
|
|
@ -280,6 +286,7 @@ async function getcoup() {
|
||||||
|
|
||||||
let noUseGoodsCoupon = [];
|
let noUseGoodsCoupon = [];
|
||||||
let noUseDiscountCoupon = [];
|
let noUseDiscountCoupon = [];
|
||||||
|
console.log("orderPrice", orderPrice.value);
|
||||||
for (let i = 0; i < couponList.length; i++) {
|
for (let i = 0; i < couponList.length; i++) {
|
||||||
const coupon = couponList[i];
|
const coupon = couponList[i];
|
||||||
const selCoupon =
|
const selCoupon =
|
||||||
|
|
@ -289,7 +296,7 @@ async function getcoup() {
|
||||||
const canuseResult = UTILS.returnCouponCanUse({
|
const canuseResult = UTILS.returnCouponCanUse({
|
||||||
canDikouGoodsArr,
|
canDikouGoodsArr,
|
||||||
coupon,
|
coupon,
|
||||||
orderPrice: orderPrice.value,
|
goodsOrderPrice: orderPrice.value,
|
||||||
user: props.user,
|
user: props.user,
|
||||||
selCoupon,
|
selCoupon,
|
||||||
shopInfo: shopUser.userInfo,
|
shopInfo: shopUser.userInfo,
|
||||||
|
|
@ -323,7 +330,7 @@ async function getcoup() {
|
||||||
v,
|
v,
|
||||||
props.user,
|
props.user,
|
||||||
orderPrice.value,
|
orderPrice.value,
|
||||||
quansSelArr.value,
|
quansSelArr.value.filter((v) => v.type != 2),
|
||||||
shopUser.userInfo
|
shopUser.userInfo
|
||||||
);
|
);
|
||||||
return {
|
return {
|
||||||
|
|
@ -339,7 +346,7 @@ async function getcoup() {
|
||||||
v,
|
v,
|
||||||
props.user,
|
props.user,
|
||||||
orderPrice.value,
|
orderPrice.value,
|
||||||
quansSelArr.value,
|
quansSelArr.value.filter((v) => v.type == 2),
|
||||||
shopUser.userInfo
|
shopUser.userInfo
|
||||||
);
|
);
|
||||||
return {
|
return {
|
||||||
|
|
@ -426,6 +433,15 @@ function updateSelCoupon() {
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
otherCoupon = otherCoupon.map((v) => {
|
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(
|
const discount = UTILS.returnCouponDiscount(
|
||||||
canDikouGoodsArr,
|
canDikouGoodsArr,
|
||||||
v,
|
v,
|
||||||
|
|
@ -436,12 +452,35 @@ function updateSelCoupon() {
|
||||||
);
|
);
|
||||||
return {
|
return {
|
||||||
...v,
|
...v,
|
||||||
|
canuseResult,
|
||||||
discount,
|
discount,
|
||||||
discountAmount: discount ? discount.discountPrice : v.discountAmount,
|
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];
|
goodsCouponSel.value = goodsCoupon[0];
|
||||||
|
couponSel.value = otherCoupon[0];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue