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

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