优化代客下单逻辑

This commit is contained in:
gyq
2025-11-18 09:06:04 +08:00
parent 18d2a73073
commit 9904c044c3
5 changed files with 65 additions and 38 deletions

View File

@@ -69,7 +69,7 @@
"vue-clipboard3": "^2.0.0", "vue-clipboard3": "^2.0.0",
"vue-i18n": "^11.1.0", "vue-i18n": "^11.1.0",
"vue-router": "^4.5.0", "vue-router": "^4.5.0",
"ysk-utils": "^1.0.69" "ysk-utils": "^1.0.74"
}, },
"devDependencies": { "devDependencies": {
"@commitlint/cli": "^19.7.1", "@commitlint/cli": "^19.7.1",

View File

@@ -280,7 +280,7 @@ export function calcFullReductionActivityFullAmount(
let amount = 0; let amount = 0;
for (let goods of goodsList) { for (let goods of goodsList) {
const availableNum = Math.max(0, goods.number - (goods.returnNum || 0)); 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的商品不计算 //临时菜,赠菜,数量<=0的商品不计算
continue; continue;
} }
@@ -316,7 +316,7 @@ export function filterOptimalFullReductionActivity(
// 第一步:基础筛选(未删除+当前店铺+活动进行中+就餐类型匹配) // 第一步:基础筛选(未删除+当前店铺+活动进行中+就餐类型匹配)
const baseEligible = activities.filter((activity) => { const baseEligible = activities.filter((activity) => {
return ( return (
activity.isDel !== true && // 未删除 // activity.isDel !== true && // 未删除
// activity.shopId === currentShopId && // 当前店铺 // activity.shopId === currentShopId && // 当前店铺
// activity.status === 2 && // 状态=2进行中 // activity.status === 2 && // 状态=2进行中
isDinnerTypeMatch(activity, currentDinnerType) && // 就餐类型匹配 isDinnerTypeMatch(activity, currentDinnerType) && // 就餐类型匹配
@@ -389,7 +389,7 @@ export function truncateToTwoDecimals(num: number | string): number {
* @returns 是否临时菜 * @returns 是否临时菜
*/ */
export function isTemporaryGoods(goods: BaseCartItem): boolean { 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 return applicableProductIds.length === 0
? baseEligibleGoods ? baseEligibleGoods
: baseEligibleGoods.filter((goods) => : baseEligibleGoods.filter((goods) =>
applicableProductIds.includes(String(goods.product_id)) applicableProductIds.includes(String(goods.product_id))
); // 核心修正用商品ID匹配 ); // 核心修正用商品ID匹配
} }
/** /**
@@ -574,7 +574,7 @@ export function calcSingleGoodsRealPrice(
const { isMember, memberDiscountRate, limitTimeDiscount: activity } = config; const { isMember, memberDiscountRate, limitTimeDiscount: activity } = config;
//如果是增菜价格为0 //如果是增菜价格为0
if (goods.is_gift||goods.isGift) { if (goods.is_gift || goods.isGift) {
return 0; return 0;
} }
@@ -587,15 +587,15 @@ export function calcSingleGoodsRealPrice(
const memberPrice = new BigNumber( const memberPrice = new BigNumber(
calcMemberPrice(goods, isMember, memberDiscountRate) calcMemberPrice(goods, isMember, memberDiscountRate)
); );
if(goods.is_time_discount||goods.isTimeDiscount){ if (goods.is_time_discount || goods.isTimeDiscount) {
//限时折扣优先 //限时折扣优先
return truncateToTwoDecimals( return truncateToTwoDecimals(
new BigNumber(goods.salePrice) new BigNumber(goods.salePrice)
.times((activity?activity.discountRate:100) / 100) .times((activity ? activity.discountRate : 100) / 100)
.decimalPlaces(2, BigNumber.ROUND_UP) .decimalPlaces(2, BigNumber.ROUND_UP)
.toNumber() .toNumber()
); );
} }
// 3. 优先级3营销活动折扣如限时折扣需按商品ID匹配活动 // 3. 优先级3营销活动折扣如限时折扣需按商品ID匹配活动
let isActivityApplicable = false; let isActivityApplicable = false;
if (activity) { if (activity) {
@@ -612,14 +612,13 @@ export function calcSingleGoodsRealPrice(
if (!activity || !isActivityApplicable) { if (!activity || !isActivityApplicable) {
return memberPrice.toNumber(); return memberPrice.toNumber();
} }
//限时折扣优先或者会员价优先但是不是会员或者未开启会员价格时限时折扣优先 //限时折扣优先或者会员价优先但是不是会员或者未开启会员价格时限时折扣优先
if ( if (
activity.discountPriority == "limit-time" || activity.discountPriority == "limit-time" ||
(activity.discountPriority == "vip-price" && !isMember) || (activity.discountPriority == "vip-price" && !isMember) ||
(activity.discountPriority == "vip-price" && isMember && !goods.memberPrice) (activity.discountPriority == "vip-price" && isMember && !goods.memberPrice)
) ) {
{
//限时折扣优先 //限时折扣优先
return truncateToTwoDecimals( return truncateToTwoDecimals(
new BigNumber(goods.salePrice) new BigNumber(goods.salePrice)
@@ -666,9 +665,9 @@ export function calcGoodsOriginalAmount(goodsList: BaseCartItem[]): number {
for (const goods of goodsList) { for (const goods of goodsList) {
const availableNum = Math.max(0, goods.number - (goods.returnNum || 0)); const availableNum = Math.max(0, goods.number - (goods.returnNum || 0));
let basePrice = new BigNumber(0); let basePrice = new BigNumber(0);
if (goods.is_temporary||goods.isTemporary) { if (goods.is_temporary || goods.isTemporary) {
basePrice = new BigNumber(goods?.discountSaleAmount ?? 0); basePrice = new BigNumber(goods?.discountSaleAmount ?? 0);
} else if (goods.is_gift||goods.isGift) { } else if (goods.is_gift || goods.isGift) {
basePrice = new BigNumber(0); basePrice = new BigNumber(0);
} else { } else {
basePrice = new BigNumber(goods.skuData?.salePrice ?? goods.salePrice); // SKU原价优先 basePrice = new BigNumber(goods.skuData?.salePrice ?? goods.salePrice); // SKU原价优先
@@ -957,8 +956,8 @@ export function calcPointDeduction(
) )
? maxDeductByPoints ? maxDeductByPoints
: new BigNumber(rule.maxDeductionAmount || Infinity).isLessThan(maxLimitBn) : new BigNumber(rule.maxDeductionAmount || Infinity).isLessThan(maxLimitBn)
? maxDeductByPoints ? maxDeductByPoints
: maxLimitBn; : maxLimitBn;
// 实际使用积分 = 抵扣金额 * 积分兑换比例 // 实际使用积分 = 抵扣金额 * 积分兑换比例
const usedPoints = maxDeductAmount.multipliedBy(pointsPerYuanBn); const usedPoints = maxDeductAmount.multipliedBy(pointsPerYuanBn);
@@ -1065,9 +1064,9 @@ export function calculateOrderCostSummary(
// 2.2 计算满减基数(先扣新客立减) // 2.2 计算满减基数(先扣新客立减)
let baseAfterNewUserDiscount = new BigNumber( let baseAfterNewUserDiscount = new BigNumber(
limitTimeDiscount && limitTimeDiscount &&
limitTimeDiscount.id && limitTimeDiscount.id &&
usedFullReductionActivity && usedFullReductionActivity &&
!usedFullReductionActivity.discountShare !usedFullReductionActivity.discountShare
? goodsRealAmount ? goodsRealAmount
: goodsRealAmount : goodsRealAmount
) )
@@ -1209,13 +1208,13 @@ export function calculateOrderCostSummary(
.plus(packFee) .plus(packFee)
.isGreaterThan(0) .isGreaterThan(0)
? new BigNumber(goodsRealAmount) ? new BigNumber(goodsRealAmount)
.minus(newUserDiscount) .minus(newUserDiscount)
.minus(fullReductionAmount) .minus(fullReductionAmount)
.minus(couponDeductionAmount) .minus(couponDeductionAmount)
.minus(pointDeductionAmount) .minus(pointDeductionAmount)
.plus(seatFee) .plus(seatFee)
.plus(packFee) .plus(packFee)
.toNumber() .toNumber()
: 0; : 0;
switch (merchantReductionConfig.type) { switch (merchantReductionConfig.type) {

View File

@@ -129,6 +129,12 @@ export const useCartsStore = defineStore("carts", () => {
return [...currentGoods, ...giftGoods, ...oldOrderGoods]; return [...currentGoods, ...giftGoods, ...oldOrderGoods];
}; };
// 台桌信息
const tableInfo = ref({})
async function changeTableInfo(info: any) {
tableInfo.value = { ...info }
}
// ------------------------------ 2. Store 内部原有响应式变量 ------------------------------ // ------------------------------ 2. Store 内部原有响应式变量 ------------------------------
// 选择用户 // 选择用户
const vipUser = ref<{ id?: string | number, isVip?: boolean }>({}); const vipUser = ref<{ id?: string | number, isVip?: boolean }>({});
@@ -988,6 +994,11 @@ export const useCartsStore = defineStore("carts", () => {
userPoints.value = 0; userPoints.value = 0;
} }
// 支付成功后清楚订单/用户信息
function clearHistory() {
vipUser.value = {}
}
return { return {
disconnect, disconnect,
dinnerType, dinnerType,
@@ -1047,7 +1058,10 @@ export const useCartsStore = defineStore("carts", () => {
payParamsInit, payParamsInit,
limitDiscountRes, limitDiscountRes,
getAllGoodsList, getAllGoodsList,
vipUser vipUser,
changeTableInfo,
tableInfo,
clearHistory
}; };
}); });

View File

@@ -125,6 +125,8 @@
<div :class="{ <div :class="{
'free-price': useVipPrice && vipAllPrice != allPrice, 'free-price': useVipPrice && vipAllPrice != allPrice,
}"> }">
<span class="onderline" v-if="cartStore.useVipPrice && item.memberPrice !== item.salePrice">¥{{
to2(item.salePrice) }}</span>
<span>¥{{ to2(allPrice) }}</span> <span>¥{{ to2(allPrice) }}</span>
</div> </div>
</div> </div>
@@ -547,4 +549,11 @@ onMounted(() => {
-webkit-appearance: none; -webkit-appearance: none;
margin: 0; margin: 0;
} }
.onderline {
font-size: 12px;
color: #999;
text-decoration: line-through;
margin-right: 4px;
}
</style> </style>

View File

@@ -41,7 +41,7 @@
</div> </div>
</div> </div>
<template #reference> <template #reference>
<el-button>{{ table.name ? "桌台号:" + table.name : "选择桌号" }}</el-button> <el-button>{{ carts.tableInfo.name ? "桌台号:" + carts.tableInfo.name : "选择桌号" }}</el-button>
</template> </template>
</el-popover> </el-popover>
<el-button type="warning" @click="refQuanHexiaoOpen">扫码验券</el-button> <el-button type="warning" @click="refQuanHexiaoOpen">扫码验券</el-button>
@@ -84,7 +84,7 @@
<!-- 购物车 --> <!-- 购物车 -->
<cartsList @editNote="showNote(true)" @createOrder="createOrder" @hideOrder="hideOrder" <cartsList @editNote="showNote(true)" @createOrder="createOrder" @hideOrder="hideOrder"
@clearOldOrder="clearOldOrder" :showOrder="showOrder" :goodsList="carts.goods" :dinerType="diners.sel" @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>
<div class="center"> <div class="center">
<!-- 购物车控制操作按钮 --> <!-- 购物车控制操作按钮 -->
@@ -126,7 +126,7 @@
</template> </template>
<!-- 订单信息展示 --> <!-- 订单信息展示 -->
<Order ref="refOrder" :orderInfo="carts.oldOrder" @chooseUser="showChooseUser" @paysuccess="refresh" <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> </div>
</div> </div>
@@ -428,7 +428,7 @@ async function clearOldOrder(params) {
const res1 = params.placeNum const res1 = params.placeNum
? await orderApi.rmPlaceOrder(params) ? await orderApi.rmPlaceOrder(params)
: await orderApi.cancelOrder(params); : await orderApi.cancelOrder(params);
carts.clearHistory(); // carts.clearHistory();
ElMessage({ ElMessage({
type: res1 ? "success" : "error", type: res1 ? "success" : "error",
message: res1 ? "删除成功" : "删除失败", message: res1 ? "删除成功" : "删除失败",
@@ -510,6 +510,7 @@ async function tableClick(item) {
carts.setOldOrder(res); carts.setOldOrder(res);
} }
table.value = item; table.value = item;
carts.changeTableInfo(item)
carts.changeTable(item.tableCode); carts.changeTable(item.tableCode);
refTable.value.hide(); refTable.value.hide();
} }
@@ -729,7 +730,7 @@ function init() {
getTableList(); getTableList();
getCategoryList(); getCategoryList();
changeCartsDinerType(); changeCartsDinerType();
carts.init({ table_code: table.value.tableCode }, carts.oldOrder); carts.init({ table_code: carts.tableInfo.tableCode }, carts.oldOrder);
} }
onBeforeRouteLeave(() => { onBeforeRouteLeave(() => {
@@ -764,6 +765,7 @@ onMounted(async () => {
} }
if (res.tableCode) { if (res.tableCode) {
table.value = { tableCode: res.tableCode }; table.value = { tableCode: res.tableCode };
carts.changeTableInfo(res)
} }
if (res.userId) { if (res.userId) {
const userRes = await shopUserApi.get({ userId: res.userId }); const userRes = await shopUserApi.get({ userId: res.userId });
@@ -775,6 +777,7 @@ onMounted(async () => {
const tableRes = await tableApi.get({ tableCode: res.tableCode }); const tableRes = await tableApi.get({ tableCode: res.tableCode });
if (tableRes.tableCode) { if (tableRes.tableCode) {
table.value = tableRes || {}; table.value = tableRes || {};
carts.changeTableInfo(tableRes)
} }
} }
if (res) { if (res) {
@@ -787,6 +790,7 @@ onMounted(async () => {
const tableRes = await tableApi.get({ tableCode: tableCode }); const tableRes = await tableApi.get({ tableCode: tableCode });
if (tableRes.tableCode) { if (tableRes.tableCode) {
table.value = tableRes || {}; table.value = tableRes || {};
carts.changeTableInfo(tableRes)
} }
} }
console.log(table.value); console.log(table.value);
@@ -807,6 +811,7 @@ function refresh() {
showOrder.value = false; showOrder.value = false;
user.value = {}; user.value = {};
table.value = {}; table.value = {};
carts.changeTableInfo({})
router.replace(route.path); router.replace(route.path);
carts.dataReset(); carts.dataReset();
carts.init(); carts.init();