client.active.draw.log.go 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. package shanghu
  2. import (
  3. orm "duoduo/database"
  4. "duoduo/tools"
  5. "time"
  6. )
  7. type ClientActiveDrawLog struct {
  8. ID int64 `gorm:"column:id;type:bigint(20);primary_key;AUTO_INCREMENT" json:"id"`
  9. ActiveConfigID int64 `gorm:"column:active_config_id;type:bigint(20)" json:"active_config_id"` // 活动抽奖id
  10. ClientOpenID string `gorm:"column:client_open_id;type:varchar(255)" json:"client_open_id"` //
  11. DrawProductID int64 `gorm:"column:draw_product_id;type:bigint(20)" json:"draw_product_id"` // 中奖商品
  12. CreateBy int64 `gorm:"column:create_by;type:bigint(20)" json:"create_by"` // 创建者
  13. UpdateBy int64 `gorm:"column:update_by;type:bigint(20)" json:"update_by"` // 更新者
  14. CreatedAt time.Time `gorm:"column:created_at;type:datetime(3)" json:"created_at"` // 创建时间
  15. UpdatedAt time.Time `gorm:"column:updated_at;type:datetime(3)" json:"updated_at"` // 最后更新时间
  16. DeletedAt time.Time `gorm:"column:deleted_at;type:datetime(3);default:null" json:"deleted_at"` // 删除时间
  17. IsPrize int `gorm:"column:is_prize;type:int(11)" json:"is_prize"` // 1-未中奖 2-未兑奖 3-已兑奖
  18. }
  19. func (m *ClientActiveDrawLog) TableName() string {
  20. return "client_active_draw_log"
  21. }
  22. func (m *ClientActiveDrawLog) GetClientActiveDrawLogByBiZHong() (int64, error) {
  23. var count int64
  24. table := orm.ShMysql.Table(m.TableName())
  25. table = table.Where("active_config_id = ? and client_open_id = ? and draw_product_id = ? ",
  26. m.ActiveConfigID, m.ClientOpenID, m.DrawProductID)
  27. if err := table.Count(&count).Error; err != nil {
  28. return 0, nil
  29. }
  30. return count, nil
  31. }
  32. func (m *ClientActiveDrawLog) GetClientActiveDrawLogNum() (int, error) {
  33. var count int
  34. table := orm.ShMysql.Table(m.TableName())
  35. table = table.Where("active_config_id = ? and client_open_id = ? ",
  36. m.ActiveConfigID, m.ClientOpenID)
  37. if err := table.Count(&count).Error; err != nil {
  38. return 0, nil
  39. }
  40. return count, nil
  41. }
  42. func (m *ClientActiveDrawLog) Create() (ClientActiveDrawLog, error) {
  43. var doc ClientActiveDrawLog
  44. var err error
  45. doc = *m
  46. err = orm.ShMysql.Table(m.TableName()).Create(&doc).Error
  47. if err != nil {
  48. return doc, err
  49. }
  50. return doc, nil
  51. }
  52. func (m *ClientActiveDrawLog) GetClientActiveDrawLogListByOpenId(pageSize int, pageIndex int) ([]ClientActiveDrawLog, int, error) {
  53. var doc []ClientActiveDrawLog
  54. table := orm.ShMysql.Table(m.TableName())
  55. table = table.Where("client_open_id = ? ", m.ClientOpenID)
  56. var count int
  57. if err := table.Select("*").Order("id desc").Offset((pageIndex - 1) * pageSize).Limit(pageSize).Find(&doc).Error; err != nil {
  58. return nil, 0, err
  59. }
  60. table.Count(&count)
  61. return doc, count, nil
  62. }
  63. func (m *ClientActiveDrawLog) GetClientActiveDrawLogListById() (ClientActiveDrawLog, error) {
  64. var doc ClientActiveDrawLog
  65. table := orm.ShMysql.Table(m.TableName())
  66. table = table.Where("id = ? ", m.ID)
  67. if err := table.Select("*").Order("id desc").First(&doc).Error; err != nil {
  68. return doc, err
  69. }
  70. return doc, nil
  71. }
  72. func (m *ClientActiveDrawLog) UpdateDrawPrize() error {
  73. if err := orm.ShMysql.Table(m.TableName()).Model(&m).Where("id = ? ", m.ID).Updates(
  74. map[string]interface{}{
  75. "is_prize": m.IsPrize,
  76. "updated_at": tools.GetCurrntTimeStr()}).Error; err != nil {
  77. return err
  78. }
  79. return nil
  80. }