node_info.go 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. package entity
  2. import (
  3. "app/commons/constant"
  4. "github.com/shopspring/decimal"
  5. "gorm.io/gorm"
  6. "time"
  7. )
  8. const (
  9. PartnerNode = "合伙人节点"
  10. EcologicalNode = "生态节点"
  11. )
  12. // 节点产品
  13. type NodeInfo struct {
  14. MysqlBaseModel
  15. NodeName string `json:"nodeName" gorm:"unique;index;type:varchar(36);comment:节点名称;"`
  16. SupportPaymentSymbols string `json:"supportPaymentSymbols" gorm:"type:varchar(64);comment:支持的支付币种,分割;"`
  17. UsdPrice decimal.Decimal `json:"usdPrice" gorm:"type:decimal(25,8);default:0;comment:单价"`
  18. SoldQuantity decimal.Decimal `json:"soldQuantity" gorm:"type:decimal(25,2);default:0;comment:已售出数量"`
  19. UpperQuantityLimit decimal.Decimal `json:"upperQuantityLimit" gorm:"type:decimal(25,2);default:0;comment:可售出上限"`
  20. LimitTime int64 `json:"limitTime" gorm:"default:0;comment:结束时间"`
  21. Sort int `json:"sort" gorm:"default:0;comment:排序"`
  22. Enable bool `json:"enable" gorm:"type:tinyint;default:0;comment:是否有效 1:开放购买 0:未开放购买"`
  23. }
  24. func (*NodeInfo) TableName() string {
  25. return NodeModelPrefix + "info"
  26. }
  27. func (*NodeInfo) Comment() string {
  28. return "节点产品"
  29. }
  30. func NewNodeInfo() *NodeInfo {
  31. return &NodeInfo{}
  32. }
  33. func (c *NodeInfo) DataInit(db *gorm.DB) error {
  34. list := []NodeInfo{
  35. {
  36. NodeName: PartnerNode,
  37. SupportPaymentSymbols: constant.CoinSymbolUSDT,
  38. UsdPrice: decimal.NewFromFloat(5000),
  39. SoldQuantity: decimal.NewFromFloat(0),
  40. UpperQuantityLimit: decimal.NewFromFloat(3000),
  41. LimitTime: time.Now().AddDate(0, 1, 0).Unix(),
  42. Sort: 0,
  43. Enable: true,
  44. },
  45. }
  46. for _, row := range list {
  47. find := NewNodeInfo()
  48. if stat := db.Model(&NodeInfo{}).
  49. Where("node_name = ?", row.NodeName).
  50. Find(&find).Statement; stat.RowsAffected == 0 {
  51. if err := db.Create(&row).Error; err != nil {
  52. return err
  53. }
  54. }
  55. }
  56. return nil
  57. }