优化代客下单逻辑
This commit is contained in:
@@ -69,7 +69,7 @@
|
||||
"vue-clipboard3": "^2.0.0",
|
||||
"vue-i18n": "^11.1.0",
|
||||
"vue-router": "^4.5.0",
|
||||
"ysk-utils": "^1.0.69"
|
||||
"ysk-utils": "^1.0.74"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@commitlint/cli": "^19.7.1",
|
||||
|
||||
@@ -280,7 +280,7 @@ export function calcFullReductionActivityFullAmount(
|
||||
let amount = 0;
|
||||
for (let goods of goodsList) {
|
||||
const availableNum = Math.max(0, goods.number - (goods.returnNum || 0));
|
||||
if (goods.is_temporary ||goods.isTemporary || goods.is_gift ||goods.isGift || availableNum <= 0) {
|
||||
if (goods.is_temporary || goods.isTemporary || goods.is_gift || goods.isGift || availableNum <= 0) {
|
||||
//临时菜,赠菜,数量<=0的商品不计算
|
||||
continue;
|
||||
}
|
||||
@@ -316,7 +316,7 @@ export function filterOptimalFullReductionActivity(
|
||||
// 第一步:基础筛选(未删除+当前店铺+活动进行中+就餐类型匹配)
|
||||
const baseEligible = activities.filter((activity) => {
|
||||
return (
|
||||
activity.isDel !== true && // 未删除
|
||||
// activity.isDel !== true && // 未删除
|
||||
// activity.shopId === currentShopId && // 当前店铺
|
||||
// activity.status === 2 && // 状态=2(进行中)
|
||||
isDinnerTypeMatch(activity, currentDinnerType) && // 就餐类型匹配
|
||||
@@ -389,7 +389,7 @@ export function truncateToTwoDecimals(num: number | string): number {
|
||||
* @returns 是否临时菜
|
||||
*/
|
||||
export function isTemporaryGoods(goods: BaseCartItem): boolean {
|
||||
return !!goods.is_temporary|| !!goods.isTemporary;
|
||||
return !!goods.is_temporary || !!goods.isTemporary;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -466,8 +466,8 @@ export function filterThresholdGoods(
|
||||
return applicableProductIds.length === 0
|
||||
? baseEligibleGoods
|
||||
: baseEligibleGoods.filter((goods) =>
|
||||
applicableProductIds.includes(String(goods.product_id))
|
||||
); // 核心修正:用商品ID匹配
|
||||
applicableProductIds.includes(String(goods.product_id))
|
||||
); // 核心修正:用商品ID匹配
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -574,7 +574,7 @@ export function calcSingleGoodsRealPrice(
|
||||
const { isMember, memberDiscountRate, limitTimeDiscount: activity } = config;
|
||||
|
||||
//如果是增菜价格为0
|
||||
if (goods.is_gift||goods.isGift) {
|
||||
if (goods.is_gift || goods.isGift) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -587,15 +587,15 @@ export function calcSingleGoodsRealPrice(
|
||||
const memberPrice = new BigNumber(
|
||||
calcMemberPrice(goods, isMember, memberDiscountRate)
|
||||
);
|
||||
if(goods.is_time_discount||goods.isTimeDiscount){
|
||||
if (goods.is_time_discount || goods.isTimeDiscount) {
|
||||
//限时折扣优先
|
||||
return truncateToTwoDecimals(
|
||||
new BigNumber(goods.salePrice)
|
||||
.times((activity?activity.discountRate:100) / 100)
|
||||
.decimalPlaces(2, BigNumber.ROUND_UP)
|
||||
.toNumber()
|
||||
);
|
||||
}
|
||||
return truncateToTwoDecimals(
|
||||
new BigNumber(goods.salePrice)
|
||||
.times((activity ? activity.discountRate : 100) / 100)
|
||||
.decimalPlaces(2, BigNumber.ROUND_UP)
|
||||
.toNumber()
|
||||
);
|
||||
}
|
||||
// 3. 优先级3:营销活动折扣(如限时折扣,需按商品ID匹配活动)
|
||||
let isActivityApplicable = false;
|
||||
if (activity) {
|
||||
@@ -612,14 +612,13 @@ export function calcSingleGoodsRealPrice(
|
||||
if (!activity || !isActivityApplicable) {
|
||||
return memberPrice.toNumber();
|
||||
}
|
||||
|
||||
|
||||
//限时折扣优先或者会员价优先但是不是会员或者未开启会员价格时限时折扣优先
|
||||
if (
|
||||
activity.discountPriority == "limit-time" ||
|
||||
(activity.discountPriority == "vip-price" && !isMember) ||
|
||||
(activity.discountPriority == "vip-price" && isMember && !goods.memberPrice)
|
||||
)
|
||||
{
|
||||
) {
|
||||
//限时折扣优先
|
||||
return truncateToTwoDecimals(
|
||||
new BigNumber(goods.salePrice)
|
||||
@@ -666,9 +665,9 @@ export function calcGoodsOriginalAmount(goodsList: BaseCartItem[]): number {
|
||||
for (const goods of goodsList) {
|
||||
const availableNum = Math.max(0, goods.number - (goods.returnNum || 0));
|
||||
let basePrice = new BigNumber(0);
|
||||
if (goods.is_temporary||goods.isTemporary) {
|
||||
if (goods.is_temporary || goods.isTemporary) {
|
||||
basePrice = new BigNumber(goods?.discountSaleAmount ?? 0);
|
||||
} else if (goods.is_gift||goods.isGift) {
|
||||
} else if (goods.is_gift || goods.isGift) {
|
||||
basePrice = new BigNumber(0);
|
||||
} else {
|
||||
basePrice = new BigNumber(goods.skuData?.salePrice ?? goods.salePrice); // SKU原价优先
|
||||
@@ -957,8 +956,8 @@ export function calcPointDeduction(
|
||||
)
|
||||
? maxDeductByPoints
|
||||
: new BigNumber(rule.maxDeductionAmount || Infinity).isLessThan(maxLimitBn)
|
||||
? maxDeductByPoints
|
||||
: maxLimitBn;
|
||||
? maxDeductByPoints
|
||||
: maxLimitBn;
|
||||
|
||||
// 实际使用积分 = 抵扣金额 * 积分兑换比例
|
||||
const usedPoints = maxDeductAmount.multipliedBy(pointsPerYuanBn);
|
||||
@@ -1065,9 +1064,9 @@ export function calculateOrderCostSummary(
|
||||
// 2.2 计算满减基数(先扣新客立减)
|
||||
let baseAfterNewUserDiscount = new BigNumber(
|
||||
limitTimeDiscount &&
|
||||
limitTimeDiscount.id &&
|
||||
usedFullReductionActivity &&
|
||||
!usedFullReductionActivity.discountShare
|
||||
limitTimeDiscount.id &&
|
||||
usedFullReductionActivity &&
|
||||
!usedFullReductionActivity.discountShare
|
||||
? goodsRealAmount
|
||||
: goodsRealAmount
|
||||
)
|
||||
@@ -1209,13 +1208,13 @@ export function calculateOrderCostSummary(
|
||||
.plus(packFee)
|
||||
.isGreaterThan(0)
|
||||
? new BigNumber(goodsRealAmount)
|
||||
.minus(newUserDiscount)
|
||||
.minus(fullReductionAmount)
|
||||
.minus(couponDeductionAmount)
|
||||
.minus(pointDeductionAmount)
|
||||
.plus(seatFee)
|
||||
.plus(packFee)
|
||||
.toNumber()
|
||||
.minus(newUserDiscount)
|
||||
.minus(fullReductionAmount)
|
||||
.minus(couponDeductionAmount)
|
||||
.minus(pointDeductionAmount)
|
||||
.plus(seatFee)
|
||||
.plus(packFee)
|
||||
.toNumber()
|
||||
: 0;
|
||||
|
||||
switch (merchantReductionConfig.type) {
|
||||
|
||||
@@ -129,6 +129,12 @@ export const useCartsStore = defineStore("carts", () => {
|
||||
return [...currentGoods, ...giftGoods, ...oldOrderGoods];
|
||||
};
|
||||
|
||||
// 台桌信息
|
||||
const tableInfo = ref({})
|
||||
async function changeTableInfo(info: any) {
|
||||
tableInfo.value = { ...info }
|
||||
}
|
||||
|
||||
// ------------------------------ 2. Store 内部原有响应式变量 ------------------------------
|
||||
// 选择用户
|
||||
const vipUser = ref<{ id?: string | number, isVip?: boolean }>({});
|
||||
@@ -988,6 +994,11 @@ export const useCartsStore = defineStore("carts", () => {
|
||||
userPoints.value = 0;
|
||||
}
|
||||
|
||||
// 支付成功后清楚订单/用户信息
|
||||
function clearHistory() {
|
||||
vipUser.value = {}
|
||||
}
|
||||
|
||||
return {
|
||||
disconnect,
|
||||
dinnerType,
|
||||
@@ -1047,7 +1058,10 @@ export const useCartsStore = defineStore("carts", () => {
|
||||
payParamsInit,
|
||||
limitDiscountRes,
|
||||
getAllGoodsList,
|
||||
vipUser
|
||||
vipUser,
|
||||
changeTableInfo,
|
||||
tableInfo,
|
||||
clearHistory
|
||||
};
|
||||
});
|
||||
|
||||
|
||||
@@ -125,6 +125,8 @@
|
||||
<div :class="{
|
||||
'free-price': useVipPrice && vipAllPrice != allPrice,
|
||||
}">
|
||||
<span class="onderline" v-if="cartStore.useVipPrice && item.memberPrice !== item.salePrice">¥{{
|
||||
to2(item.salePrice) }}</span>
|
||||
<span>¥{{ to2(allPrice) }}</span>
|
||||
</div>
|
||||
</div>
|
||||
@@ -547,4 +549,11 @@ onMounted(() => {
|
||||
-webkit-appearance: none;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.onderline {
|
||||
font-size: 12px;
|
||||
color: #999;
|
||||
text-decoration: line-through;
|
||||
margin-right: 4px;
|
||||
}
|
||||
</style>
|
||||
@@ -41,7 +41,7 @@
|
||||
</div>
|
||||
</div>
|
||||
<template #reference>
|
||||
<el-button>{{ table.name ? "桌台号:" + table.name : "选择桌号" }}</el-button>
|
||||
<el-button>{{ carts.tableInfo.name ? "桌台号:" + carts.tableInfo.name : "选择桌号" }}</el-button>
|
||||
</template>
|
||||
</el-popover>
|
||||
<el-button type="warning" @click="refQuanHexiaoOpen">扫码验券</el-button>
|
||||
@@ -84,7 +84,7 @@
|
||||
<!-- 购物车 -->
|
||||
<cartsList @editNote="showNote(true)" @createOrder="createOrder" @hideOrder="hideOrder"
|
||||
@clearOldOrder="clearOldOrder" :showOrder="showOrder" :goodsList="carts.goods" :dinerType="diners.sel"
|
||||
:perpole="perpole" :remark="remark" :table="table" ref="refCart"></cartsList>
|
||||
:perpole="perpole" :remark="remark" :table="carts.tableInfo" ref="refCart"></cartsList>
|
||||
</div>
|
||||
<div class="center">
|
||||
<!-- 购物车控制操作按钮 -->
|
||||
@@ -126,7 +126,7 @@
|
||||
</template>
|
||||
<!-- 订单信息展示 -->
|
||||
<Order ref="refOrder" :orderInfo="carts.oldOrder" @chooseUser="showChooseUser" @paysuccess="refresh"
|
||||
:table="table" :perpole="perpole" v-else :user="user"></Order>
|
||||
:table="carts.tableInfo" :perpole="perpole" v-else :user="user"></Order>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -428,7 +428,7 @@ async function clearOldOrder(params) {
|
||||
const res1 = params.placeNum
|
||||
? await orderApi.rmPlaceOrder(params)
|
||||
: await orderApi.cancelOrder(params);
|
||||
carts.clearHistory();
|
||||
// carts.clearHistory();
|
||||
ElMessage({
|
||||
type: res1 ? "success" : "error",
|
||||
message: res1 ? "删除成功" : "删除失败",
|
||||
@@ -510,6 +510,7 @@ async function tableClick(item) {
|
||||
carts.setOldOrder(res);
|
||||
}
|
||||
table.value = item;
|
||||
carts.changeTableInfo(item)
|
||||
carts.changeTable(item.tableCode);
|
||||
refTable.value.hide();
|
||||
}
|
||||
@@ -729,7 +730,7 @@ function init() {
|
||||
getTableList();
|
||||
getCategoryList();
|
||||
changeCartsDinerType();
|
||||
carts.init({ table_code: table.value.tableCode }, carts.oldOrder);
|
||||
carts.init({ table_code: carts.tableInfo.tableCode }, carts.oldOrder);
|
||||
}
|
||||
|
||||
onBeforeRouteLeave(() => {
|
||||
@@ -764,6 +765,7 @@ onMounted(async () => {
|
||||
}
|
||||
if (res.tableCode) {
|
||||
table.value = { tableCode: res.tableCode };
|
||||
carts.changeTableInfo(res)
|
||||
}
|
||||
if (res.userId) {
|
||||
const userRes = await shopUserApi.get({ userId: res.userId });
|
||||
@@ -775,6 +777,7 @@ onMounted(async () => {
|
||||
const tableRes = await tableApi.get({ tableCode: res.tableCode });
|
||||
if (tableRes.tableCode) {
|
||||
table.value = tableRes || {};
|
||||
carts.changeTableInfo(tableRes)
|
||||
}
|
||||
}
|
||||
if (res) {
|
||||
@@ -787,6 +790,7 @@ onMounted(async () => {
|
||||
const tableRes = await tableApi.get({ tableCode: tableCode });
|
||||
if (tableRes.tableCode) {
|
||||
table.value = tableRes || {};
|
||||
carts.changeTableInfo(tableRes)
|
||||
}
|
||||
}
|
||||
console.log(table.value);
|
||||
@@ -807,6 +811,7 @@ function refresh() {
|
||||
showOrder.value = false;
|
||||
user.value = {};
|
||||
table.value = {};
|
||||
carts.changeTableInfo({})
|
||||
router.replace(route.path);
|
||||
carts.dataReset();
|
||||
carts.init();
|
||||
|
||||
Reference in New Issue
Block a user