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

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

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