From dd343787c51ad0fe11c53064a5022432c6971aeb Mon Sep 17 00:00:00 2001 From: tommy <3405129587@qq.com> Date: Mon, 25 May 2020 14:59:44 +0800 Subject: [PATCH] vote --- controllers/client/vote.go | 3 +-- controllers/pc/activity.go | 2 +- controllers/pc/vote.go | 24 +++++++++--------------- libs/im/im_test.go | 2 +- models/new_vote_activity.go | 18 ++++++++++-------- models/new_vote_activity_ladder.go | 7 +++++++ test/annex_test.go | 2 +- test/bindata.go | 2 +- 8 files changed, 31 insertions(+), 29 deletions(-) diff --git a/controllers/client/vote.go b/controllers/client/vote.go index 9b984e2..91dd595 100644 --- a/controllers/client/vote.go +++ b/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{}{ diff --git a/controllers/pc/activity.go b/controllers/pc/activity.go index d203cf0..a653309 100644 --- a/controllers/pc/activity.go +++ b/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) // 卡路里->卡路里活动 diff --git a/controllers/pc/vote.go b/controllers/pc/vote.go index 7e2689e..60c8c2a 100644 --- a/controllers/pc/vote.go +++ b/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) } diff --git a/libs/im/im_test.go b/libs/im/im_test.go index 83a0708..ffecfd1 100644 --- a/libs/im/im_test.go +++ b/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) } diff --git a/models/new_vote_activity.go b/models/new_vote_activity.go index 7ea1533..f0e5f6d 100644 --- a/models/new_vote_activity.go +++ b/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 } diff --git a/models/new_vote_activity_ladder.go b/models/new_vote_activity_ladder.go index 7d6936f..63e9c25 100644 --- a/models/new_vote_activity_ladder.go +++ b/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 +} diff --git a/test/annex_test.go b/test/annex_test.go index beb2630..5762702 100644 --- a/test/annex_test.go +++ b/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) diff --git a/test/bindata.go b/test/bindata.go index ba46170..d7b3a75 100644 --- a/test/bindata.go +++ b/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"