增加分销页面,订单增加会员折扣
This commit is contained in:
@@ -268,6 +268,12 @@ export interface TimeLimitDiscountConfig {
|
||||
[property: string]: any;
|
||||
}
|
||||
|
||||
//用户信息
|
||||
interface ShopUserInfo {
|
||||
isVip: number | null; //是否会员
|
||||
discount: number | null; //用户折扣
|
||||
isMemberPrice: number | null; //会员折扣与会员价是否同时使用
|
||||
}
|
||||
/** 订单额外费用配置 */
|
||||
export interface OrderExtraConfig {
|
||||
// merchantReduction: number; // 商家减免金额(元,默认0)
|
||||
@@ -286,6 +292,7 @@ export interface OrderExtraConfig {
|
||||
isFreeDine?: boolean; //是否霸王餐
|
||||
freeDineConfig?: FreeDineConfig;
|
||||
limitTimeDiscount?: TimeLimitDiscountConfig; //限时折扣
|
||||
shopUserInfo: ShopUserInfo; // 用户信息
|
||||
}
|
||||
|
||||
/** 订单费用汇总(修改:补充商家减免类型和明细) */
|
||||
@@ -1283,6 +1290,22 @@ export function calcPointDeduction(
|
||||
};
|
||||
}
|
||||
|
||||
function calcVipDiscountAmount(
|
||||
goodsRealAmount: number,
|
||||
shopUserInfo: ShopUserInfo
|
||||
): number {
|
||||
if (!shopUserInfo.isVip || shopUserInfo.discount === 0) return 0;
|
||||
if (shopUserInfo.isVip == 1 && shopUserInfo.isMemberPrice != 1) {
|
||||
return 0;
|
||||
}
|
||||
return truncateToTwoDecimals(
|
||||
new BigNumber(goodsRealAmount)
|
||||
.multipliedBy((100 - (shopUserInfo.discount || 0)) / 100)
|
||||
.decimalPlaces(2, BigNumber.ROUND_UP)
|
||||
.toNumber()
|
||||
);
|
||||
}
|
||||
|
||||
// ============================ 6. 订单总费用汇总与实付金额计算(核心入口,补充细分字段) ============================
|
||||
/**
|
||||
* 计算订单所有费用子项并汇总(核心入口函数)
|
||||
@@ -1310,7 +1333,9 @@ export function calculateOrderCostSummary(
|
||||
freeDineConfig,
|
||||
limitTimeDiscount,
|
||||
fullReductionActivities,
|
||||
shopUserInfo,
|
||||
} = config;
|
||||
console.log("shopUserInfo", shopUserInfo);
|
||||
|
||||
// ------------------------------ 1. 基础费用计算 ------------------------------
|
||||
const goodsOriginalAmount = calcGoodsOriginalAmount(goodsList); // 商品原价总和
|
||||
@@ -1323,13 +1348,19 @@ export function calculateOrderCostSummary(
|
||||
limitTimeDiscount: config.limitTimeDiscount,
|
||||
}
|
||||
);
|
||||
|
||||
// 会员折扣减免
|
||||
const vipDiscountAmount = calcVipDiscountAmount(
|
||||
goodsRealAmount,
|
||||
shopUserInfo
|
||||
); // 会员折扣减免金额
|
||||
|
||||
const goodsDiscountAmount = calcGoodsDiscountAmount(
|
||||
goodsOriginalAmount,
|
||||
goodsRealAmount
|
||||
); // 商品折扣金额
|
||||
|
||||
//会员折扣
|
||||
let vipDiscountAmount = 0;
|
||||
|
||||
|
||||
const newUserDiscount = config.newUserDiscount || 0; // 新客立减
|
||||
|
||||
@@ -1522,6 +1553,7 @@ export function calculateOrderCostSummary(
|
||||
// ------------------------------ 6. 最终实付金额计算 ------------------------------
|
||||
const finalPayAmountBn = new BigNumber(goodsRealAmount)
|
||||
.minus(newUserDiscount)
|
||||
.minus(vipDiscountAmount)
|
||||
.minus(fullReductionAmount)
|
||||
.minus(couponDeductionAmount)
|
||||
.minus(pointDeductionAmount)
|
||||
@@ -1549,6 +1581,7 @@ export function calculateOrderCostSummary(
|
||||
.plus(couponDeductionAmount)
|
||||
.plus(pointDeductionAmount)
|
||||
.plus(merchantReductionActualAmount)
|
||||
.plus(vipDiscountAmount)
|
||||
.toNumber()
|
||||
);
|
||||
//积分可抵扣最大金额 最终支付金额+积分抵扣-商家减免
|
||||
|
||||
Reference in New Issue
Block a user