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

76 lines
2.1 KiB

5 years ago
  1. package vote_service
  2. import (
  3. "errors"
  4. "hudongzhuanjia/models"
  5. )
  6. func GetCurrentVote(aid, uid, rid int64) (map[string]interface{}, error) {
  7. vote := new(models.NewVoteActivity)
  8. exist, err := vote.GetCurrent(aid)
  9. if err != nil {
  10. return nil, err
  11. }
  12. if !exist {
  13. return nil, errors.New("轮次尚未开启")
  14. }
  15. return map[string]interface{}{
  16. "vote": vote,
  17. }, nil
  18. }
  19. //type VoteRankResult struct {
  20. // TotalNumber int64 `json:"total_number"`
  21. // Id int64 `json:"id"`
  22. // VoteActivityId int64 `json:"vote_activity_id" description:"投票轮次的id"`
  23. // VoteNumber int64 `json:"vote_number" description:"投票的初始票数"`
  24. // VoteMember string `json:"vote_member" description:"被投票的人员名字"`
  25. // MemberImg string `json:"member_img" description:"被投票的人员图片"`
  26. // IsVoted bool `json:"is_vote" description:"是否已經被投票"`
  27. //}
  28. //type VoteRankResults []*VoteRankResult
  29. //
  30. //func RankVote(vid, uid, rid int64) ([]*VoteRankResult, error) {
  31. // result := make([]*models.NewVoteActivityLadder, 0)
  32. // err := core.GetXormAuto().Where("vote_activity_id=? and is_delete=0", vid).
  33. // Desc("total_number").Desc("updated_at").Find(&result)
  34. // if err != nil {
  35. // return nil, err
  36. // }
  37. // ladderIds := make([]int64, 0)
  38. // for index, item := range result {
  39. // result[index].TotalNumber += result[index].VoteNumber
  40. // ladderIds = append(ladderIds, item.Id)
  41. // }
  42. // sort.Sort(result)
  43. //
  44. // histories := make([]*models.NewVoteActivityHistory, 0)
  45. // err = core.GetXormAuto().Where("is_delete=0 and user_id=? and rehearsal_id=?", uid, rid).
  46. // In("vote_activity_ladder_id", ladderIds).Find(&histories)
  47. // if err != nil {
  48. // return nil, err
  49. // }
  50. // for i := range result {
  51. // for j := range histories {
  52. // if result[i].Id == histories[j].VoteActivityLadderId {
  53. // result[i].IsVoted = true
  54. // break
  55. // }
  56. // }
  57. // }
  58. //
  59. // return result, nil
  60. //}
  61. //func (s VoteRankResults) Len() int {
  62. // return len(s)
  63. //}
  64. //
  65. //func (s VoteRankResults) Less(i, j int) bool {
  66. // if s[i].TotalNumber > s[j].TotalNumber {
  67. // return true
  68. // }
  69. // return false
  70. //}
  71. //func (s VoteRankResults) Swap(i, j int) {
  72. // s[i], s[j] = s[j], s[i]
  73. //}