feat(server): codes.GrantPaidSubscriptionTx 提炼订阅叠加语义供 pay 复用
CreateSubscription/applySubscription 加 source 参数(兑换路径传 "code" 零行为变化);新导出 GrantPaidSubscriptionTx(ctx, tx, ...) 供 pay 侧在 调用方事务内以 source='pay' 复用同一段叠加语义(同 plan 活跃订阅原地 延长,否则新建行),写 pay_grant 审计。 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013nMthbVEmQquxBRKb9Fj8u
This commit is contained in:
@@ -158,6 +158,7 @@ func (s *Store) CreateSubscription(
|
||||
userID, planID int64,
|
||||
durationDays int,
|
||||
latestSamePlan time.Time,
|
||||
source string,
|
||||
) (int64, error) {
|
||||
now := time.Now().UTC()
|
||||
base := now
|
||||
@@ -168,8 +169,8 @@ func (s *Store) CreateSubscription(
|
||||
|
||||
res, err := tx.ExecContext(ctx,
|
||||
`INSERT INTO subscriptions (user_id, plan_id, expires_at, source, created_at)
|
||||
VALUES (?, ?, ?, 'code', ?)`,
|
||||
userID, planID, expiresAt, now)
|
||||
VALUES (?, ?, ?, ?, ?)`,
|
||||
userID, planID, expiresAt, source, now)
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("store.CreateSubscription: %w", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user