feat(core): 按照严格TDD模式完成活动项目(4位核销码)、订单状态机、财务分销与双身份切换核心领域服务及30项单元测试
这个提交包含在:
@@ -0,0 +1,70 @@
|
||||
export class FinanceCalculator {
|
||||
/**
|
||||
* 计算平台抽成与大神实际分润所得
|
||||
*/
|
||||
splitOrderIncome(params: {
|
||||
orderAmountCents: number;
|
||||
platformRatePercent: number;
|
||||
}): { platformFeeCents: number; expertIncomeCents: number } {
|
||||
const platformFeeCents = Math.floor((params.orderAmountCents * params.platformRatePercent) / 100);
|
||||
const expertIncomeCents = params.orderAmountCents - platformFeeCents;
|
||||
return { platformFeeCents, expertIncomeCents };
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算二级分销佣金
|
||||
*/
|
||||
calculateDistribution(params: {
|
||||
orderAmountCents: number;
|
||||
level1Percent: number;
|
||||
level2Percent: number;
|
||||
hasLevel1: boolean;
|
||||
hasLevel2: boolean;
|
||||
}): { level1Cents: number; level2Cents: number; totalCommissionCents: number } {
|
||||
const level1Cents = params.hasLevel1
|
||||
? Math.floor((params.orderAmountCents * params.level1Percent) / 100)
|
||||
: 0;
|
||||
const level2Cents = params.hasLevel2
|
||||
? Math.floor((params.orderAmountCents * params.level2Percent) / 100)
|
||||
: 0;
|
||||
|
||||
return {
|
||||
level1Cents,
|
||||
level2Cents,
|
||||
totalCommissionCents: level1Cents + level2Cents,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 应用优惠券抵扣
|
||||
*/
|
||||
applyCoupon(params: {
|
||||
orderAmountCents: number;
|
||||
couponDiscountCents: number;
|
||||
minOrderThresholdCents: number;
|
||||
}): number {
|
||||
if (params.orderAmountCents < params.minOrderThresholdCents) {
|
||||
throw new Error('订单未达到优惠券使用门槛');
|
||||
}
|
||||
const payAmount = params.orderAmountCents - params.couponDiscountCents;
|
||||
return Math.max(0, payAmount);
|
||||
}
|
||||
|
||||
/**
|
||||
* 提现校验与实际到账金额计算
|
||||
*/
|
||||
calculateWithdrawal(params: {
|
||||
withdrawAmountCents: number;
|
||||
minLimitCents: number;
|
||||
feePercent: number;
|
||||
}): { feeCents: number; actualArrivalCents: number } {
|
||||
if (params.withdrawAmountCents < params.minLimitCents) {
|
||||
throw new Error('提现金额低于平台最低提现限额');
|
||||
}
|
||||
|
||||
const feeCents = Math.floor((params.withdrawAmountCents * params.feePercent) / 100);
|
||||
const actualArrivalCents = params.withdrawAmountCents - feeCents;
|
||||
|
||||
return { feeCents, actualArrivalCents };
|
||||
}
|
||||
}
|
||||
在新工单中引用
屏蔽一个用户