| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- package entity
- import (
- "app/commons/constant"
- "gorm.io/gorm"
- )
- type SysCoin struct {
- MysqlBaseModel
- Symbol string `json:"symbol" gorm:"comment:币种名;unique;index;type:VARCHAR(20)"`
- Icon string `json:"icon" gorm:"comment:图标;type:VARCHAR(255)"`
- WithdrawStatus bool `json:"withdrawStatus" gorm:"type:tinyint;default:false;comment:是否允许提现(全局):0=禁止,1=允许"`
- Enable bool `json:"enable" gorm:"default:false;comment:是否有效"`
- }
- func (*SysCoin) TableName() string {
- return SysModelPrefix + "coin"
- }
- func (*SysCoin) Comment() string {
- return "平台代币"
- }
- func NewSysCoin() *SysCoin {
- return &SysCoin{}
- }
- func (c *SysCoin) DataInit(db *gorm.DB) error {
- list := []SysCoin{
- {
- Symbol: constant.CoinSymbolTD,
- Enable: true,
- Icon: "",
- WithdrawStatus: true,
- },
- {
- Symbol: constant.CoinSymbolUSDT,
- Enable: true,
- Icon: "",
- WithdrawStatus: true,
- },
- }
- for _, row := range list {
- find := NewSysCoin()
- if stat := db.Model(&SysCoin{}).Where("symbol = ?", row.Symbol).
- Find(&find).Statement; stat.RowsAffected == 0 {
- if err := db.Create(&row).Error; err != nil {
- return err
- }
- }
- }
- return nil
- }
|