You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
50 lines
2.2 KiB
50 lines
2.2 KiB
package models
|
|
|
|
import (
|
|
"github.com/ouxuanserver/osmanthuswine/src/core"
|
|
"time"
|
|
)
|
|
|
|
const SignHistoryTN = TableNamePrefix + "sign_history"
|
|
|
|
//签到历史表
|
|
type SignHistory struct {
|
|
Id int64 `json:"id" xorm:"pk autoincr comment('主键') INT(11)"`
|
|
AreaId int64 `json:"area_id" xorm:"not null default 0 comment('地区id') INT(11)"`
|
|
ActivityId int64 `json:"activity_id" xorm:"not null default 0 comment('主活动id') INT(11)"`
|
|
RehearsalId int64 `json:"rehearsal_id" xorm:"not null default 0 comment('彩排id/ 0正式') INT(11)"`
|
|
SignRuleId int64 `json:"sign_rule_id" xorm:"not null default 0 comment('sign_up表id') INT(11)"`
|
|
Type int `json:"type" xorm:"not null default 0 comment('普通签到') TINYINT(1)"`
|
|
UserId int64 `json:"user_id" xorm:"not null default 0 comment('用户表id') INT(11)"`
|
|
IsDelete bool `json:"is_delete" xorm:"not null default(0) comment('删除') TINYINT(1)"`
|
|
CreatedAt time.Time `json:"created_at" xorm:"not null created comment('创建时间') DATETIME"`
|
|
UpdatedAt time.Time `json:"updated_at" xorm:"not null updated comment('更新时间') DATETIME"`
|
|
}
|
|
|
|
func (t *SignHistory) TableName() string {
|
|
return SignHistoryTN
|
|
}
|
|
|
|
func (t *SignHistory) GetByUserId(aid, uid, rid, arid int64) (bool, error) {
|
|
return core.GetXormAuto().Where("is_delete=0 and activity_id=? and user_id=? and "+
|
|
"rehearsal_id=? and area_id=?", aid, uid, rid, arid).Get(t)
|
|
}
|
|
|
|
func (t *SignHistory) Count(signUpId, activityId, rehearsalId interface{}) (int64, error) {
|
|
// 签到人数
|
|
return core.GetXormAuto().Where("is_delete=0 and sign_rule_id=? and rehearsal_id=? and activity_id=?",
|
|
signUpId, rehearsalId, activityId).Count(t)
|
|
}
|
|
|
|
func GetLotteryUsersResultBySignHistory(obj, areaId, activityId, rehearsalId interface{}, ids []int64) error {
|
|
session := core.GetXormAuto().Table(new(SignHistory)).Alias("h").
|
|
Select("h.user_id, u.nickname as username, u.avatar").Distinct("h.user_id").
|
|
Join("LEFT", new(User).Alias("u"), "h.user_id=u.id and u.is_delete = 0").
|
|
Where("h.is_delete=0 and h.area_id=? and h.activity_id=? and h.rehearsal_id=?",
|
|
areaId, activityId, rehearsalId)
|
|
defer session.Close()
|
|
if len(ids) > 0 {
|
|
session = session.NotIn("h.user_id", ids)
|
|
}
|
|
return session.Find(&obj)
|
|
}
|