Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions backend/cmd/server/wire.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ func provideCleanup(
backupSvc *service.BackupService,
paymentOrderExpiry *service.PaymentOrderExpiryService,
channelMonitorRunner *service.ChannelMonitorRunner,
billingStatementEmail *service.BillingStatementEmailService,
) func() {
return func() {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
Expand Down Expand Up @@ -246,6 +247,12 @@ func provideCleanup(
}
return nil
}},
{"BillingStatementEmailService", func() error {
if billingStatementEmail != nil {
billingStatementEmail.Stop()
}
return nil
}},
}

infraSteps := []cleanupStep{
Expand Down
10 changes: 9 additions & 1 deletion backend/cmd/server/wire_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions backend/cmd/server/wire_gen_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ func TestProvideCleanup_WithMinimalDependencies_NoPanic(t *testing.T) {
nil, // backupSvc
nil, // paymentOrderExpiry
nil, // channelMonitorRunner
nil, // billingStatementEmail
)

require.NotPanics(t, func() {
Expand Down
17 changes: 14 additions & 3 deletions backend/internal/handler/admin/setting_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,8 @@ func (h *SettingHandler) GetSettings(c *gin.Context) {
AvailableChannelsEnabled: settings.AvailableChannelsEnabled,

AffiliateEnabled: settings.AffiliateEnabled,

BillingStatementEmailConfig: settings.BillingStatementEmailConfig,
}

// OpenAI fast policy (stored under a dedicated setting key)
Expand Down Expand Up @@ -569,6 +571,9 @@ type UpdateSettingsRequest struct {
// 风控中心功能开关
RiskControlEnabled *bool `json:"risk_control_enabled"`

// Billing statement email config (JSON string, only updated when non-empty)
BillingStatementEmailConfig *string `json:"billing_statement_email_config,omitempty"`

// OpenAI fast/flex policy (optional, only updated when provided)
OpenAIFastPolicySettings *dto.OpenAIFastPolicySettings `json:"openai_fast_policy_settings,omitempty"`
}
Expand Down Expand Up @@ -1505,6 +1510,12 @@ func (h *SettingHandler) UpdateSettings(c *gin.Context) {
}
return previousSettings.RiskControlEnabled
}(),
BillingStatementEmailConfig: func() string {
if req.BillingStatementEmailConfig != nil {
return *req.BillingStatementEmailConfig
}
return previousSettings.BillingStatementEmailConfig
}(),
}

authSourceDefaults := &service.AuthSourceDefaultSettings{
Expand Down Expand Up @@ -1783,9 +1794,9 @@ func (h *SettingHandler) UpdateSettings(c *gin.Context) {

AvailableChannelsEnabled: updatedSettings.AvailableChannelsEnabled,

AffiliateEnabled: updatedSettings.AffiliateEnabled,

RiskControlEnabled: updatedSettings.RiskControlEnabled,
AffiliateEnabled: updatedSettings.AffiliateEnabled,
RiskControlEnabled: updatedSettings.RiskControlEnabled,
BillingStatementEmailConfig: updatedSettings.BillingStatementEmailConfig,
}
if fastPolicy, err := h.settingService.GetOpenAIFastPolicySettings(c.Request.Context()); err != nil {
slog.Error("openai_fast_policy_settings_get_failed", "error", err)
Expand Down
38 changes: 21 additions & 17 deletions backend/internal/handler/dto/mappers.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,27 @@ func UserFromServiceShallow(u *service.User) *User {
return nil
}
return &User{
ID: u.ID,
Email: u.Email,
Username: u.Username,
Role: u.Role,
Balance: u.Balance,
Concurrency: u.Concurrency,
Status: u.Status,
AllowedGroups: u.AllowedGroups,
LastActiveAt: u.LastActiveAt,
CreatedAt: u.CreatedAt,
UpdatedAt: u.UpdatedAt,
BalanceNotifyEnabled: u.BalanceNotifyEnabled,
BalanceNotifyThresholdType: u.BalanceNotifyThresholdType,
BalanceNotifyThreshold: u.BalanceNotifyThreshold,
BalanceNotifyExtraEmails: NotifyEmailEntriesFromService(u.BalanceNotifyExtraEmails),
TotalRecharged: u.TotalRecharged,
RPMLimit: u.RPMLimit,
ID: u.ID,
Email: u.Email,
Username: u.Username,
Role: u.Role,
Balance: u.Balance,
Concurrency: u.Concurrency,
Status: u.Status,
AllowedGroups: u.AllowedGroups,
LastActiveAt: u.LastActiveAt,
CreatedAt: u.CreatedAt,
UpdatedAt: u.UpdatedAt,
BalanceNotifyEnabled: u.BalanceNotifyEnabled,
BalanceNotifyThresholdType: u.BalanceNotifyThresholdType,
BalanceNotifyThreshold: u.BalanceNotifyThreshold,
BalanceNotifyExtraEmails: NotifyEmailEntriesFromService(u.BalanceNotifyExtraEmails),
TotalRecharged: u.TotalRecharged,
RPMLimit: u.RPMLimit,
BillingStatementDailyEnabled: u.BillingStatementDailyEnabled,
BillingStatementWeeklyEnabled: u.BillingStatementWeeklyEnabled,
BillingStatementMonthlyEnabled: u.BillingStatementMonthlyEnabled,
Timezone: u.Timezone,
}
}

Expand Down
10 changes: 9 additions & 1 deletion backend/internal/handler/dto/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,9 @@ type SystemSettings struct {
// Affiliate (邀请返利) feature switch
AffiliateEnabled bool `json:"affiliate_enabled"`

// Billing statement email config (JSON string)
BillingStatementEmailConfig string `json:"billing_statement_email_config"`

// OpenAI fast/flex policy
OpenAIFastPolicySettings *OpenAIFastPolicySettings `json:"openai_fast_policy_settings,omitempty"`
}
Expand Down Expand Up @@ -283,7 +286,12 @@ type PublicSettings struct {

AffiliateEnabled bool `json:"affiliate_enabled"`

RiskControlEnabled bool `json:"risk_control_enabled"`
RiskControlEnabled bool `json:"risk_control_enabled"`
BillingStatementEmailEnabled bool `json:"billing_statement_email_enabled"`
BillingStatementDailyEnabled bool `json:"billing_statement_daily_enabled"`
BillingStatementWeeklyEnabled bool `json:"billing_statement_weekly_enabled"`
BillingStatementMonthlyEnabled bool `json:"billing_statement_monthly_enabled"`
ServerTimezone string `json:"server_timezone"`
}

type LoginAgreementDocument struct {
Expand Down
8 changes: 7 additions & 1 deletion backend/internal/handler/dto/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,13 @@ type User struct {
TotalRecharged float64 `json:"total_recharged"`

// RPMLimit 用户级每分钟请求数上限(0 = 不限制),仅在所用分组未设置 rpm_limit 时作为兜底生效。
RPMLimit int `json:"rpm_limit"`
RPMLimit int `json:"rpm_limit"`
Timezone string `json:"timezone"`

// 账单邮件偏好
BillingStatementDailyEnabled bool `json:"billing_statement_daily_enabled"`
BillingStatementWeeklyEnabled bool `json:"billing_statement_weekly_enabled"`
BillingStatementMonthlyEnabled bool `json:"billing_statement_monthly_enabled"`

APIKeys []APIKey `json:"api_keys,omitempty"`
Subscriptions []UserSubscription `json:"subscriptions,omitempty"`
Expand Down
7 changes: 6 additions & 1 deletion backend/internal/handler/setting_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,12 @@ func (h *SettingHandler) GetPublicSettings(c *gin.Context) {

AffiliateEnabled: settings.AffiliateEnabled,

RiskControlEnabled: settings.RiskControlEnabled,
RiskControlEnabled: settings.RiskControlEnabled,
BillingStatementEmailEnabled: settings.BillingStatementEmailEnabled,
BillingStatementDailyEnabled: settings.BillingStatementDailyEnabled,
BillingStatementWeeklyEnabled: settings.BillingStatementWeeklyEnabled,
BillingStatementMonthlyEnabled: settings.BillingStatementMonthlyEnabled,
ServerTimezone: settings.ServerTimezone,
})
}

Expand Down
18 changes: 14 additions & 4 deletions backend/internal/handler/user_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ type UpdateProfileRequest struct {
AvatarURL *string `json:"avatar_url"`
BalanceNotifyEnabled *bool `json:"balance_notify_enabled"`
BalanceNotifyThreshold *float64 `json:"balance_notify_threshold"`

// Billing statement email preferences
BillingStatementDailyEnabled *bool `json:"billing_statement_daily_enabled"`
BillingStatementWeeklyEnabled *bool `json:"billing_statement_weekly_enabled"`
BillingStatementMonthlyEnabled *bool `json:"billing_statement_monthly_enabled"`
Timezone *string `json:"timezone"`
}

type userProfileResponse struct {
Expand Down Expand Up @@ -142,10 +148,14 @@ func (h *UserHandler) UpdateProfile(c *gin.Context) {
}

svcReq := service.UpdateProfileRequest{
Username: req.Username,
AvatarURL: req.AvatarURL,
BalanceNotifyEnabled: req.BalanceNotifyEnabled,
BalanceNotifyThreshold: req.BalanceNotifyThreshold,
Username: req.Username,
AvatarURL: req.AvatarURL,
BalanceNotifyEnabled: req.BalanceNotifyEnabled,
BalanceNotifyThreshold: req.BalanceNotifyThreshold,
BillingStatementDailyEnabled: req.BillingStatementDailyEnabled,
BillingStatementWeeklyEnabled: req.BillingStatementWeeklyEnabled,
BillingStatementMonthlyEnabled: req.BillingStatementMonthlyEnabled,
Timezone: req.Timezone,
}
updatedUser, err := h.userService.UpdateProfile(c.Request.Context(), subject.UserID, svcReq)
if err != nil {
Expand Down
6 changes: 6 additions & 0 deletions backend/internal/server/api_contract_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ func TestAPIContracts(t *testing.T) {
"balance_notify_threshold": null,
"balance_notify_extra_emails": null,
"total_recharged": 0,
"timezone": "UTC",
"billing_statement_daily_enabled": false,
"billing_statement_weekly_enabled": false,
"billing_statement_monthly_enabled": false,
"linuxdo_bound": false,
"oidc_bound": false,
"wechat_bound": false,
Expand Down Expand Up @@ -818,6 +822,7 @@ func TestAPIContracts(t *testing.T) {
"balance_low_notify_threshold": 0,
"balance_low_notify_recharge_url": "",
"account_quota_notify_emails": [],
"billing_statement_email_config": "",
"channel_monitor_enabled": true,
"channel_monitor_default_interval_seconds": 60,
"available_channels_enabled": false,
Expand Down Expand Up @@ -1029,6 +1034,7 @@ func TestAPIContracts(t *testing.T) {
"balance_low_notify_threshold": 0,
"balance_low_notify_recharge_url": "",
"account_quota_notify_emails": [],
"billing_statement_email_config": "",
"channel_monitor_enabled": true,
"channel_monitor_default_interval_seconds": 60,
"available_channels_enabled": false,
Expand Down
Loading
Loading