fix: gofmt formatting across all Go source files
This commit is contained in:
@@ -1533,39 +1533,48 @@ func (a *Account) QuotaNotifyConfig(dim string) (enabled bool, threshold float64
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (a *Account) GetQuotaNotifyDailyEnabled() bool {
|
func (a *Account) GetQuotaNotifyDailyEnabled() bool {
|
||||||
e, _, _ := a.QuotaNotifyConfig(quotaDimDaily); return e
|
e, _, _ := a.QuotaNotifyConfig(quotaDimDaily)
|
||||||
|
return e
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *Account) GetQuotaNotifyDailyThreshold() float64 {
|
func (a *Account) GetQuotaNotifyDailyThreshold() float64 {
|
||||||
_, t, _ := a.QuotaNotifyConfig(quotaDimDaily); return t
|
_, t, _ := a.QuotaNotifyConfig(quotaDimDaily)
|
||||||
|
return t
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *Account) GetQuotaNotifyDailyThresholdType() string {
|
func (a *Account) GetQuotaNotifyDailyThresholdType() string {
|
||||||
_, _, tt := a.QuotaNotifyConfig(quotaDimDaily); return tt
|
_, _, tt := a.QuotaNotifyConfig(quotaDimDaily)
|
||||||
|
return tt
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *Account) GetQuotaNotifyWeeklyEnabled() bool {
|
func (a *Account) GetQuotaNotifyWeeklyEnabled() bool {
|
||||||
e, _, _ := a.QuotaNotifyConfig(quotaDimWeekly); return e
|
e, _, _ := a.QuotaNotifyConfig(quotaDimWeekly)
|
||||||
|
return e
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *Account) GetQuotaNotifyWeeklyThreshold() float64 {
|
func (a *Account) GetQuotaNotifyWeeklyThreshold() float64 {
|
||||||
_, t, _ := a.QuotaNotifyConfig(quotaDimWeekly); return t
|
_, t, _ := a.QuotaNotifyConfig(quotaDimWeekly)
|
||||||
|
return t
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *Account) GetQuotaNotifyWeeklyThresholdType() string {
|
func (a *Account) GetQuotaNotifyWeeklyThresholdType() string {
|
||||||
_, _, tt := a.QuotaNotifyConfig(quotaDimWeekly); return tt
|
_, _, tt := a.QuotaNotifyConfig(quotaDimWeekly)
|
||||||
|
return tt
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *Account) GetQuotaNotifyTotalEnabled() bool {
|
func (a *Account) GetQuotaNotifyTotalEnabled() bool {
|
||||||
e, _, _ := a.QuotaNotifyConfig(quotaDimTotal); return e
|
e, _, _ := a.QuotaNotifyConfig(quotaDimTotal)
|
||||||
|
return e
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *Account) GetQuotaNotifyTotalThreshold() float64 {
|
func (a *Account) GetQuotaNotifyTotalThreshold() float64 {
|
||||||
_, t, _ := a.QuotaNotifyConfig(quotaDimTotal); return t
|
_, t, _ := a.QuotaNotifyConfig(quotaDimTotal)
|
||||||
|
return t
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *Account) GetQuotaNotifyTotalThresholdType() string {
|
func (a *Account) GetQuotaNotifyTotalThresholdType() string {
|
||||||
_, _, tt := a.QuotaNotifyConfig(quotaDimTotal); return tt
|
_, _, tt := a.QuotaNotifyConfig(quotaDimTotal)
|
||||||
|
return tt
|
||||||
}
|
}
|
||||||
|
|
||||||
// nextFixedDailyReset 计算在 after 之后的下一个每日固定重置时间点
|
// nextFixedDailyReset 计算在 after 之后的下一个每日固定重置时间点
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ type ProviderInstanceResponse struct {
|
|||||||
Limits string `json:"limits"`
|
Limits string `json:"limits"`
|
||||||
Enabled bool `json:"enabled"`
|
Enabled bool `json:"enabled"`
|
||||||
RefundEnabled bool `json:"refund_enabled"`
|
RefundEnabled bool `json:"refund_enabled"`
|
||||||
|
AllowUserRefund bool `json:"allow_user_refund"`
|
||||||
SortOrder int `json:"sort_order"`
|
SortOrder int `json:"sort_order"`
|
||||||
PaymentMode string `json:"payment_mode"`
|
PaymentMode string `json:"payment_mode"`
|
||||||
}
|
}
|
||||||
@@ -46,8 +47,8 @@ func (s *PaymentConfigService) ListProviderInstancesWithConfig(ctx context.Conte
|
|||||||
resp := ProviderInstanceResponse{
|
resp := ProviderInstanceResponse{
|
||||||
ID: int64(inst.ID), ProviderKey: inst.ProviderKey, Name: inst.Name,
|
ID: int64(inst.ID), ProviderKey: inst.ProviderKey, Name: inst.Name,
|
||||||
SupportedTypes: splitTypes(inst.SupportedTypes), Limits: inst.Limits,
|
SupportedTypes: splitTypes(inst.SupportedTypes), Limits: inst.Limits,
|
||||||
Enabled: inst.Enabled, RefundEnabled: inst.RefundEnabled, SortOrder: inst.SortOrder,
|
Enabled: inst.Enabled, RefundEnabled: inst.RefundEnabled, AllowUserRefund: inst.AllowUserRefund,
|
||||||
PaymentMode: inst.PaymentMode,
|
SortOrder: inst.SortOrder, PaymentMode: inst.PaymentMode,
|
||||||
}
|
}
|
||||||
resp.Config, err = s.decryptAndMaskConfig(inst.Config)
|
resp.Config, err = s.decryptAndMaskConfig(inst.Config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -110,10 +111,12 @@ func (s *PaymentConfigService) CreateProviderInstance(ctx context.Context, req C
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
allowUserRefund := req.AllowUserRefund && req.RefundEnabled
|
||||||
return s.entClient.PaymentProviderInstance.Create().
|
return s.entClient.PaymentProviderInstance.Create().
|
||||||
SetProviderKey(req.ProviderKey).SetName(req.Name).SetConfig(enc).
|
SetProviderKey(req.ProviderKey).SetName(req.Name).SetConfig(enc).
|
||||||
SetSupportedTypes(typesStr).SetEnabled(req.Enabled).SetPaymentMode(req.PaymentMode).
|
SetSupportedTypes(typesStr).SetEnabled(req.Enabled).SetPaymentMode(req.PaymentMode).
|
||||||
SetSortOrder(req.SortOrder).SetLimits(req.Limits).SetRefundEnabled(req.RefundEnabled).
|
SetSortOrder(req.SortOrder).SetLimits(req.Limits).SetRefundEnabled(req.RefundEnabled).
|
||||||
|
SetAllowUserRefund(allowUserRefund).
|
||||||
Save(ctx)
|
Save(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -221,6 +224,21 @@ func (s *PaymentConfigService) UpdateProviderInstance(ctx context.Context, id in
|
|||||||
}
|
}
|
||||||
if req.RefundEnabled != nil {
|
if req.RefundEnabled != nil {
|
||||||
u.SetRefundEnabled(*req.RefundEnabled)
|
u.SetRefundEnabled(*req.RefundEnabled)
|
||||||
|
// Cascade: turning off refund_enabled also disables allow_user_refund
|
||||||
|
if !*req.RefundEnabled {
|
||||||
|
u.SetAllowUserRefund(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if req.AllowUserRefund != nil {
|
||||||
|
// Only allow enabling when refund_enabled is true
|
||||||
|
if *req.AllowUserRefund {
|
||||||
|
inst, err := s.entClient.PaymentProviderInstance.Get(ctx, id)
|
||||||
|
if err == nil && inst.RefundEnabled {
|
||||||
|
u.SetAllowUserRefund(true)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
u.SetAllowUserRefund(false)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if req.PaymentMode != nil {
|
if req.PaymentMode != nil {
|
||||||
u.SetPaymentMode(*req.PaymentMode)
|
u.SetPaymentMode(*req.PaymentMode)
|
||||||
@@ -228,6 +246,23 @@ func (s *PaymentConfigService) UpdateProviderInstance(ctx context.Context, id in
|
|||||||
return u.Save(ctx)
|
return u.Save(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetUserRefundEligibleInstanceIDs returns provider instance IDs that allow user refund.
|
||||||
|
func (s *PaymentConfigService) GetUserRefundEligibleInstanceIDs(ctx context.Context) ([]string, error) {
|
||||||
|
instances, err := s.entClient.PaymentProviderInstance.Query().
|
||||||
|
Where(
|
||||||
|
paymentproviderinstance.AllowUserRefundEQ(true),
|
||||||
|
paymentproviderinstance.RefundEnabledEQ(true),
|
||||||
|
).Select(paymentproviderinstance.FieldID).All(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
ids := make([]string, 0, len(instances))
|
||||||
|
for _, inst := range instances {
|
||||||
|
ids = append(ids, strconv.FormatInt(int64(inst.ID), 10))
|
||||||
|
}
|
||||||
|
return ids, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (s *PaymentConfigService) mergeConfig(ctx context.Context, id int64, newConfig map[string]string) (map[string]string, error) {
|
func (s *PaymentConfigService) mergeConfig(ctx context.Context, id int64, newConfig map[string]string) (map[string]string, error) {
|
||||||
inst, err := s.entClient.PaymentProviderInstance.Get(ctx, id)
|
inst, err := s.entClient.PaymentProviderInstance.Get(ctx, id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -114,6 +114,7 @@ type CreateProviderInstanceRequest struct {
|
|||||||
SortOrder int `json:"sort_order"`
|
SortOrder int `json:"sort_order"`
|
||||||
Limits string `json:"limits"`
|
Limits string `json:"limits"`
|
||||||
RefundEnabled bool `json:"refund_enabled"`
|
RefundEnabled bool `json:"refund_enabled"`
|
||||||
|
AllowUserRefund bool `json:"allow_user_refund"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type UpdateProviderInstanceRequest struct {
|
type UpdateProviderInstanceRequest struct {
|
||||||
@@ -125,6 +126,7 @@ type UpdateProviderInstanceRequest struct {
|
|||||||
SortOrder *int `json:"sort_order"`
|
SortOrder *int `json:"sort_order"`
|
||||||
Limits *string `json:"limits"`
|
Limits *string `json:"limits"`
|
||||||
RefundEnabled *bool `json:"refund_enabled"`
|
RefundEnabled *bool `json:"refund_enabled"`
|
||||||
|
AllowUserRefund *bool `json:"allow_user_refund"`
|
||||||
}
|
}
|
||||||
type CreatePlanRequest struct {
|
type CreatePlanRequest struct {
|
||||||
GroupID int64 `json:"group_id"`
|
GroupID int64 `json:"group_id"`
|
||||||
|
|||||||
@@ -100,9 +100,22 @@ func valueOrZero(v *int64) int64 {
|
|||||||
return *v
|
return *v
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AccountQuotaState holds the post-increment quota state returned by the DB transaction.
|
||||||
|
// All values are post-update (i.e., already include the increment).
|
||||||
|
type AccountQuotaState struct {
|
||||||
|
TotalUsed float64
|
||||||
|
TotalLimit float64
|
||||||
|
DailyUsed float64
|
||||||
|
DailyLimit float64
|
||||||
|
WeeklyUsed float64
|
||||||
|
WeeklyLimit float64
|
||||||
|
}
|
||||||
|
|
||||||
type UsageBillingApplyResult struct {
|
type UsageBillingApplyResult struct {
|
||||||
Applied bool
|
Applied bool
|
||||||
APIKeyQuotaExhausted bool
|
APIKeyQuotaExhausted bool
|
||||||
|
NewBalance *float64 // post-deduction balance (nil = no balance deduction)
|
||||||
|
QuotaState *AccountQuotaState // post-increment quota state (nil = no quota increment)
|
||||||
}
|
}
|
||||||
|
|
||||||
type UsageBillingRepository interface {
|
type UsageBillingRepository interface {
|
||||||
|
|||||||
Reference in New Issue
Block a user