fix(pre-planting): getEligibility 返回 canPurchase 字段修复"待开启"问题
后端 getEligibility() 原先只返回 hasPrePlanting/canTrade 等内部字段, 缺少前端购买页期望的 canPurchase/maxAdditional/message 字段。 由于 json['canPurchase'] ?? false 默认为 false,导致购买页始终显示"待开启"。 修复:getEligibility() 现在先查询 admin config 的 isActive 状态, 结合用户持仓计算出 canPurchase/maxAdditional/message,同时保留原有字段。 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
ef68b7b9c0
commit
2684a81383
|
|
@ -353,7 +353,11 @@ export class PrePlantingApplicationService {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取预种资格信息(供内部 API 使用)
|
* 获取预种资格信息(供内部 API + 移动端购买页使用)
|
||||||
|
*
|
||||||
|
* 返回字段同时满足两个消费者:
|
||||||
|
* - 内部 API: hasPrePlanting, canApplyAuthorization, canTrade
|
||||||
|
* - 移动端购买页: canPurchase, maxAdditional, message
|
||||||
*/
|
*/
|
||||||
async getEligibility(accountSequence: string): Promise<{
|
async getEligibility(accountSequence: string): Promise<{
|
||||||
hasPrePlanting: boolean;
|
hasPrePlanting: boolean;
|
||||||
|
|
@ -361,9 +365,40 @@ export class PrePlantingApplicationService {
|
||||||
totalTreesMerged: number;
|
totalTreesMerged: number;
|
||||||
canApplyAuthorization: boolean;
|
canApplyAuthorization: boolean;
|
||||||
canTrade: boolean;
|
canTrade: boolean;
|
||||||
|
canPurchase: boolean;
|
||||||
|
maxAdditional: number | null;
|
||||||
|
message: string | null;
|
||||||
}> {
|
}> {
|
||||||
|
const config = await this.adminClient.getPrePlantingConfig();
|
||||||
|
|
||||||
return this.prisma.$transaction(async (tx) => {
|
return this.prisma.$transaction(async (tx) => {
|
||||||
const position = await this.positionRepo.findByAccountSequence(tx, accountSequence);
|
const position = await this.positionRepo.findByAccountSequence(tx, accountSequence);
|
||||||
|
|
||||||
|
// 计算购买资格
|
||||||
|
let canPurchase = true;
|
||||||
|
let maxAdditional: number | null = null;
|
||||||
|
let message: string | null = null;
|
||||||
|
|
||||||
|
if (config.isActive) {
|
||||||
|
// 开关打开,任何人都可以购买
|
||||||
|
canPurchase = true;
|
||||||
|
} else if (!position || position.totalPortions === 0) {
|
||||||
|
// 开关关闭 + 无持仓 → 不可购买
|
||||||
|
canPurchase = false;
|
||||||
|
message = '预种功能待开启';
|
||||||
|
} else {
|
||||||
|
// 开关关闭 + 有持仓 → 看是否还能续购凑满
|
||||||
|
const additionalNeeded = position.maxAdditionalPortionsToMerge();
|
||||||
|
if (additionalNeeded === 0) {
|
||||||
|
canPurchase = false;
|
||||||
|
message = '预种功能已关闭,您当前份额已满,无法继续购买';
|
||||||
|
} else {
|
||||||
|
canPurchase = true;
|
||||||
|
maxAdditional = additionalNeeded;
|
||||||
|
message = `预种功能已暂停,您可继续购买 ${additionalNeeded} 份以凑满合并`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!position) {
|
if (!position) {
|
||||||
return {
|
return {
|
||||||
hasPrePlanting: false,
|
hasPrePlanting: false,
|
||||||
|
|
@ -371,6 +406,9 @@ export class PrePlantingApplicationService {
|
||||||
totalTreesMerged: 0,
|
totalTreesMerged: 0,
|
||||||
canApplyAuthorization: true,
|
canApplyAuthorization: true,
|
||||||
canTrade: true,
|
canTrade: true,
|
||||||
|
canPurchase,
|
||||||
|
maxAdditional,
|
||||||
|
message,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
|
|
@ -379,6 +417,9 @@ export class PrePlantingApplicationService {
|
||||||
totalTreesMerged: position.totalTreesMerged,
|
totalTreesMerged: position.totalTreesMerged,
|
||||||
canApplyAuthorization: position.totalTreesMerged >= 1,
|
canApplyAuthorization: position.totalTreesMerged >= 1,
|
||||||
canTrade: position.totalTreesMerged >= 1,
|
canTrade: position.totalTreesMerged >= 1,
|
||||||
|
canPurchase,
|
||||||
|
maxAdditional,
|
||||||
|
message,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue