diff --git a/package.json b/package.json index 31888ad..2675b1a 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/lib/goods.ts b/src/lib/goods.ts index f120522..554104d 100644 --- a/src/lib/goods.ts +++ b/src/lib/goods.ts @@ -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) { diff --git a/src/store/modules/carts.ts b/src/store/modules/carts.ts index f25ceaa..bf8a0b3 100644 --- a/src/store/modules/carts.ts +++ b/src/store/modules/carts.ts @@ -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 }; }); diff --git a/src/views/tool/Instead/components/carts/item.vue b/src/views/tool/Instead/components/carts/item.vue index 268632c..019181b 100644 --- a/src/views/tool/Instead/components/carts/item.vue +++ b/src/views/tool/Instead/components/carts/item.vue @@ -125,6 +125,8 @@