You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

56 lines
1.6 KiB

  1. package model
  2. import "time"
  3. const (
  4. SyncTypeUserCreate = "user_create"
  5. SyncTypeQuotaChange = "quota_change"
  6. SyncTypePreConsumeQuery = "pre_consume_query"
  7. SyncTypeBatchSync = "batch_sync"
  8. SyncTypeManualSync = "manual_sync"
  9. SyncTypeStartupSync = "startup_sync"
  10. SyncTypeSettle = "settle"
  11. )
  12. const (
  13. SyncDirectionCnToOv = "cn_to_ov"
  14. SyncDirectionOvToCn = "ov_to_cn"
  15. )
  16. const (
  17. SyncStatusSuccess = "success"
  18. SyncStatusFailed = "failed"
  19. )
  20. // QuotaSyncLog 余额同步日志
  21. type QuotaSyncLog struct {
  22. Id int `json:"id" gorm:"primaryKey"`
  23. UserId int `json:"user_id" gorm:"index:idx_user_id"`
  24. RemoteUserId int `json:"remote_user_id" gorm:"index"`
  25. SyncType string `json:"sync_type" gorm:"size:32;index:idx_sync_type"`
  26. BeforeQuota int `json:"before_quota"`
  27. AfterQuota int `json:"after_quota"`
  28. ChangeAmount int `json:"change_amount"`
  29. MasterQuota int `json:"master_quota"`
  30. PendingQuota int `json:"pending_quota"`
  31. RequestId string `json:"request_id"`
  32. Model string `json:"model"`
  33. Direction string `json:"direction" gorm:"size:16"`
  34. Status string `json:"status" gorm:"size:16;default:'success';index:idx_status"`
  35. ErrorMsg string `json:"error_msg"`
  36. CreatedAt int64 `json:"created_at" gorm:"index:idx_created_at"`
  37. SyncedAt int64 `json:"synced_at"`
  38. }
  39. func (QuotaSyncLog) TableName() string {
  40. return "quota_sync_logs"
  41. }
  42. // CreateSyncLog 创建同步日志
  43. func CreateSyncLog(log *QuotaSyncLog) error {
  44. if log.CreatedAt == 0 {
  45. log.CreatedAt = time.Now().Unix()
  46. }
  47. return DB.Create(log).Error
  48. }