| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- package entity
- import (
- "app/commons/constant"
- "github.com/shopspring/decimal"
- "gorm.io/gorm"
- "time"
- )
- const (
- PartnerNode = "合伙人节点"
- EcologicalNode = "生态节点"
- )
- // 节点产品
- type NodeInfo struct {
- MysqlBaseModel
- NodeName string `json:"nodeName" gorm:"unique;index;type:varchar(36);comment:节点名称;"`
- SupportPaymentSymbols string `json:"supportPaymentSymbols" gorm:"type:varchar(64);comment:支持的支付币种,分割;"`
- UsdPrice decimal.Decimal `json:"usdPrice" gorm:"type:decimal(25,8);default:0;comment:单价"`
- SoldQuantity decimal.Decimal `json:"soldQuantity" gorm:"type:decimal(25,2);default:0;comment:已售出数量"`
- UpperQuantityLimit decimal.Decimal `json:"upperQuantityLimit" gorm:"type:decimal(25,2);default:0;comment:可售出上限"`
- LimitTime int64 `json:"limitTime" gorm:"default:0;comment:结束时间"`
- Sort int `json:"sort" gorm:"default:0;comment:排序"`
- Enable bool `json:"enable" gorm:"type:tinyint;default:0;comment:是否有效 1:开放购买 0:未开放购买"`
- }
- func (*NodeInfo) TableName() string {
- return NodeModelPrefix + "info"
- }
- func (*NodeInfo) Comment() string {
- return "节点产品"
- }
- func NewNodeInfo() *NodeInfo {
- return &NodeInfo{}
- }
- func (c *NodeInfo) DataInit(db *gorm.DB) error {
- list := []NodeInfo{
- {
- NodeName: PartnerNode,
- SupportPaymentSymbols: constant.CoinSymbolUSDT,
- UsdPrice: decimal.NewFromFloat(5000),
- SoldQuantity: decimal.NewFromFloat(0),
- UpperQuantityLimit: decimal.NewFromFloat(3000),
- LimitTime: time.Now().AddDate(0, 1, 0).Unix(),
- Sort: 0,
- Enable: true,
- },
- }
- for _, row := range list {
- find := NewNodeInfo()
- if stat := db.Model(&NodeInfo{}).
- Where("node_name = ?", row.NodeName).
- Find(&find).Statement; stat.RowsAffected == 0 {
- if err := db.Create(&row).Error; err != nil {
- return err
- }
- }
- }
- return nil
- }
|