互动
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.

71 lines
3.9 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. package models
  2. import (
  3. "github.com/ouxuanserver/osmanthuswine/src/core"
  4. "hudongzhuanjia/utils/define"
  5. "time"
  6. )
  7. const NewVoteActivityTableName = TableNamePrefix + "new_vote_activity"
  8. type NewVoteActivity struct {
  9. Id int64 `json:"id" xorm:"not null pk autoincr INT(11)"`
  10. ActivityId int64 `json:"activity_id" xorm:"not null comment('互动id') INT(11)"`
  11. VoteActivityLadders []*NewVoteActivityLadder `json:"vote_activity_ladders" xorm:"-"`
  12. Theme string `json:"theme" xorm:"not null default('') comment('投票主题') VARCHAR(255)"`
  13. JoinWay string `json:"join_way" xorm:"not null comment('参与方式说明') TEXT"`
  14. Description string `json:"description" xorm:"not null comment('投票介绍') TEXT"`
  15. Model string `json:"model" xorm:"not null default('单选') comment('投票类型[单选|多选]') VARCHAR(128)"`
  16. ModelNum int64 `json:"model_num" xorm:"not null default(1) comment('投票类型选多少个') INT(11)"`
  17. VoteLastTime string `json:"vote_last_time" description:"投票时长秒 0表示无时间限制"`
  18. VoteEndTime int64 `json:"vote_end_time" xorm:"default(0)" description:"投票开始时间"`
  19. ResultDisplay string `json:"result_display" description:"结果展示[百分比|票数]"`
  20. ResultLimit int `json:"result_limit" description:"默认显示多少名"`
  21. DisplayVoteNumber string `json:"display_vote_number" description:"[显示|不显示] 投票人数"`
  22. PhoneVoteDisplayResult string `json:"phone_vote_display_result" description:"[显示|不显示] 手机端投票是否显示结果"`
  23. VoteBySignUser string `json:"vote_by_sign_user" description:"[指定|不指定] 是否指定签到用户投票"`
  24. VoteStatus string `json:"vote_status" description:"投票活动的状态 [可投票|不可投票]"`
  25. IsDelete bool `json:"-" xorm:"default(0)"`
  26. CreatedAt time.Time `json:"-" xorm:"created"`
  27. UpdatedAt time.Time `json:"-" xorm:"updated"`
  28. }
  29. func (t *NewVoteActivity) TableName() string {
  30. return NewVoteActivityTableName
  31. }
  32. //func (t *NewVoteActivity) GetByActivityId(aid int64, status string) (bool, error) {
  33. // return core.GetXormAuto().Where("is_delete=0 and activity_id=? and vote_status=?", aid, status).
  34. // Desc("created_at").Get(t)
  35. //}
  36. func (t *NewVoteActivity) UpdateToStatusByAid(aid int64, before string, after string) (int64, error) {
  37. t.VoteStatus = after
  38. t.UpdatedAt = time.Now()
  39. return core.GetXormAuto().Where("is_delete=0 and vote_status=? and activity_id=?", before, aid).
  40. Cols("vote_status", "updated_at").Update(t)
  41. }
  42. func (t *NewVoteActivity) UpdateStatusById(id int64, status string) (int64, error) {
  43. t.VoteStatus = status
  44. t.UpdatedAt = time.Now()
  45. return core.GetXormAuto().Where("is_delete=0 and id=?", id).
  46. Cols("vote_status", "updated_at").Update(t)
  47. }
  48. func (t *NewVoteActivity) GetCurrent(aid int64) (bool, error) {
  49. return core.GetXormAuto().Where("is_delete=0 and activity_id=? and (vote_status=? or vote_status=?)",
  50. aid, define.StatusReady, define.StatusRunning).Desc("created_at").Get(t)
  51. }
  52. func UpdateVoteStatusByActivityId(aid int64) (int64, error) {
  53. return core.GetXormAuto().Where("is_delete=0 and activity_id=?", aid).
  54. Update(&NewVoteActivity{VoteStatus: define.StatusNotBegin})
  55. }
  56. func GetVoteListByActivityId(activityId interface{}) ([]*NewVoteActivity, error) {
  57. votes := make([]*NewVoteActivity, 0)
  58. err := core.GetXormAuto().Where("is_delete=0 and activity_id=?", activityId).
  59. Asc("created_at").Find(&votes)
  60. return votes, err
  61. }