package models import ( "github.com/ouxuanserver/osmanthuswine/src/core" "hudongzhuanjia/utils/define" "time" ) const NewVoteActivityTableName = TableNamePrefix + "new_vote_activity" type NewVoteActivity struct { Id int64 `json:"id" xorm:"not null pk autoincr INT(11)"` ActivityId int64 `json:"activity_id" xorm:"not null comment('互动id') INT(11)"` VoteActivityLadders []*NewVoteActivityLadder `json:"vote_activity_ladders" xorm:"-"` Theme string `json:"theme" xorm:"not null default('') comment('投票主题') VARCHAR(255)"` JoinWay string `json:"join_way" xorm:"not null comment('参与方式说明') TEXT"` Description string `json:"description" xorm:"not null comment('投票介绍') TEXT"` Model string `json:"model" xorm:"not null default('单选') comment('投票类型[单选|多选]') VARCHAR(128)"` ModelNum int64 `json:"model_num" xorm:"not null default(1) comment('投票类型选多少个') INT(11)"` VoteLastTime string `json:"vote_last_time" description:"投票时长秒 0表示无时间限制"` VoteEndTime int64 `json:"vote_end_time" xorm:"default(0)" description:"投票开始时间"` ResultDisplay string `json:"result_display" description:"结果展示[百分比|票数]"` ResultLimit int `json:"result_limit" description:"默认显示多少名"` DisplayVoteNumber string `json:"display_vote_number" description:"[显示|不显示] 投票人数"` PhoneVoteDisplayResult string `json:"phone_vote_display_result" description:"[显示|不显示] 手机端投票是否显示结果"` VoteBySignUser string `json:"vote_by_sign_user" description:"[指定|不指定] 是否指定签到用户投票"` VoteStatus string `json:"vote_status" description:"投票活动的状态 [可投票|不可投票]"` IsDelete bool `json:"-" xorm:"default(0)"` CreatedAt time.Time `json:"-" xorm:"created"` UpdatedAt time.Time `json:"-" xorm:"updated"` } func (t *NewVoteActivity) TableName() string { return NewVoteActivityTableName } //func (t *NewVoteActivity) GetByActivityId(aid int64, status string) (bool, error) { // return core.GetXormAuto().Where("is_delete=0 and activity_id=? and vote_status=?", aid, status). // Desc("created_at").Get(t) //} func (t *NewVoteActivity) UpdateToStatusByAid(aid int64, before string, after string) (int64, error) { t.VoteStatus = after t.UpdatedAt = time.Now() return core.GetXormAuto().Where("is_delete=0 and vote_status=? and activity_id=?", before, aid). Cols("vote_status", "updated_at").Update(t) } func (t *NewVoteActivity) UpdateStatusById(id int64, status string) (int64, error) { t.VoteStatus = status t.UpdatedAt = time.Now() return core.GetXormAuto().Where("is_delete=0 and id=?", id). Cols("vote_status", "updated_at").Update(t) } func (t *NewVoteActivity) GetCurrent(aid int64) (bool, error) { return core.GetXormAuto().Where("is_delete=0 and activity_id=? and (vote_status=? or vote_status=?)", aid, define.StatusReady, define.StatusRunning).Desc("created_at").Get(t) } func UpdateVoteStatusByActivityId(aid int64) (int64, error) { return core.GetXormAuto().Where("is_delete=0 and activity_id=?", aid). Update(&NewVoteActivity{VoteStatus: define.StatusNotBegin}) } func GetVoteListByActivityId(activityId interface{}) ([]*NewVoteActivity, error) { votes := make([]*NewVoteActivity, 0) err := core.GetXormAuto().Where("is_delete=0 and activity_id=?", activityId). Asc("created_at").Find(&votes) return votes, err }