feat: 套餐分组清理 + 续费延期 + UI统一
- Schema: groupId 改为 nullable,新增迁移 - GET 套餐列表自动检测并清除 Sub2API 中已删除的分组绑定 - PUT 保存时校验分组存在性,已删除则自动解绑并返回 409 - 续费逻辑:同分组有活跃订阅时从到期日计算天数再 createAndRedeem - 提取 PlanInfoDisplay 共享组件,SubscriptionConfirm 复用 - 默认模型统一到 /v1/messages badge 内 - 前端编辑表单适配 nullable groupId,未绑定时禁用保存
This commit is contained in:
@@ -17,16 +17,30 @@ export async function GET(request: NextRequest) {
|
||||
let groupExists = false;
|
||||
let groupName: string | null = null;
|
||||
let group: Awaited<ReturnType<typeof getGroup>> | null = null;
|
||||
try {
|
||||
group = await getGroup(plan.groupId);
|
||||
groupExists = group !== null;
|
||||
groupName = group?.name ?? null;
|
||||
} catch {
|
||||
groupExists = false;
|
||||
|
||||
if (plan.groupId !== null) {
|
||||
try {
|
||||
group = await getGroup(plan.groupId);
|
||||
groupExists = group !== null;
|
||||
groupName = group?.name ?? null;
|
||||
} catch {
|
||||
groupExists = false;
|
||||
}
|
||||
|
||||
// 分组已失效:自动清除绑定并下架
|
||||
if (!groupExists) {
|
||||
prisma.subscriptionPlan
|
||||
.update({
|
||||
where: { id: plan.id },
|
||||
data: { groupId: null, forSale: false },
|
||||
})
|
||||
.catch((err) => console.error(`Failed to unbind stale group for plan ${plan.id}:`, err));
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
id: plan.id,
|
||||
groupId: String(plan.groupId),
|
||||
groupId: groupExists ? String(plan.groupId) : null,
|
||||
groupName,
|
||||
name: plan.name,
|
||||
description: plan.description,
|
||||
@@ -36,7 +50,7 @@ export async function GET(request: NextRequest) {
|
||||
validityUnit: plan.validityUnit,
|
||||
features: plan.features ? JSON.parse(plan.features) : [],
|
||||
sortOrder: plan.sortOrder,
|
||||
enabled: plan.forSale,
|
||||
enabled: groupExists ? plan.forSale : false,
|
||||
groupExists,
|
||||
groupPlatform: group?.platform ?? null,
|
||||
groupRateMultiplier: group?.rate_multiplier ?? null,
|
||||
|
||||
Reference in New Issue
Block a user