fix: 修改订单计算逻辑
This commit is contained in:
@@ -161,19 +161,25 @@
|
||||
<div class="order-info">
|
||||
<div class="u-flex u-m-b-10 u-row-between">
|
||||
<span class="title">订单号:</span>
|
||||
|
||||
<span class="u-m-l-10 value">{{ orderInfo.orderNo }}</span>
|
||||
</div>
|
||||
<div class="u-flex u-m-b-10 u-row-between">
|
||||
<span class="title">餐位费</span>
|
||||
<span class="u-m-l-10 value">¥{{ seatAmount }}</span>
|
||||
<span class="u-m-l-10 value">¥{{ carts.orderCostSummary.seatFee }}</span>
|
||||
</div>
|
||||
<div class="u-flex u-m-b-10 u-row-between">
|
||||
<span class="title">打包费</span>
|
||||
<span class="u-m-l-10 value">¥{{ carts.packFee }}</span>
|
||||
<span class="u-m-l-10 value">¥{{ carts.orderCostSummary.packFee }}</span>
|
||||
</div>
|
||||
<div class="u-flex u-m-b-10 u-row-between">
|
||||
<span class="title">商品订单金额</span>
|
||||
<span class="u-m-l-10 value">¥{{ carts.goodsTotal }}</span>
|
||||
<span class="u-m-l-10 value">
|
||||
¥{{
|
||||
carts.orderCostSummary.goodsOriginalAmount -
|
||||
carts.orderCostSummary.goodsDiscountAmount
|
||||
}}
|
||||
</span>
|
||||
</div>
|
||||
<div class="u-flex u-m-b-10 u-row-between">
|
||||
<span class="title">商品优惠券</span>
|
||||
@@ -186,11 +192,13 @@
|
||||
|
||||
<div class="u-flex u-m-b-10 u-row-between">
|
||||
<span class="title">整单改价</span>
|
||||
<span class="u-m-l-10 value color-red">-¥{{ discountAmount }}</span>
|
||||
<span class="u-m-l-10 value color-red">
|
||||
-¥{{ carts.orderCostSummary.merchantReduction.actualAmount }}
|
||||
</span>
|
||||
</div>
|
||||
<div class="u-flex u-m-b-10 u-row-between">
|
||||
<span class="title">积分抵扣</span>
|
||||
<span class="u-m-l-10 value">-¥{{ pointsDiscountAmount }}</span>
|
||||
<span class="u-m-l-10 value">-¥{{ carts.orderCostSummary.pointDeductionAmount }}</span>
|
||||
</div>
|
||||
<div class="u-flex u-m-b-10 u-row-between">
|
||||
<span class="title">抹零</span>
|
||||
@@ -198,11 +206,11 @@
|
||||
</div>
|
||||
<div class="u-flex u-m-b-10 u-row-between">
|
||||
<span class="title">总价(商品订单金额-商品优惠券-满减券-整单改价-积分抵扣)</span>
|
||||
<span class="u-m-l-10 value color-red">¥{{ totalMoney }}</span>
|
||||
<span class="u-m-l-10 value color-red">¥{{ totalPrice }}</span>
|
||||
</div>
|
||||
<div class="u-flex u-m-b-10 u-row-between">
|
||||
<span class="title">应付金额(总价+客座费+打包费)</span>
|
||||
<span class="u-m-l-10 value price">¥{{ currentpayMoney }}</span>
|
||||
<span class="u-m-l-10 value price">¥{{ carts.orderCostSummary.finalPayAmount }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -228,13 +236,12 @@
|
||||
|
||||
<script setup>
|
||||
import * as quanUtil from "../quan_util.js";
|
||||
|
||||
import { OrderPriceCalculator } from "@/utils/goods";
|
||||
import { useCartsStore } from "@/store/modules/carts";
|
||||
import { useUserStore } from "@/store/modules/user";
|
||||
import chooseGuaZahng from "./popup-choose-guazhang.vue";
|
||||
const shopUser = useUserStore();
|
||||
const carts = useCartsStore();
|
||||
|
||||
import popupCoupon from "./popup-coupon.vue";
|
||||
import PointsApi from "@/api/account/points";
|
||||
|
||||
@@ -244,7 +251,13 @@ import scanPay from "./scan-pay.vue";
|
||||
import discount from "./discount.vue";
|
||||
import { ElLoading } from "element-plus";
|
||||
import { ElMessage, ElMessageBox } from "element-plus";
|
||||
import { BigNumber } from "bignumber.js";
|
||||
|
||||
// 配置BigNumber精度
|
||||
BigNumber.set({
|
||||
DECIMAL_PLACES: 2,
|
||||
ROUNDING_MODE: BigNumber.ROUND_DOWN, // 向下取整,符合业务需求
|
||||
});
|
||||
//挂账
|
||||
const refGuaZhang = ref();
|
||||
function refGuaZhangConfirm(guazhangRen) {
|
||||
@@ -312,17 +325,40 @@ function discountConfirm(e) {
|
||||
console.log(e);
|
||||
Object.assign(checkOrderPay, e);
|
||||
if (e.discount) {
|
||||
checkOrderPay.discountAmount = carts.goodsTotal - (carts.goodsTotal * (100 - e.discount)) / 100;
|
||||
carts.setMerchantDiscountReduction(e.discount);
|
||||
} else {
|
||||
carts.setMerchantFixedReduction(e.discountAmount);
|
||||
checkOrderPay.discount = 0;
|
||||
}
|
||||
|
||||
score.sel = -1;
|
||||
usePointsNumber.value = 0;
|
||||
}
|
||||
|
||||
//计算商家减免前金额
|
||||
function returnMerchantReductionDiscount() {
|
||||
const {
|
||||
goodsOriginalAmount, // 商品原价总和
|
||||
goodsDiscountAmount, // 减去商品折扣
|
||||
couponDeductionAmount, // 减去优惠券抵扣
|
||||
pointDeductionAmount, // 减去积分抵扣
|
||||
merchantReductionActualAmount, // 减去商家实际减免金额
|
||||
seatFee, // 加上餐位费(不参与减免)
|
||||
packFee, // 加上打包费(不参与减免)
|
||||
additionalFee,
|
||||
} = carts.orderCostSummary;
|
||||
const total =
|
||||
goodsOriginalAmount - // 商品原价总和
|
||||
goodsDiscountAmount - // 减去商品折扣
|
||||
couponDeductionAmount - // 减去优惠券抵扣
|
||||
pointDeductionAmount; // 减去积分抵扣
|
||||
|
||||
return total <= 0 ? 0 : total;
|
||||
}
|
||||
function discountShow(e) {
|
||||
refDiscount.value.open({
|
||||
amount: carts.goodsTotal - productCouponDiscountAmount.value,
|
||||
// amount: carts.goodsTotal - productCouponDiscountAmount.value,
|
||||
amount: returnMerchantReductionDiscount(),
|
||||
});
|
||||
}
|
||||
|
||||
@@ -392,17 +428,25 @@ watch(
|
||||
}
|
||||
);
|
||||
|
||||
// 返回积分抵扣前金额
|
||||
function returnPointsDiscountAmount() {
|
||||
const total = currentpayMoney.value * 1 + carts.orderCostSummary.pointDeductionAmount * 1;
|
||||
return total <= 0 ? 0 : total;
|
||||
}
|
||||
|
||||
async function pointsInit() {
|
||||
if (!props.user.id || score.sel == -1) {
|
||||
return;
|
||||
}
|
||||
const orderAmount = currentpayMoney.value * 1 + pointsDiscountAmount.value * 1;
|
||||
const res = await PointsApi.calcOrderUsablePoints({
|
||||
shopUserId: props.user.id,
|
||||
orderAmount: orderAmount <= 0 ? 0 : orderAmount,
|
||||
orderAmount: returnPointsDiscountAmount(),
|
||||
});
|
||||
pointsRes.value = res;
|
||||
carts.pointDeductionRule.pointsPerYuan = res.equivalentPoints;
|
||||
|
||||
usePointsNumber.value = res.usable ? res.maxUsablePoints : 0;
|
||||
carts.userPoints = usePointsNumber.value;
|
||||
if (res.usable) {
|
||||
pointsToMoney();
|
||||
} else {
|
||||
@@ -412,12 +456,20 @@ async function pointsInit() {
|
||||
}
|
||||
// 根据积分计算可抵扣金额
|
||||
async function pointsToMoney() {
|
||||
const res = await PointsApi.calcPointsToMoney({
|
||||
shopUserId: props.user.id,
|
||||
orderAmount: currentpayMoney.value * 1 + pointsDiscountAmount.value * 1,
|
||||
points: usePointsNumber.value,
|
||||
});
|
||||
pointsDiscountAmount.value = res;
|
||||
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() {
|
||||
@@ -483,6 +535,8 @@ function returnPayParams() {
|
||||
originAmount: carts.payMoney * 1 + seatAmount.value * 1,
|
||||
discountAmount: discountAmount.value,
|
||||
productCouponDiscountAmount: productCouponDiscountAmount.value * 1,
|
||||
otherCouponDiscountAmount:
|
||||
carts.orderCostSummary.couponDeductionAmount - productCouponDiscountAmount.value * 1,
|
||||
orderAmount: currentpayMoney.value * 1,
|
||||
roundAmount: props.orderInfo.roundAmount,
|
||||
pointsDiscountAmount: pointsDiscountAmount.value * 1,
|
||||
@@ -616,19 +670,18 @@ const discountAmount = computed(() => {
|
||||
});
|
||||
//满减优惠券
|
||||
const fullCouponDiscountAmount = computed(() => {
|
||||
return quansSelArr.value
|
||||
.reduce((pre, cur) => {
|
||||
return pre + cur.discountAmount;
|
||||
}, 0)
|
||||
.toFixed(2);
|
||||
return (
|
||||
carts.orderCostSummary.fullCouponDeduction || props.orderInfo.fullCouponDiscountAmount || 0
|
||||
);
|
||||
});
|
||||
//商品券抵扣金额
|
||||
const productCouponDiscountAmount = computed(() => {
|
||||
let index = -1;
|
||||
return quansSelArr.value.reduce((pre, cur) => {
|
||||
index++;
|
||||
return pre + returnProDiscount(cur, index) * 1;
|
||||
}, 0);
|
||||
// 优先从 Store 扩展字段取,若无则用 props 数据(过渡方案)
|
||||
return (
|
||||
carts.orderCostSummary.productCouponDeduction ||
|
||||
props.orderInfo.productCouponDiscountAmount ||
|
||||
0
|
||||
);
|
||||
});
|
||||
//除开客座费,打包费总金额
|
||||
const totalMoney = computed(() => {
|
||||
@@ -640,9 +693,30 @@ const totalMoney = computed(() => {
|
||||
pointsDiscountAmount.value
|
||||
).toFixed(2);
|
||||
});
|
||||
|
||||
const totalPrice = computed(() => {
|
||||
// 使用bignumber.js处理高精度计算
|
||||
const originalAmount = new BigNumber(carts.orderCostSummary.goodsOriginalAmount);
|
||||
const discountAmount = new BigNumber(carts.orderCostSummary.goodsDiscountAmount);
|
||||
const couponDeduction = new BigNumber(carts.orderCostSummary.couponDeductionAmount);
|
||||
const merchantReduction = new BigNumber(carts.orderCostSummary.merchantReduction.actualAmount);
|
||||
const pointDeduction = new BigNumber(carts.orderCostSummary.pointDeductionAmount);
|
||||
|
||||
// 逐步计算:原价 - 商品折扣 - 优惠券 - 商家减免 - 积分抵扣
|
||||
const total = originalAmount
|
||||
.minus(discountAmount)
|
||||
.minus(couponDeduction)
|
||||
.minus(merchantReduction)
|
||||
.minus(pointDeduction)
|
||||
.decimalPlaces(2, BigNumber.ROUND_DOWN); // 保持与工具库一致的舍入策略
|
||||
|
||||
return total.toNumber();
|
||||
});
|
||||
|
||||
//应付金额
|
||||
const currentpayMoney = computed(() => {
|
||||
return (totalMoney.value * 1 + carts.packFee * 1 + seatAmount.value * 1).toFixed(2);
|
||||
return carts.orderCostSummary.finalPayAmount;
|
||||
// return (totalMoney.value * 1 + carts.packFee * 1 + seatAmount.value * 1).toFixed(2);
|
||||
});
|
||||
watch(
|
||||
() => currentpayMoney.value,
|
||||
|
||||
Reference in New Issue
Block a user