sys_coin.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. package entity
  2. import (
  3. "app/commons/constant"
  4. "gorm.io/gorm"
  5. )
  6. type SysCoin struct {
  7. MysqlBaseModel
  8. Symbol string `json:"symbol" gorm:"comment:币种名;unique;index;type:VARCHAR(20)"`
  9. Icon string `json:"icon" gorm:"comment:图标;type:VARCHAR(255)"`
  10. WithdrawStatus bool `json:"withdrawStatus" gorm:"type:tinyint;default:false;comment:是否允许提现(全局):0=禁止,1=允许"`
  11. Enable bool `json:"enable" gorm:"default:false;comment:是否有效"`
  12. }
  13. func (*SysCoin) TableName() string {
  14. return SysModelPrefix + "coin"
  15. }
  16. func (*SysCoin) Comment() string {
  17. return "平台代币"
  18. }
  19. func NewSysCoin() *SysCoin {
  20. return &SysCoin{}
  21. }
  22. func (c *SysCoin) DataInit(db *gorm.DB) error {
  23. list := []SysCoin{
  24. {
  25. Symbol: constant.CoinSymbolTD,
  26. Enable: true,
  27. Icon: "",
  28. WithdrawStatus: true,
  29. },
  30. {
  31. Symbol: constant.CoinSymbolUSDT,
  32. Enable: true,
  33. Icon: "",
  34. WithdrawStatus: true,
  35. },
  36. }
  37. for _, row := range list {
  38. find := NewSysCoin()
  39. if stat := db.Model(&SysCoin{}).Where("symbol = ?", row.Symbol).
  40. Find(&find).Statement; stat.RowsAffected == 0 {
  41. if err := db.Create(&row).Error; err != nil {
  42. return err
  43. }
  44. }
  45. }
  46. return nil
  47. }