client.active.draw.log.go 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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)" 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) Create() (ClientActiveDrawLog, error) {
  33. var doc ClientActiveDrawLog
  34. var err error
  35. doc = *m
  36. err = orm.ShMysql.Table(m.TableName()).Create(&doc).Error
  37. if err != nil {
  38. return doc, err
  39. }
  40. return doc, nil
  41. }
  42. func (m *ClientActiveDrawLog) GetClientActiveDrawLogListByOpenId(pageSize int, pageIndex int) ([]ClientActiveDrawLog, int, error) {
  43. var doc []ClientActiveDrawLog
  44. table := orm.ShMysql.Table(m.TableName())
  45. table = table.Where("client_open_id = ? ", m.ClientOpenID)
  46. var count int
  47. if err := table.Select("*").Order("id desc").Offset((pageIndex - 1) * pageSize).Limit(pageSize).Find(&doc).Error; err != nil {
  48. return nil, 0, err
  49. }
  50. table.Count(&count)
  51. return doc, count, nil
  52. }
  53. func (m *ClientActiveDrawLog) GetClientActiveDrawLogListById() (ClientActiveDrawLog, error) {
  54. var doc ClientActiveDrawLog
  55. table := orm.ShMysql.Table(m.TableName())
  56. table = table.Where("id = ? ", m.ID)
  57. if err := table.Select("*").Order("id desc").First(&doc).Error; err != nil {
  58. return doc, err
  59. }
  60. return doc, nil
  61. }
  62. func (m *ClientActiveDrawLog) UpdateDrawPrize() error {
  63. if err := orm.ShMysql.Table(m.TableName()).Model(&m).Where("id = ? ", m.ID).Updates(
  64. map[string]interface{}{
  65. "is_prize": m.IsPrize,
  66. "updated_at": tools.GetCurrntTimeStr()}).Error; err != nil {
  67. return err
  68. }
  69. return nil
  70. }