node_order.go 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. package entity
  2. import (
  3. "app/commons/utils"
  4. "github.com/demdxx/gocast"
  5. "github.com/shopspring/decimal"
  6. "gorm.io/gorm"
  7. )
  8. // 用户节点订单
  9. // 节点收益是否需要 手动领取
  10. const (
  11. NodeOrderPayStateWaiting = iota // 待支付
  12. NodeOrderPayStateSuccess // 支付成功
  13. NodeOrderPayStateFail // 支付失败
  14. )
  15. const (
  16. NodeOrderStateUnknown = iota // 未知
  17. NodeOrderStateEffective // 有效
  18. NodeOrderStateExpired // 过期失效
  19. NodeOrderStateFailInvalid // 主动失效
  20. )
  21. const (
  22. NodeOrderSourceFromUser = iota // 用户购买
  23. NodeOrderSourceBuy1 //
  24. NodeOrderSourceBuy2 //
  25. NodeOrderSourceBuy3 //
  26. NodeOrderSourceFromAdminBuy // 管理后台购买
  27. )
  28. type NodeOrder struct {
  29. MysqlBaseModel
  30. RecordId string `json:"recordId" gorm:"unique;type:VARCHAR(64);comment:奖励记录ID"`
  31. UserId int64 `json:"userId" gorm:"index;comment:用户ID;"`
  32. Uid string `json:"uid" gorm:"index;type:varchar(64);comment:用户交易所ID:;"`
  33. ProductId int64 `json:"productId" gorm:"comment:产品ID;"`
  34. ProductName string `json:"productName" gorm:"type:varchar(64);comment:产品名称;"`
  35. UsdPrice decimal.Decimal `json:"usdPrice" gorm:"type:decimal(25,8);default:0;comment:单价"`
  36. Quantity decimal.Decimal `json:"quantity" gorm:"type:decimal(25,2);default:0;comment:数量"`
  37. UsdAmount decimal.Decimal `json:"usdAmount" gorm:"type:decimal(25,8);default:0;comment:总价值"`
  38. PayState int `json:"payState" gorm:"default:0;comment:支付状态:0:待支付 1: 支付成功 2: 支付失败 "`
  39. State int `json:"state" gorm:"default:0;comment:订单状态:0:未知 1:有效 2:过期失效 3:其他失效 "`
  40. Source int `json:"source" gorm:"default:0;comment:来源:0 用户购买 1: 2: 3: 4:后台购买"`
  41. }
  42. func (*NodeOrder) TableName() string {
  43. return NodeModelPrefix + "node_order"
  44. }
  45. func (*NodeOrder) Comment() string {
  46. return "股票活期理财产品表"
  47. }
  48. func NewNodeOrder() *NodeOrder {
  49. return &NodeOrder{}
  50. }
  51. // BeforeCreate GORM 钩子,在创建记录之前调用
  52. func (c *NodeOrder) BeforeCreate(tx *gorm.DB) (err error) {
  53. if c.RecordId == "" {
  54. c.RecordId = gocast.ToString(utils.UuidPrefix("ND"))
  55. }
  56. return nil
  57. }