package shanghu import ( orm "duoduo/database" "duoduo/tools" "time" ) type ClientActiveDrawLog struct { ID int64 `gorm:"column:id;type:bigint(20);primary_key;AUTO_INCREMENT" json:"id"` ActiveConfigID int64 `gorm:"column:active_config_id;type:bigint(20)" json:"active_config_id"` // 活动抽奖id ClientOpenID string `gorm:"column:client_open_id;type:varchar(255)" json:"client_open_id"` // DrawProductID int64 `gorm:"column:draw_product_id;type:bigint(20)" json:"draw_product_id"` // 中奖商品 CreateBy int64 `gorm:"column:create_by;type:bigint(20)" json:"create_by"` // 创建者 UpdateBy int64 `gorm:"column:update_by;type:bigint(20)" json:"update_by"` // 更新者 CreatedAt time.Time `gorm:"column:created_at;type:datetime(3)" json:"created_at"` // 创建时间 UpdatedAt time.Time `gorm:"column:updated_at;type:datetime(3)" json:"updated_at"` // 最后更新时间 DeletedAt time.Time `gorm:"column:deleted_at;type:datetime(3);default:null" json:"deleted_at"` // 删除时间 IsPrize int `gorm:"column:is_prize;type:int(11)" json:"is_prize"` // 1-未中奖 2-未兑奖 3-已兑奖 } func (m *ClientActiveDrawLog) TableName() string { return "client_active_draw_log" } func (m *ClientActiveDrawLog) GetClientActiveDrawLogByBiZHong() (int64, error) { var count int64 table := orm.ShMysql.Table(m.TableName()) table = table.Where("active_config_id = ? and client_open_id = ? and draw_product_id = ? ", m.ActiveConfigID, m.ClientOpenID, m.DrawProductID) if err := table.Count(&count).Error; err != nil { return 0, nil } return count, nil } func (m *ClientActiveDrawLog) GetClientActiveDrawLogNum() (int, error) { var count int table := orm.ShMysql.Table(m.TableName()) table = table.Where("active_config_id = ? and client_open_id = ? ", m.ActiveConfigID, m.ClientOpenID) if err := table.Count(&count).Error; err != nil { return 0, nil } return count, nil } func (m *ClientActiveDrawLog) Create() (ClientActiveDrawLog, error) { var doc ClientActiveDrawLog var err error doc = *m err = orm.ShMysql.Table(m.TableName()).Create(&doc).Error if err != nil { return doc, err } return doc, nil } func (m *ClientActiveDrawLog) GetClientActiveDrawLogListByOpenId(pageSize int, pageIndex int) ([]ClientActiveDrawLog, int, error) { var doc []ClientActiveDrawLog table := orm.ShMysql.Table(m.TableName()) table = table.Where("client_open_id = ? ", m.ClientOpenID) var count int if err := table.Select("*").Order("id desc").Offset((pageIndex - 1) * pageSize).Limit(pageSize).Find(&doc).Error; err != nil { return nil, 0, err } table.Count(&count) return doc, count, nil } func (m *ClientActiveDrawLog) GetClientActiveDrawLogListById() (ClientActiveDrawLog, error) { var doc ClientActiveDrawLog table := orm.ShMysql.Table(m.TableName()) table = table.Where("id = ? ", m.ID) if err := table.Select("*").Order("id desc").First(&doc).Error; err != nil { return doc, err } return doc, nil } func (m *ClientActiveDrawLog) GetClientActiveDrawLogListByOpenIdAndId() (ClientActiveDrawLog, error) { var doc ClientActiveDrawLog table := orm.ShMysql.Table(m.TableName()) table = table.Where("id = ? and client_open_id = ?", m.ID, m.ClientOpenID) if err := table.Select("*").Order("id desc").First(&doc).Error; err != nil { return doc, err } return doc, nil } func (m *ClientActiveDrawLog) UpdateDrawPrize() error { if err := orm.ShMysql.Table(m.TableName()).Model(&m).Where("id = ? ", m.ID).Updates( map[string]interface{}{ "is_prize": m.IsPrize, "updated_at": tools.GetCurrntTimeStr()}).Error; err != nil { return err } return nil }