Browse Source

vote

master
黄梓健 5 years ago
parent
commit
dd343787c5
  1. 3
      controllers/client/vote.go
  2. 2
      controllers/pc/activity.go
  3. 24
      controllers/pc/vote.go
  4. 2
      libs/im/im_test.go
  5. 18
      models/new_vote_activity.go
  6. 7
      models/new_vote_activity_ladder.go
  7. 2
      test/annex_test.go
  8. 2
      test/bindata.go

3
controllers/client/vote.go

@ -82,8 +82,7 @@ func (t *VoteCtl) List() {
t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
t.CheckRunning(activity.Status)
votes := make([]*models.NewVoteActivity, 0)
err = models.GetVoteListByActivityId(votes, activity.Id)
votes, err := models.GetVoteListByActivityId(activity.Id)
t.CheckErr(err)
t.JSON(map[string]interface{}{

2
controllers/pc/activity.go

@ -101,7 +101,7 @@ func (t *ActivityCtl) StopActivity() {
t.CheckErr(err)
// 投票->投票活动
_, err = models.UpdateVoteStatusByActiviytId(activityId)
_, err = models.UpdateVoteStatusByActivityId(activityId)
t.CheckErr(err)
// 卡路里->卡路里活动

24
controllers/pc/vote.go

@ -2,6 +2,7 @@ package pc
import (
"fmt"
"github.com/ouxuanserver/osmanthuswine/src/core"
"hudongzhuanjia/controllers"
"hudongzhuanjia/models"
"hudongzhuanjia/utils"
@ -9,8 +10,6 @@ import (
"hudongzhuanjia/utils/define"
"strconv"
"time"
"github.com/ouxuanserver/osmanthuswine/src/core"
)
type VoteCtl struct {
@ -133,42 +132,37 @@ func (t *VoteCtl) JoinTotal() {
func (t *VoteCtl) List() {
activityId := t.MustGetInt64("activity_id")
list := make([]*models.NewVoteActivity, 0)
total, err := core.GetXormAuto().Where("is_delete=0 and activity_id=?", activityId).
Asc("created_at").FindAndCount(&list)
votes, err := models.GetVoteListByActivityId(activityId)
t.CheckErr(err)
ids := make([]int64, 0)
for _, v := range list {
for _, v := range votes {
ids = append(ids, v.Id)
}
ladders := make([]*models.NewVoteActivityLadder, 0)
err = core.GetXormAuto().Where("is_delete=0").In("vote_activity_id", ids).Find(&ladders)
t.CheckErr(err)
for index := range list {
for index := range votes {
for i := range ladders {
if list[index].Id == ladders[i].VoteActivityId {
list[index].VoteActivityLadders = append(list[index].VoteActivityLadders, ladders[i])
if votes[index].Id == ladders[i].VoteActivityId {
votes[index].VoteActivityLadders = append(votes[index].VoteActivityLadders, ladders[i])
}
}
}
t.JSON(map[string]interface{}{
"total": total,
"list": list,
"total": len(votes),
"list": votes,
})
}
//获取投票的前几(头像、姓名、票数)
func (t *VoteCtl) History() {
voteActivityId := t.MustGetInt64("vote_activity_id")
//rehearsalId := t.MustGetInt64("rehearsal_id")
total := t.MustGetInt("total")
ladders := make([]*models.NewVoteActivityLadder, 0)
err := core.GetXormAuto().Where("is_delete=0 and vote_activity_id=?", voteActivityId).
Desc("total_number").Asc("updated_at").Limit(total).Find(&ladders)
ladders, err := models.GetNewVoteTopByVoteActivityId(voteActivityId, total)
t.CheckErr(err)
t.JSON(ladders)
}

2
libs/im/im_test.go

@ -11,7 +11,7 @@ func TestAccountImport(t *testing.T) {
}
func TestSendGroupSystemNotification(t *testing.T) {
err := SendGroupSystemNotification("@TGS#aZWTFELGU", 256, "你好吗")
err := SendGroupSystemNotification("@TGS#aZWTFELGU", 256, nil)
fmt.Println(err)
}

18
models/new_vote_activity.go

@ -34,10 +34,10 @@ func (t *NewVoteActivity) TableName() string {
return NewVoteActivityTableName
}
func (t *NewVoteActivity) GetByActivityId(aid int64, status string) (bool, error) {
return core.GetXormAuto().Where("is_delete=0 and activity_id=? and vote_status=?", aid, status).
Desc("created_at").Get(t)
}
//func (t *NewVoteActivity) GetByActivityId(aid int64, status string) (bool, error) {
// return core.GetXormAuto().Where("is_delete=0 and activity_id=? and vote_status=?", aid, status).
// Desc("created_at").Get(t)
//}
func (t *NewVoteActivity) UpdateToStatusByAid(aid int64, before string, after string) (int64, error) {
t.VoteStatus = after
@ -58,12 +58,14 @@ func (t *NewVoteActivity) GetCurrent(aid int64) (bool, error) {
aid, define.StatusReady, define.StatusRunning).Desc("created_at").Get(t)
}
func UpdateVoteStatusByActiviytId(aid int64) (int64, error) {
func UpdateVoteStatusByActivityId(aid int64) (int64, error) {
return core.GetXormAuto().Where("is_delete=0 and activity_id=?", aid).
Update(&NewVoteActivity{VoteStatus: define.StatusNotBegin})
}
func GetVoteListByActivityId(obj, activityId interface{}) error {
return core.GetXormAuto().Where("is_delete=0 and activity_id=?", activityId).
Desc("created_at").Find(&obj)
func GetVoteListByActivityId(activityId interface{}) ([]*NewVoteActivity, error) {
votes := make([]*NewVoteActivity, 0)
err := core.GetXormAuto().Where("is_delete=0 and activity_id=?", activityId).
Asc("created_at").Find(&votes)
return votes, err
}

7
models/new_vote_activity_ladder.go

@ -27,3 +27,10 @@ func (t *NewVoteActivityLadder) TableName() string {
func (t *NewVoteActivityLadder) Incr(id, number int64) (int64, error) {
return core.GetXormAuto().Where("is_delete=0 and id=?", id).Incr("total_number", number).Update(t)
}
func GetNewVoteTopByVoteActivityId(voteId interface{}, limit int) ([]*NewVoteActivityLadder, error) {
ladders := make([]*NewVoteActivityLadder, 0)
err := core.GetXormAuto().Where("is_delete=0 and vote_activity_id=?", voteId).
Desc("total_number").Asc("updated_at").Limit(limit).Find(&ladders)
return ladders, err
}

2
test/annex_test.go

@ -32,7 +32,7 @@ func TestAnnexUpload(t *testing.T) {
t.Fatal(err)
}
fmt.Println("上传成功,路径:", fmt.Sprintf("%s/%s", u.String(), picName))
objs := []cos.Object{cos.Object{Key: picName}}
objs := []cos.Object{{Key: picName}}
odmo := new(cos.ObjectDeleteMultiOptions)
odmo.Objects = objs
odmr, _, err := client.Object.DeleteMulti(context.Background(), odmo)

2
test/bindata.go

@ -4,7 +4,7 @@
// cacert/apiclient_cert.pem
// cacert/apiclient_key.pem
// cacert/rootca.pem
package pay_service
package test
import (
"bytes"

Loading…
Cancel
Save