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

36 lines
1.7 KiB

5 years ago
5 years ago
  1. package models
  2. import (
  3. "github.com/ouxuanserver/osmanthuswine/src/core"
  4. "time"
  5. )
  6. const VoteActivityLadderTableName = TableNamePrefix + "new_vote_activity_ladder"
  7. type NewVoteActivityLadder struct {
  8. Id int64 `json:"id" xorm:"not null pk autoincr INT(11)"`
  9. VoteActivityId int64 `json:"vote_activity_id" xorm:"not null comment('投票轮次的id') INT(11)"`
  10. VoteNumber int64 `json:"vote_number" xorm:"not null comment('投票的初始的票数') INT(11)"`
  11. VoteMember string `json:"vote_member" xorm:"not null comment('投票的人员名字') VARCHAR(255)"`
  12. MemberImg string `json:"member_img" xorm:"not null comment('被投票人员的图片')"`
  13. TotalNumber int64 `json:"total_number" xorm:"not null default 0 comment('投票总数') INT(11)"`
  14. IsVote bool `json:"is_vote" xorm:"-" description:"是否被投票"`
  15. IsDelete bool `json:"is_delete" xorm:"not null default(0) comment('删除') TINYINT(1)"`
  16. CreatedAt time.Time `json:"created_at" xorm:"not null created comment('创建时间') DATETIME"`
  17. UpdatedAt time.Time `json:"updated_at" xorm:"not null updated comment('更新时间') DATETIME"`
  18. }
  19. func (t *NewVoteActivityLadder) TableName() string {
  20. return VoteActivityLadderTableName
  21. }
  22. func (t *NewVoteActivityLadder) Incr(id, number int64) (int64, error) {
  23. return core.GetXormAuto().Where("is_delete=0 and id=?", id).Incr("total_number", number).Update(t)
  24. }
  25. func GetNewVoteTopByVoteActivityId(voteId interface{}, limit int) ([]*NewVoteActivityLadder, error) {
  26. ladders := make([]*NewVoteActivityLadder, 0)
  27. err := core.GetXormAuto().Where("is_delete=0 and vote_activity_id=?", voteId).
  28. Desc("total_number").Asc("updated_at").Limit(limit).Find(&ladders)
  29. return ladders, err
  30. }