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

package vote_service
import (
"errors"
"hudongzhuanjia/models"
)
func GetCurrentVote(aid, uid, rid int64) (map[string]interface{}, error) {
vote := new(models.NewVoteActivity)
exist, err := vote.GetCurrent(aid)
if err != nil {
return nil, err
}
if !exist {
return nil, errors.New("轮次尚未开启")
}
return map[string]interface{}{
"vote": vote,
}, nil
}
//type VoteRankResult struct {
// TotalNumber int64 `json:"total_number"`
// Id int64 `json:"id"`
// VoteActivityId int64 `json:"vote_activity_id" description:"投票轮次的id"`
// VoteNumber int64 `json:"vote_number" description:"投票的初始票数"`
// VoteMember string `json:"vote_member" description:"被投票的人员名字"`
// MemberImg string `json:"member_img" description:"被投票的人员图片"`
// IsVoted bool `json:"is_vote" description:"是否已經被投票"`
//}
//type VoteRankResults []*VoteRankResult
//
//func RankVote(vid, uid, rid int64) ([]*VoteRankResult, error) {
// result := make([]*models.NewVoteActivityLadder, 0)
// err := core.GetXormAuto().Where("vote_activity_id=? and is_delete=0", vid).
// Desc("total_number").Desc("updated_at").Find(&result)
// if err != nil {
// return nil, err
// }
// ladderIds := make([]int64, 0)
// for index, item := range result {
// result[index].TotalNumber += result[index].VoteNumber
// ladderIds = append(ladderIds, item.Id)
// }
// sort.Sort(result)
//
// histories := make([]*models.NewVoteActivityHistory, 0)
// err = core.GetXormAuto().Where("is_delete=0 and user_id=? and rehearsal_id=?", uid, rid).
// In("vote_activity_ladder_id", ladderIds).Find(&histories)
// if err != nil {
// return nil, err
// }
// for i := range result {
// for j := range histories {
// if result[i].Id == histories[j].VoteActivityLadderId {
// result[i].IsVoted = true
// break
// }
// }
// }
//
// return result, nil
//}
//func (s VoteRankResults) Len() int {
// return len(s)
//}
//
//func (s VoteRankResults) Less(i, j int) bool {
// if s[i].TotalNumber > s[j].TotalNumber {
// return true
// }
// return false
//}
//func (s VoteRankResults) Swap(i, j int) {
// s[i], s[j] = s[j], s[i]
//}