client.active.draw.num.go 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. package shanghu
  2. import (
  3. orm "duoduo/database"
  4. "time"
  5. )
  6. type ClientActiveDrawNum struct {
  7. ID int `gorm:"column:id;type:int(11);primary_key;AUTO_INCREMENT" json:"id"`
  8. ActiveConfigID int64 `gorm:"column:active_config_id;type:bigint(20)" json:"active_config_id"`
  9. ClientOpenID string `gorm:"column:client_open_id;type:varchar(255)" json:"client_open_id"` // 邀请人
  10. ClientOpenIDInvited string `gorm:"column:client_open_id_invited;type:varchar(255)" json:"client_open_id_invited"` // 被邀请人
  11. CreateBy int64 `gorm:"column:create_by;type:bigint(20)" json:"create_by"` // 创建者
  12. UpdateBy int64 `gorm:"column:update_by;type:bigint(20)" json:"update_by"` // 更新者
  13. CreatedAt time.Time `gorm:"column:created_at;type:datetime(3)" json:"created_at"` // 创建时间
  14. UpdatedAt time.Time `gorm:"column:updated_at;type:datetime(3)" json:"updated_at"` // 最后更新时间
  15. DeletedAt time.Time `gorm:"column:deleted_at;type:datetime(3);default:null" json:"deleted_at"` // 删除时间
  16. }
  17. func (m *ClientActiveDrawNum) TableName() string {
  18. return "client_active_draw_num"
  19. }
  20. // 抽奖次数
  21. func (m *ClientActiveDrawNum) GetDrawNum() (int, error) {
  22. table := orm.ShMysql.Table(m.TableName())
  23. table = table.Where("client_open_id = ? and active_config_id = ? ", m.ClientOpenID, m.ActiveConfigID)
  24. var count int
  25. table.Count(&count)
  26. return count, nil
  27. }
  28. func (u *ClientActiveDrawNum) Create() (ClientActiveDrawNum, error) {
  29. var doc ClientActiveDrawNum
  30. var err error
  31. doc = *u
  32. err = orm.ShMysql.Table(u.TableName()).Create(&doc).Error
  33. if err != nil {
  34. return doc, err
  35. }
  36. return doc, nil
  37. }
  38. func (m *ClientActiveDrawNum) GetClientDrawNum() (int, error) {
  39. table := orm.ShMysql.Table(m.TableName())
  40. table = table.Where("client_open_id = ? and active_config_id = ? and client_open_id_invited = ? ", m.ClientOpenID, m.ActiveConfigID, m.ClientOpenIDInvited)
  41. var count int
  42. table.Count(&count)
  43. return count, nil
  44. }
  45. func (m *ClientActiveDrawNum) GetClientDrawByOpenID() (int, error) {
  46. table := orm.ShMysql.Table(m.TableName())
  47. table = table.Where("client_open_id = ? and active_config_id = ? ", m.ClientOpenID, m.ActiveConfigID)
  48. var count int
  49. table.Count(&count)
  50. return count, nil
  51. }