package shanghu import ( orm "duoduo/database" "time" ) type ClientActiveDrawNum struct { ID int `gorm:"column:id;type:int(11);primary_key;AUTO_INCREMENT" json:"id"` ActiveConfigID int64 `gorm:"column:active_config_id;type:bigint(20)" json:"active_config_id"` ClientOpenID string `gorm:"column:client_open_id;type:varchar(255)" json:"client_open_id"` // 邀请人 ClientOpenIDInvited string `gorm:"column:client_open_id_invited;type:varchar(255)" json:"client_open_id_invited"` // 被邀请人 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"` // 删除时间 } func (m *ClientActiveDrawNum) TableName() string { return "client_active_draw_num" } // 抽奖次数 func (m *ClientActiveDrawNum) GetDrawNum() (int, error) { table := orm.ShMysql.Table(m.TableName()) table = table.Where("client_open_id = ? and active_config_id = ? ", m.ClientOpenID, m.ActiveConfigID) var count int table.Count(&count) return count, nil } func (u *ClientActiveDrawNum) Create() (ClientActiveDrawNum, error) { var doc ClientActiveDrawNum var err error doc = *u err = orm.ShMysql.Table(u.TableName()).Create(&doc).Error if err != nil { return doc, err } return doc, nil } func (m *ClientActiveDrawNum) GetClientDrawNum() (int, error) { table := orm.ShMysql.Table(m.TableName()) table = table.Where("client_open_id = ? and active_config_id = ? and client_open_id_invited = ? ", m.ClientOpenID, m.ActiveConfigID, m.ClientOpenIDInvited) var count int table.Count(&count) return count, nil } func (m *ClientActiveDrawNum) GetClientDrawByOpenID() (int, error) { table := orm.ShMysql.Table(m.TableName()) table = table.Where("client_open_id = ? and active_config_id = ? ", m.ClientOpenID, m.ActiveConfigID) var count int table.Count(&count) return count, nil }