feat(subscription): 支持套餐绑定分组,实现渠道/分组级别的订阅消耗限制#4246
feat(subscription): 支持套餐绑定分组,实现渠道/分组级别的订阅消耗限制#4246Mobaitt wants to merge 2 commits intoQuantumNous:mainfrom
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
WalkthroughAdds group-based restrictions to subscription plans: new Changes
Sequence DiagramsequenceDiagram
participant Admin as Admin/UI
participant Controller as Controller
participant Model as Model
participant DB as Database
participant Billing as BillingSession
participant Funding as FundingService
Note over Admin,DB: Create/Update Subscription Plan
Admin->>Controller: POST/PUT plan (allowed_groups:"g1,g2")
Controller->>Model: NormalizeSubscriptionAllowedGroups("g1,g2")
Model-->>Controller: "g1,g2"
Controller->>Controller: Validate groups exist via ratio_setting
Controller->>DB: Save plan with allowed_groups
DB-->>Controller: OK
Controller-->>Admin: Success
Note over Billing,Funding: Consumption with Group
Admin->>Billing: Request billing (relay.using_group / auto)
Billing->>Billing: resolveSubscriptionBillingGroup(...)
Billing->>Funding: Create SubscriptionFunding(usingGroup)
Funding->>Model: PreConsumeUserSubscription(..., usingGroup, ...)
Model->>DB: Query active subscriptions for user
DB-->>Model: [sub1, sub2]
Model->>Model: For each plan: subscriptionPlanAllowsGroup(plan, usingGroup)
alt Any plan allows group
Model-->>Funding: Approve pre-consume (quota reserved)
Funding-->>Billing: Success
else No plan allows group
Model-->>Funding: Error "no active subscription for group <group>"
Funding-->>Billing: Error
end
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
controller/subscription.go (1)
154-163: Consider consistent error message language.The error message
"allowed group does not exist"is in English, while other validation messages in this handler are in Chinese (e.g.,"套餐标题不能为空","升级分组不存在"). Consider using Chinese for consistency:- common.ApiErrorMsg(c, "allowed group does not exist") + common.ApiErrorMsg(c, "适用分组不存在")🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@controller/subscription.go` around lines 154 - 163, The validation currently returns an English message for missing allowed groups; change the error text to the existing Chinese phrasing used elsewhere to keep messages consistent. In the block that iterates req.Plan.AllowedGroups (using ratio_setting.GetGroupRatioCopy() and common.ApiErrorMsg), replace the "allowed group does not exist" message with the Chinese message used elsewhere (e.g., "升级分组不存在") so that the call common.ApiErrorMsg(c, ...) uses the Chinese string.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@controller/subscription.go`:
- Around line 154-163: The validation currently returns an English message for
missing allowed groups; change the error text to the existing Chinese phrasing
used elsewhere to keep messages consistent. In the block that iterates
req.Plan.AllowedGroups (using ratio_setting.GetGroupRatioCopy() and
common.ApiErrorMsg), replace the "allowed group does not exist" message with the
Chinese message used elsewhere (e.g., "升级分组不存在") so that the call
common.ApiErrorMsg(c, ...) uses the Chinese string.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 26363a76-3611-4d66-a33d-dead3476d59e
⛔ Files ignored due to path filters (1)
web/bun.lockis excluded by!**/*.lock
📒 Files selected for processing (8)
controller/subscription.gomodel/main.gomodel/subscription.goservice/billing_session.goservice/funding_source.goweb/src/components/table/subscriptions/SubscriptionsColumnDefs.jsxweb/src/components/table/subscriptions/modals/AddEditSubscriptionModal.jsxweb/src/components/topup/SubscriptionPlansCard.jsx
📝 变更描述 / Description
实现了套餐与分组的绑定功能,从而能够在渠道或分组级别上对订阅消耗进行限制。通过这种方式,可以更好地控制和管理不同分组或渠道的资源使用情况。
🚀 变更类型 / Type of change
🔗 关联任务 / Related Issue
✅ 提交前检查项 / Checklist
Bug fix,我已提交或关联对应 Issue,且不会将设计取舍、预期不一致或理解偏差直接归类为 bug。📸 运行证明 / Proof of Work
Summary by CodeRabbit