asset_config.go 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package entity
  2. import (
  3. "github.com/shopspring/decimal"
  4. "gorm.io/gorm"
  5. )
  6. // 系统配置表 -- 可修改
  7. type AssetConfig struct {
  8. MysqlBaseModel
  9. WithdrawStatus bool `json:"withdrawStatus" gorm:"type:tinyint;default:false;comment:是否允许提现(全局):0=禁止,1=允许"`
  10. WithdrawNoauditLimit decimal.Decimal `json:"withdrawNoauditLimit" gorm:"default:0;type:decimal(25,8);comment:提现免审额度,0表示都需要审核"`
  11. MinWithdrawAmount decimal.Decimal `json:"minWithdrawAmount" gorm:"default:0;type:decimal(25,8);comment:提现最小限额,0表示无限制"`
  12. MaxWithdrawAmount decimal.Decimal `json:"maxWithdrawAmount" gorm:"default:0;type:decimal(25,8);comment:每笔提现最大限额,-1表示无限制,0表示不能提现"`
  13. WithdrawRatio decimal.Decimal `json:"withdrawRatio" gorm:"type:decimal(25,8);comment:提现手续费比例"`
  14. WithdrawBaseAmount decimal.Decimal `json:"withdrawBaseAmount" gorm:"default:0;type:decimal(25,8);comment:单次提现手续费数量"`
  15. }
  16. func (*AssetConfig) TableName() string {
  17. return ModelPrefix + "asset_config"
  18. }
  19. func (*AssetConfig) Comment() string {
  20. return "提现配置配置表"
  21. }
  22. func NewAssetConfig() *AssetConfig {
  23. return &AssetConfig{}
  24. }
  25. func (c *AssetConfig) DataInit(db *gorm.DB) error {
  26. list := []AssetConfig{
  27. {
  28. WithdrawNoauditLimit: decimal.NewFromFloat(10000),
  29. MinWithdrawAmount: decimal.NewFromFloat(1),
  30. MaxWithdrawAmount: decimal.NewFromFloat(100000),
  31. WithdrawStatus: true,
  32. WithdrawRatio: decimal.Zero,
  33. },
  34. }
  35. for _, row := range list {
  36. find := NewAssetConfig()
  37. if stat := db.Model(&AssetConfig{}).Where("id = ?", 1).
  38. Find(&find).Statement; stat.RowsAffected == 0 {
  39. if err := db.Create(&row).Error; err != nil {
  40. return err
  41. }
  42. }
  43. }
  44. return nil
  45. }