霸王餐,满减活动等问题修复

This commit is contained in:
2025-10-17 20:22:59 +08:00
parent d858a34698
commit 5d98b7efc2
7 changed files with 239 additions and 129 deletions

View File

@@ -158,6 +158,9 @@ const groupChanges = (type) => {
return; return;
} }
const item = paymentMethodList.value.find((v) => v.type == type); const item = paymentMethodList.value.find((v) => v.type == type);
console.log("groupChanges", item);
console.log("props.disablePayType", props.disablePayType);
if (item && returnDisabled(item)) { if (item && returnDisabled(item)) {
uni.showToast({ uni.showToast({
title: "当前支付方式不可用", title: "当前支付方式不可用",
@@ -170,7 +173,7 @@ const groupChanges = (type) => {
// } // }
radiovalue.value = type; radiovalue.value = type;
let name = paymentMethodName.value[type - 1].name; let name = paymentMethodName.value[type - 1].name;
console.log('emit:groupChange',paymentMethodName.value[type - 1]);
emits("groupChange", paymentMethodName.value[type - 1]); emits("groupChange", paymentMethodName.value[type - 1]);
}; };

View File

@@ -577,7 +577,7 @@ const goUrl = (item) => {
return; return;
} }
chnageIsUsePoints(); chnageIsUsePoints();
break; break;
} }
}; };
@@ -608,16 +608,25 @@ async function getMaxPointsDiscount() {
shopUserId: props.orderVIP.id, shopUserId: props.orderVIP.id,
orderAmount: maxMoney.value, orderAmount: maxMoney.value,
}); });
if(res){
cartStore.setPointDeductionRule(
res.equivalentPoints,
res.maxDeductionAmount
);
}
Object.assign(pointsRes, res); Object.assign(pointsRes, res);
maxPointDiscount.value = res.maxDeductionAmount; maxPointDiscount.value = res.maxDeductionAmount;
console.log("积分可抵扣最大金额", maxPointDiscount.value);
console.log("是否可以用积分", usePoints.value);
if (usePoints.value) { if (usePoints.value) {
console.log("积分抵扣金额", res.maxDeductionAmount);
cartStore.setUserPoints(res.maxUsablePoints || 0); cartStore.setUserPoints(res.maxUsablePoints || 0);
} }
} }
watch( watch(
() => maxMoney.value, () => maxMoney.value,
(newval) => { (newval) => {
console.log("maxMoney.value", newval);
getMaxPointsDiscount(); getMaxPointsDiscount();
} }
); );
@@ -734,6 +743,7 @@ watch(
const originalPrice = computed(() => { const originalPrice = computed(() => {
const originalPrice = const originalPrice =
cartStore.orderCostSummary.goodsRealAmount + cartStore.orderCostSummary.goodsRealAmount +
-cartStore.orderCostSummary.newUserDiscount +
cartStore.orderCostSummary.packFee + cartStore.orderCostSummary.packFee +
cartStore.orderCostSummary.seatFee; cartStore.orderCostSummary.seatFee;
console.log("originalPrice", originalPrice); console.log("originalPrice", originalPrice);
@@ -760,14 +770,24 @@ watch(
disabledCouponUse.value = true; disabledCouponUse.value = true;
disabledCouponReason.value = "霸王餐与优惠券不可同时使用"; disabledCouponReason.value = "霸王餐与优惠券不可同时使用";
cartStore.setCoupons([]); cartStore.setCoupons([]);
} else {
disabledCouponUse.value = false;
disabledCouponReason.value = "";
} }
if (!freeDineConfig.withPoints) { if (!freeDineConfig.withPoints) {
disabledPointsUse.value = true; disabledPointsUse.value = true;
disabledPointsUseReason.value = "霸王餐与积分不可同时使用"; disabledPointsUseReason.value = "霸王餐与积分不可同时使用";
usePoints.value = false; usePoints.value = false;
cartStore.setUserPoints(0); cartStore.setUserPoints(0);
} else {
disabledPointsUse.value = false;
disabledPointsUseReason.value = "";
} }
} else { } else {
disabledPointsUse.value = false;
disabledPointsUseReason.value = "";
disabledCouponUse.value = false;
disabledCouponReason.value = "";
if (back_discountActivity) { if (back_discountActivity) {
calcDiscountActivity(); calcDiscountActivity();
} }
@@ -783,11 +803,18 @@ function calcDiscountActivity() {
if (!res.vipPriceShare && user.isVip) { if (!res.vipPriceShare && user.isVip) {
return; return;
} }
console.log("calcDiscountActivity:originalPrice", originalPrice.value);
if (res && res.thresholds && res.thresholds.length > 0) { if (res && res.thresholds && res.thresholds.length > 0) {
console.log("calcDiscountActivity", res); const canUseThresholds = res.thresholds
const canUseThresholds = res.thresholds.filter((v) => { .filter((v) => {
return originalPrice.value >= v.fullAmount; return originalPrice.value >= v.fullAmount;
}); })
.sort((a, b) => {
return b.discountAmount - a.discountAmount;
});
console.log("canUseThresholds", canUseThresholds);
if (canUseThresholds.length) { if (canUseThresholds.length) {
discountActivity.value = canUseThresholds[0]; discountActivity.value = canUseThresholds[0];
back_discountActivity = canUseThresholds[0]; back_discountActivity = canUseThresholds[0];
@@ -822,8 +849,8 @@ async function getDiscountActivity() {
discountActivityRes.value = res; discountActivityRes.value = res;
calcDiscountActivity(); calcDiscountActivity();
} }
onMounted(() => { onMounted(async () => {
getConsumeDiscount(); await getConsumeDiscount();
getDiscountActivity(); getDiscountActivity();
}); });
</script> </script>

View File

@@ -100,12 +100,13 @@
<rechargeFree <rechargeFree
:freeDineConfig="orderVIP.freeDineConfig" :freeDineConfig="orderVIP.freeDineConfig"
:payAmount="listinfo.totalPrices" :payAmount="listinfo.totalPrices"
v-if="showFreeDine" v-if="showFreeDine && (listinfo.status == 'unpaid' || !listinfo.id)"
@changeFree="changeFree" @changeFree="changeFree"
> >
</rechargeFree> </rechargeFree>
<!-- 充值享优惠 --> <!-- 充值享优惠 -->
<view v-else> <view v-if="!showFreeDine && (listinfo.status == 'unpaid' || !listinfo.id)">
<ChargeVue <ChargeVue
@updateChargeSel="updateChargeSel" @updateChargeSel="updateChargeSel"
@updateRechargeId="updateRechargeId" @updateRechargeId="updateRechargeId"
@@ -305,7 +306,11 @@ function updateChargeSel(newval) {
} }
return; return;
} }
disablePayType.value = []; if (cartStore.orderCostSummary.orderOriginFinalPayAmount <= 0) {
disablePayType.value = ["微信支付"];
} else {
disablePayType.value = [];
}
} }
async function onMessage(Message) { async function onMessage(Message) {
@@ -322,6 +327,7 @@ async function onMessage(Message) {
orderId: listinfo.id, orderId: listinfo.id,
}); });
console.log("onMessage:APIgetOrderById", res); console.log("onMessage:APIgetOrderById", res);
Object.assign(listinfo, res);
if (res) { if (res) {
orderRemarker.value = res.remark; orderRemarker.value = res.remark;
// cartStore.carts=[]; // cartStore.carts=[];
@@ -418,23 +424,7 @@ const shopQrcode = ref(ordershopUserInfo.shopInfo || false);
// 霸王餐 // 霸王餐
const isBwc = ref(false); const isBwc = ref(false);
//是否显示霸王餐 //是否显示霸王餐
const showFreeDine = computed(() => { const showFreeDine = ref(false);
//原始金额
const originMoney = BigNumber(cartStore.orderCostSummary.goodsOriginalAmount)
.plus(cartStore.orderCostSummary.packFee)
.plus(cartStore.orderCostSummary.seatFee)
.plus(cartStore.orderCostSummary.additionalFee);
//实付金额=原始金额*倍数
// const fullAmount=originMoney.times(oorderVIP.value.freeDineConfig.multiple)
if (
(listinfo.status == "unpaid" || !listinfo.id) &&
orderVIP.value.freeDineConfig.enable &&
originMoney >= orderVIP.value.freeDineConfig.rechargeThreshold
) {
return true;
}
});
//订单备注 //订单备注
const orderRemarker = ref(""); const orderRemarker = ref("");
@@ -473,6 +463,7 @@ const orderorderInfo = async () => {
tableCode: options.tableCode, tableCode: options.tableCode,
}); });
orderRemarker.value = res.remark; orderRemarker.value = res.remark;
Object.assign(listinfo, res);
if (res && res.tableCode) { if (res && res.tableCode) {
socketInitPar.table_code = res.tableCode; socketInitPar.table_code = res.tableCode;
let tableRes = await getTableInfo({ let tableRes = await getTableInfo({
@@ -655,18 +646,15 @@ const paymentmethod = reactive({
}); });
const groupChange = async (e) => { const groupChange = async (e) => {
if (e == 5) {
return;
}
console.log("groupChange", e);
paymentmethod.radiovalue = e.type; paymentmethod.radiovalue = e.type;
paymentmethod.paymentBtnText = e.name; paymentmethod.paymentBtnText = e.name;
paymentmethod.payType = e.payType; paymentmethod.payType = e.payType;
}; };
// * 去充值
const goRecharge = () => {
uni.pro.navigateTo("/pages/member/index", {
shopId: listinfo.shopId,
});
};
// 操作下单时候 // 操作下单时候
const orderInfoAfterRef = ref(null); const orderInfoAfterRef = ref(null);
@@ -799,6 +787,7 @@ function pay_lock() {
} }
function pay_unlock() { function pay_unlock() {
console.log("pay_unlock");
clearInterval(payStatusTimer); clearInterval(payStatusTimer);
cartsSocket.sendMessage({ cartsSocket.sendMessage({
...socketInitPar, ...socketInitPar,
@@ -818,7 +807,6 @@ async function search_pay_lock() {
} }
let payStatusTimer = null; let payStatusTimer = null;
let orderIsLock = true; let orderIsLock = true;
let usePoints = ref(0);
function returnPayParams() { function returnPayParams() {
const checkOrderPay = { const checkOrderPay = {
@@ -833,7 +821,7 @@ function returnPayParams() {
cartStore.orderCostSummary.productCouponDeduction, //商品优惠券抵扣金额 cartStore.orderCostSummary.productCouponDeduction, //商品优惠券抵扣金额
otherCouponDiscountAmount: cartStore.orderCostSummary.fullCouponDeduction, //其他优惠券抵扣金额 otherCouponDiscountAmount: cartStore.orderCostSummary.fullCouponDeduction, //其他优惠券抵扣金额
couponList: cartStore.backendCoupons.map((v) => v.id), //用户使用的卡券 couponList: cartStore.backendCoupons.map((v) => v.id), //用户使用的卡券
orderAmount: cartStore.orderCostSummary.finalPayAmount, // 最终订单金额 orderAmount:isBwc.value? cartStore.orderCostSummary.orderOriginFinalPayAmount: cartStore.orderCostSummary.finalPayAmount, // 最终订单金额
roundAmount: 0, //抹零金额 减免多少钱 roundAmount: 0, //抹零金额 减免多少钱
pointsDiscountAmount: cartStore.orderCostSummary.pointDeductionAmount, //积分抵扣金额(tb_points_basic_setting表) pointsDiscountAmount: cartStore.orderCostSummary.pointDeductionAmount, //积分抵扣金额(tb_points_basic_setting表)
pointsNum: cartStore.orderCostSummary.pointUsed, //(扣除各类折扣 enable_deduction后使用) pointsNum: cartStore.orderCostSummary.pointUsed, //(扣除各类折扣 enable_deduction后使用)
@@ -844,8 +832,10 @@ function returnPayParams() {
: "", : "",
remark: orderRemarker.value, //用户备注 remark: orderRemarker.value, //用户备注
discountActAmount: cartStore.orderCostSummary.fullReduction.actualAmount, //满减抵扣金额 discountActAmount: cartStore.orderCostSummary.fullReduction.actualAmount, //满减抵扣金额
userId: uni.cache.get("userInfo").id || "", //
}; };
return { return {
isBwc: isBwc.value,
checkOrderPay, checkOrderPay,
payType: paymentmethod.payType, payType: paymentmethod.payType,
buyerRemark: "", buyerRemark: "",
@@ -855,6 +845,7 @@ function returnPayParams() {
shopUserId: orderVIP.value.id, shopUserId: orderVIP.value.id,
shopId: orderVIP.value.shopId, shopId: orderVIP.value.shopId,
pwd: "", pwd: "",
userId: uni.cache.get("userInfo").id || "", //
discountActld: cartStore.orderCostSummary.fullReduction.usedActivity discountActld: cartStore.orderCostSummary.fullReduction.usedActivity
? cartStore.orderCostSummary.fullReduction.usedActivity.id ? cartStore.orderCostSummary.fullReduction.usedActivity.id
: "", //满减活动id : "", //满减活动id
@@ -862,35 +853,39 @@ function returnPayParams() {
} }
const istoricalorders = async () => { const istoricalorders = async () => {
const payParams = returnPayParams();
console.log("istoricalorders:payParams", payParams);
//先付 //先付
if (isPayBefor()) { if (isPayBefor()) {
// 购物车有数据 // 购物车有数据
if (!cartStore.isEmpty) { if (!cartStore.isEmpty) {
usePoints = cartStore.orderCostSummary.pointUsed;
const res = await createOrder(); const res = await createOrder();
//历史订单数据 //历史订单数据
const res1 = await APIgetOrderById({ const res1 = await APIgetOrderById({
orderId: res.id, orderId: res.id,
}); });
Object.assign(listinfo, res1);
orderRemarker.value = res1.remark; orderRemarker.value = res1.remark;
cartStore.setOldOrder(res1); cartStore.setOldOrder(res1);
} }
goToPay(); goToPay(payParams);
// goToPay() // goToPay()
} else { } else {
//后付 //后付
// 购物车有数据 // 购物车有数据
if (!cartStore.isEmpty) { if (!cartStore.isEmpty) {
usePoints = cartStore.orderCostSummary.pointUsed;
const res = await createOrder(); const res = await createOrder();
//历史订单数据 //历史订单数据
const res1 = await APIgetOrderById({ const res1 = await APIgetOrderById({
orderId: res.id, orderId: res.id,
}); });
Object.assign(listinfo, res1);
orderRemarker.value = res1.remark; orderRemarker.value = res1.remark;
cartStore.setOldOrder(res1); cartStore.setOldOrder(res1);
goToPay(); goToPay(payParams);
return; return;
} }
// 先调用历史订单 // 先调用历史订单
@@ -908,7 +903,7 @@ const istoricalorders = async () => {
} }
// 判断支付之前是是否还有新加订单 // 判断支付之前是是否还有新加订单
if (listinfo.combinedArray.length === combinedArray.length) { if (listinfo.combinedArray.length === combinedArray.length) {
goToPay(); goToPay(payParams);
} else { } else {
uni.showToast({ uni.showToast({
title: "你的订单已更新!", title: "你的订单已更新!",
@@ -929,11 +924,11 @@ const istoricalorders = async () => {
}; };
// * 去支付 // * 去支付
const goToPay = async (isCreateOrder = false) => { const goToPay = async (payParams) => {
const payParams = returnPayParams(); console.log("goToPay:payParams", payParams);
const { checkOrderPay } = payParams;
// 余额支付 // 余额支付
if (paymentmethod.payType == "accountPay") { if (payParams.payType == "accountPay") {
if (orderVIP.value.payPwd == "") { if (orderVIP.value.payPwd == "") {
uni.showModal({ uni.showModal({
title: "提示", title: "提示",
@@ -966,30 +961,50 @@ const goToPay = async (isCreateOrder = false) => {
title: "有人正在付款中!", title: "有人正在付款中!",
icon: "none", icon: "none",
}); });
const shopUserInfo = uni.cache.get("shopUserInfo");
console.log("shopUserInfo", shopUserInfo);
console.log("listinfo", listinfo);
if (shopUserInfo) {
if (shopUserInfo.userId == listinfo.userId) {
pay_unlock();
}
}
return; return;
} }
console.log("canPay:goToPay:payParams", payParams);
pay_lock(); pay_lock();
payStatusTimer = setInterval(() => { payStatusTimer = setInterval(() => {
pay_lock(); pay_lock();
}, 1000); }, 1000);
console.log("霸王餐前payParams", payParams);
if (orderVIP.value.freeDineConfig.enable && isBwc.value) { if (payParams.isBwc) {
const isPaySuccess = await storeMemberpay.actionspayltPayVip({ payParams.checkOrderPay.orderId = listinfo.id;
shopId: orderVIP.value.shopId, console.log("霸王餐支付参数:", payParams);
shopUserId: orderVIP.value.id, try {
orderId: listinfo.id, const isPaySuccess = await storeMemberpay.actionspayltPayVip({
userAllPack: is_type.value == 0 ? 0 : 1, //是否整单打包 ...payParams,
amount: cartStore.orderCostSummary.finalPayAmount, // 最终订单金额 shopId: orderVIP.value.shopId,
orderAmount: cartStore.orderCostSummary.orderOriginFinalPayAmount, // 最终订单原金额 shopUserId: orderVIP.value.id,
originAmount: cartStore.orderCostSummary.goodsRealAmount, //订单原金额(不包含打包费+餐位费) orderId: listinfo.id,
returnUrl: "", //跳转地址 userAllPack: is_type.value == 0 ? 0 : 1, //是否整单打包
buyerRemark: "", amount: cartStore.orderCostSummary.finalPayAmount, // 最终订单金额
seatNum: is_type.value == 0 ? cartStore.seatFeeConfig.personCount : 0, //用餐人数 orderAmount: cartStore.orderCostSummary.orderOriginFinalPayAmount, // 最终订单原金额
}); originAmount: cartStore.orderCostSummary.goodsRealAmount, //订单原金额(不包含打包费+餐位费)
if (isPaySuccess) { returnUrl: "", //跳转地址
paySucessCallback(); buyerRemark: "",
seatNum: is_type.value == 0 ? cartStore.seatFeeConfig.personCount : 0, //用餐人数
});
if (isPaySuccess) {
paySucessCallback();
orderorderInfo();
pay_unlock();
}
} catch (error) {
console.log("error", error);
pay_unlock();
} }
orderorderInfo();
return false; return false;
} else { } else {
payParams.checkOrderPay.orderId = listinfo.id; payParams.checkOrderPay.orderId = listinfo.id;
@@ -1026,6 +1041,14 @@ const memberPointscalcUsablePoints = async () => {
shopUserId: orderVIP.value.id, shopUserId: orderVIP.value.id,
orderAmount: listinfo.totalCost, orderAmount: listinfo.totalCost,
}); });
console.log('获取订单可用积分及抵扣金额(支付页面使用)')
if(res){
cartStore.setPointDeductionRule(
res.equivalentPoints,
res.maxDeductionAmount
);
}
orderInfoAfterRef.value?.getCalcUsablePoints(res); orderInfoAfterRef.value?.getCalcUsablePoints(res);
}; };
// //
@@ -1056,6 +1079,43 @@ const accountPayevent = async (pwd) => {
} }
orderorderInfo(); orderorderInfo();
}; };
watch(
() => cartStore.orderCostSummary.orderOriginFinalPayAmount,
(newval) => {
console.log("orderOriginFinalPayAmount", newval);
if (newval <= 0) {
disablePayType.value = ["微信支付"];
paymentMethodref.value.groupChanges(1);
}
if (
newval <= 0 ||
newval < orderVIP.value.freeDineConfig.rechargeThreshold
) {
isBwc.value = false;
showFreeDine.value = false;
return;
}
disablePayType.value = [];
if (
(listinfo.status == "unpaid" || !listinfo.id) &&
orderVIP.value.freeDineConfig.enable &&
newval >= orderVIP.value.freeDineConfig.rechargeThreshold
) {
showFreeDine.value = true;
}
},
{
immediate: true,
}
);
watch(
() => isBwc.value,
(newval) => {
cartStore.isFreeDine = newval;
}
);
onBeforeUnmount(() => { onBeforeUnmount(() => {
uni.$off("returnData", handleReturnData); uni.$off("returnData", handleReturnData);
@@ -1170,6 +1230,7 @@ async function init(opt) {
cartStore.setSeatFeeConfig("personCount", res.seatNum); cartStore.setSeatFeeConfig("personCount", res.seatNum);
cartStore.setDinnerType(res.dineMode || "dine-in"); cartStore.setDinnerType(res.dineMode || "dine-in");
orderRemarker.value = res.remark; orderRemarker.value = res.remark;
Object.assign(listinfo, res);
} }
} }
//获取店铺信息 //获取店铺信息

View File

@@ -57,6 +57,13 @@
<text v-if="item.bizCode == 'adminOut'"> <text v-if="item.bizCode == 'adminOut'">
管理员消费 管理员消费
</text> </text>
<text v-if="item.bizCode == 'cashback'">
消费返现
</text>
<text v-if="item.bizCode == 'freeIn'">
霸王餐充值
</text>
</view> </view>
<view v-else> <view v-else>
{{item.content}} {{item.content}}

View File

@@ -128,7 +128,7 @@ export const useCartsStore = defineStore("cart", () => {
//积分规则 //积分规则
const pointDeductionRule = ref({ const pointDeductionRule = ref({
pointsPerYuan: 100, pointsPerYuan: 0,
maxDeductionAmount: Infinity, maxDeductionAmount: Infinity,
}); });
@@ -606,7 +606,7 @@ export const useCartsStore = defineStore("cart", () => {
dinnerType.value = "dine-in"; dinnerType.value = "dine-in";
userPoints.value = 0; userPoints.value = 0;
fullReductionActivities.value = []; fullReductionActivities.value = [];
isFreeDine.value = false; isFreeDine.value = false;
} }
return { return {
@@ -649,8 +649,8 @@ export const useCartsStore = defineStore("cart", () => {
//清空配置 //清空配置
clearOrderConfig, clearOrderConfig,
//满减活动 //满减活动
fullReductionActivities, fullReductionActivities,
isFreeDine,//是否使用霸王餐 isFreeDine, //是否使用霸王餐
// 商家霸王餐配置 // 商家霸王餐配置
freeDineConfig, freeDineConfig,
}; };

View File

@@ -238,7 +238,6 @@ export const Memberpay = defineStore('memberpay', {
placeNum: data.placeNum, //当前订单下单次数 placeNum: data.placeNum, //当前订单下单次数
waitCall: data.waitCall //是否等叫 0 否 1 等叫 waitCall: data.waitCall //是否等叫 0 否 1 等叫
}) })
console.log('actionscreateOrder res:');
console.log(res); console.log(res);
if (res) { if (res) {
resolve(res) resolve(res)

View File

@@ -288,7 +288,7 @@ export interface OrderCostSummary {
actualAmount: number; // 满减实际减免金额(元) actualAmount: number; // 满减实际减免金额(元)
}; };
// 订单原支付金额 // 订单原支付金额
orderOriginFinalPayAmount: number; //订单原金额(包含打包费+餐位费) orderOriginFinalPayAmount: number; //订单原金额(包含打包费+餐位费)
} }
/** 满减活动阈值单条满减规则满X减Y- 对应 MkDiscountThresholdInsertGroupDefaultGroup */ /** 满减活动阈值单条满减规则满X减Y- 对应 MkDiscountThresholdInsertGroupDefaultGroup */
@@ -414,7 +414,6 @@ export function filterOptimalFullReductionActivity(
currentTime: Date = new Date() currentTime: Date = new Date()
): FullReductionActivity | undefined { ): FullReductionActivity | undefined {
if (!activities || !activities.length) return undefined; if (!activities || !activities.length) return undefined;
console.log("原始满减活动列表:", activities);
// 第一步:基础筛选(未删除+当前店铺+活动进行中+就餐类型匹配) // 第一步:基础筛选(未删除+当前店铺+活动进行中+就餐类型匹配)
const baseEligible = activities.filter((activity) => { const baseEligible = activities.filter((activity) => {
return ( return (
@@ -425,7 +424,6 @@ export function filterOptimalFullReductionActivity(
activity.thresholds?.length // 至少有一个满减阈值 activity.thresholds?.length // 至少有一个满减阈值
); );
}); });
console.log("基础筛选结果:", baseEligible);
if (!baseEligible.length) return undefined; if (!baseEligible.length) return undefined;
// 第二步:时间筛选(有效期内+周期内+时段内) // 第二步:时间筛选(有效期内+周期内+时段内)
@@ -814,10 +812,7 @@ export function selectOptimalThreshold(
if (!thresholds.length) return undefined; if (!thresholds.length) return undefined;
// 第一步确定满减门槛基数根据discountShare规则 // 第一步确定满减门槛基数根据discountShare规则
const thresholdBase = const thresholdBase = baseAmount;
discountShare === 1
? new BigNumber(goodsRealAmount) // 与限时折扣同享→用折扣后金额
: new BigNumber(goodsOriginalAmount); // 不同享→用原价
// 第二步:筛选「满金额≤基数」且「减免金额>0」的有效阈值 // 第二步:筛选「满金额≤基数」且「减免金额>0」的有效阈值
const validThresholds = thresholds.filter((threshold) => { const validThresholds = thresholds.filter((threshold) => {
@@ -830,21 +825,34 @@ export function selectOptimalThreshold(
}); });
if (!validThresholds.length) return undefined; if (!validThresholds.length) return undefined;
// 第三步选择最优阈值优先级1.满金额最小 → 2.减免金额最大) // 第三步选择最优阈值优先级1.满金额最小 → 2.减免金额最大)
return validThresholds.sort((a, b) => { // const sortValidThresholds = validThresholds.sort((a, b) => {
const aFull = new BigNumber(a.fullAmount || 0); // const aFull = new BigNumber(a.fullAmount || 0);
const bFull = new BigNumber(b.fullAmount || 0); // const bFull = new BigNumber(b.fullAmount || 0);
const aDiscount = new BigNumber(a.discountAmount || 0); // const aDiscount = new BigNumber(a.discountAmount || 0);
const bDiscount = new BigNumber(b.discountAmount || 0); // const bDiscount = new BigNumber(b.discountAmount || 0);
// 先比满金额越小越优先满1减10 比 满100减20 更优) // // 先比满金额越小越优先满1减10 比 满100减20 更优)
if (!aFull.isEqualTo(bFull)) { // if (!aFull.isEqualTo(bFull)) {
return aFull.comparedTo(bFull) || 0; // Ensure a number is always returned // return aFull.comparedTo(bFull) || 0; // Ensure a number is always returned
} // }
// 再比减免金额:越大越优先 // // 再比减免金额:越大越优先
return bDiscount.comparedTo(aDiscount) || 0; // Ensure a number is always returned // return bDiscount.comparedTo(aDiscount) || 0; // Ensure a number is always returned
})[0]; // })
// 找到抵扣金额最大的门槛项
const maxDiscountThreshold = validThresholds.reduce(
(maxItem, currentItem) => {
// 处理空值默认抵扣金额为0
const maxDiscount = new BigNumber(maxItem?.discountAmount || 0);
const currentDiscount = new BigNumber(currentItem?.discountAmount || 0);
// 比较当前项和已存最大项的抵扣金额,保留更大的
return currentDiscount.gt(maxDiscount) ? currentItem : maxItem;
},
validThresholds[0] || null
); // 初始值为数组第一项若数组为空则返回null
console.log("maxDiscountThreshold", maxDiscountThreshold);
return maxDiscountThreshold;
} }
/** /**
@@ -1016,6 +1024,7 @@ export function calcPointDeduction(
deductionAmount: number; deductionAmount: number;
usedPoints: number; usedPoints: number;
} { } {
console.log("calcPointDeduction", userPoints, rule, maxDeductionLimit);
if (rule.pointsPerYuan <= 0 || userPoints <= 0) { if (rule.pointsPerYuan <= 0 || userPoints <= 0) {
return { deductionAmount: 0, usedPoints: 0 }; return { deductionAmount: 0, usedPoints: 0 };
} }
@@ -1098,12 +1107,21 @@ export function calculateOrderCostSummary(
currentTime currentTime
); );
// 其他费用计算(原有逻辑不变) ------------------------------
const packFee = calcTotalPackFee(goodsList, dinnerType); // 打包费
let seatFee = calcSeatFee(config.seatFeeConfig); // 餐位费
seatFee = dinnerType === "dine-in" ? seatFee : 0; // 外卖不收餐位费
const additionalFee = Math.max(0, config.additionalFee); // 附加费
// 2.2 计算满减基数(先扣新客立减) // 2.2 计算满减基数(先扣新客立减)
const baseAfterNewUserDiscount = new BigNumber(goodsRealAmount) let baseAfterNewUserDiscount = new BigNumber(goodsRealAmount)
.minus(newUserDiscount) .minus(newUserDiscount)
.isGreaterThan(0) .plus(packFee)
? new BigNumber(goodsRealAmount).minus(newUserDiscount).toNumber() .plus(seatFee)
: 0; .plus(additionalFee)
.toNumber();
baseAfterNewUserDiscount =
baseAfterNewUserDiscount > 0 ? baseAfterNewUserDiscount : 0;
// 2.3 选择最优满减阈值(多门槛场景) // 2.3 选择最优满减阈值(多门槛场景)
if (usedFullReductionActivity) { if (usedFullReductionActivity) {
@@ -1122,7 +1140,6 @@ export function calculateOrderCostSummary(
usedFullReductionThreshold usedFullReductionThreshold
); );
} }
// ------------------------------ 3. 优惠券抵扣(适配满减同享规则) ------------------------------ // ------------------------------ 3. 优惠券抵扣(适配满减同享规则) ------------------------------
let couponDeductionAmount = 0; let couponDeductionAmount = 0;
let productCouponDeduction = 0; let productCouponDeduction = 0;
@@ -1144,7 +1161,6 @@ export function calculateOrderCostSummary(
currentTime, currentTime,
} }
); );
console.log("优惠券计算结果", couponResult);
couponDeductionAmount = couponResult.deductionAmount; couponDeductionAmount = couponResult.deductionAmount;
productCouponDeduction = couponResult.productCouponDeduction; productCouponDeduction = couponResult.productCouponDeduction;
fullCouponDeduction = couponResult.fullCouponDeduction; fullCouponDeduction = couponResult.fullCouponDeduction;
@@ -1153,46 +1169,49 @@ export function calculateOrderCostSummary(
// 若满减与优惠券同享couponShare=1才计算优惠券否则优惠券抵扣为0 // 若满减与优惠券同享couponShare=1才计算优惠券否则优惠券抵扣为0
if (usedFullReductionActivity && !usedFullReductionActivity.couponShare) { if (usedFullReductionActivity && !usedFullReductionActivity.couponShare) {
couponDeductionAmount=0; couponDeductionAmount = 0;
productCouponDeduction=0; productCouponDeduction = 0;
fullCouponDeduction=0; fullCouponDeduction = 0;
usedCoupon=undefined; usedCoupon = undefined;
excludedProductIds=[]; excludedProductIds = [];
} }
// ------------------------------ 4. 积分抵扣(适配满减同享规则) ------------------------------ // ------------------------------ 4. 积分抵扣(适配满减同享规则) ------------------------------
let pointDeductionAmount = 0; let pointDeductionAmount = 0;
let usedPoints = 0; let usedPoints = 0;
// 计算积分抵扣基数(商品折扣后 - 新客立减 - 满减 - 优惠券) // 计算积分抵扣基数(商品折扣后 - 新客立减 - 满减 - 优惠券 + 餐位费 + 打包费 + 附加费
const maxPointDeductionLimit = new BigNumber(goodsRealAmount) let maxPointDeductionLimit = new BigNumber(goodsRealAmount)
.minus(newUserDiscount) .minus(newUserDiscount)
.minus(fullReductionAmount) .minus(fullReductionAmount)
.minus(couponDeductionAmount) .minus(couponDeductionAmount)
.isGreaterThan(0) .plus(seatFee)
? new BigNumber(goodsRealAmount) .plus(packFee)
.minus(newUserDiscount) .plus(additionalFee)
.minus(fullReductionAmount) .toNumber();
.minus(couponDeductionAmount) maxPointDeductionLimit =
.toNumber() maxPointDeductionLimit > 0 ? maxPointDeductionLimit : 0;
: 0;
// 若满减与积分同享pointsShare=1才计算积分否则积分抵扣为0
if ( const pointResult = calcPointDeduction(
usedFullReductionActivity?.pointsShare === 1 && config.userPoints,
maxPointDeductionLimit > 0 config.pointDeductionRule,
) { maxPointDeductionLimit
const pointResult = calcPointDeduction( );
config.userPoints, console.log("积分抵扣结果:", pointResult);
config.pointDeductionRule,
maxPointDeductionLimit pointDeductionAmount = pointResult.deductionAmount;
); usedPoints = pointResult.usedPoints;
pointDeductionAmount = pointResult.deductionAmount; // 若满减与积分不同享pointsShare=1积分抵扣为0
usedPoints = pointResult.usedPoints; if (usedFullReductionActivity && !usedFullReductionActivity.pointsShare) {
console.log("满减与积分不同享:积分抵扣为0");
pointDeductionAmount = 0;
usedPoints = 0;
} }
//使用霸王餐 //使用霸王餐
if (isFreeDine && freeDineConfig && freeDineConfig.enable) { if (isFreeDine && freeDineConfig && freeDineConfig.enable) {
console.log("使用霸王餐");
//不与优惠券同享 //不与优惠券同享
if (!freeDineConfig.withCoupon) { if (!freeDineConfig.withCoupon) {
couponDeductionAmount = 0; couponDeductionAmount = 0;
@@ -1208,12 +1227,6 @@ export function calculateOrderCostSummary(
} }
} }
// ------------------------------ 5. 其他费用计算(原有逻辑不变) ------------------------------
const packFee = calcTotalPackFee(goodsList, dinnerType); // 打包费
let seatFee = calcSeatFee(config.seatFeeConfig); // 餐位费
seatFee = dinnerType === "dine-in" ? seatFee : 0; // 外卖不收餐位费
const additionalFee = Math.max(0, config.additionalFee); // 附加费
// 商家减免计算(原有逻辑不变) // 商家减免计算(原有逻辑不变)
const merchantReductionConfig = config.merchantReduction; const merchantReductionConfig = config.merchantReduction;
let merchantReductionActualAmount = 0; let merchantReductionActualAmount = 0;
@@ -1270,7 +1283,7 @@ export function calculateOrderCostSummary(
truncateToTwoDecimals(finalPayAmountBn.toNumber()) truncateToTwoDecimals(finalPayAmountBn.toNumber())
); );
// ------------------------------ 使用霸王餐计算 ------------------------------ // ------------------------------ 使用霸王餐计算 ------------------------------
let orderOriginFinalPayAmount=finalPayAmount; let orderOriginFinalPayAmount = finalPayAmount;
if (isFreeDine && freeDineConfig && freeDineConfig.enable) { if (isFreeDine && freeDineConfig && freeDineConfig.enable) {
finalPayAmount = BigNumber(finalPayAmount) finalPayAmount = BigNumber(finalPayAmount)
.times(freeDineConfig.rechargeTimes) .times(freeDineConfig.rechargeTimes)