billing.go 857 B

123456789101112131415161718192021
  1. package common
  2. import "github.com/gin-gonic/gin"
  3. // BillingSettler 抽象计费会话的生命周期操作。
  4. // 由 service.BillingSession 实现,存储在 RelayInfo 上以避免循环引用。
  5. type BillingSettler interface {
  6. // Settle 根据实际消耗额度进行结算,计算 delta = actualQuota - preConsumedQuota,
  7. // 同时调整资金来源(钱包/订阅)和令牌额度。
  8. Settle(actualQuota int) error
  9. // Refund 退还所有预扣费额度(资金来源 + 令牌),幂等安全。
  10. // 通过 gopool 异步执行。如果已经结算或退款则不做任何操作。
  11. Refund(c *gin.Context)
  12. // NeedsRefund 返回会话是否存在需要退还的预扣状态(未结算且未退款)。
  13. NeedsRefund() bool
  14. // GetPreConsumedQuota 返回实际预扣的额度值(信任用户可能为 0)。
  15. GetPreConsumedQuota() int
  16. }