From 422f051617e92915bb920c09c80f9ba423ded37d Mon Sep 17 00:00:00 2001 From: tommy <3405129587@qq.com> Date: Thu, 14 May 2020 17:55:13 +0800 Subject: [PATCH] =?UTF-8?q?=E5=89=94=E9=99=A4=E5=90=8C=E8=BD=AE=E6=AC=A1?= =?UTF-8?q?=E7=9A=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controllers/common/im.go | 64 ++++++++++++++++++++++++++++++++++++++++++ controllers/pc/lottery_draw.go | 61 ++++++++++++++++++++++++++++++++++++++-- services/im/im.go | 2 ++ 3 files changed, 125 insertions(+), 2 deletions(-) diff --git a/controllers/common/im.go b/controllers/common/im.go index 351adf7..d72261d 100644 --- a/controllers/common/im.go +++ b/controllers/common/im.go @@ -34,3 +34,67 @@ func (t *ImTestCtl) SendRedPack() { }) t.SUCCESS("发送成功") } + +type LotteryUser struct { + UserId int64 + Username string + UserPhone string + Avatar string + PrizeName string + LadderId int64 + PrizeImg string +} + +func (t *ImTestCtl) SendLottery() { + activityId := t.MustGetInt64("activity_id") + ladderId := t.MustGetInt64("lottery_draw_ladder_id") + desc := t.MustGet("desc") + notice := t.MustGetInt("notice") + if notice == 264 { + winners := make([]*LotteryUser, 0) + winners = append(winners, &LotteryUser{ + UserId: 1, + Username: "哗啦啦@黄梓健", + UserPhone: "18814098671", + Avatar: "http://thirdwx.qlogo.cn/mmopen/vi_32/U8krFYdib9PITkDicbaNPnJHKpUMJ8unribzyPcUKWKGyJovoKmES6UHW1Zl6bVsUUtmFjyzsUTrajAJ53icZpEcgw/132", + PrizeName: "白金王座", + LadderId: ladderId, + PrizeImg: "http://thirdwx.qlogo.cn/mmopen/vi_32/U8krFYdib9PITkDicbaNPnJHKpUMJ8unribzyPcUKWKGyJovoKmES6UHW1Zl6bVsUUtmFjyzsUTrajAJ53icZpEcgw/132", + }) + winners = append(winners, &LotteryUser{ + UserId: 3, + Username: "明月清风", + UserPhone: "18814098673", + Avatar: "http://thirdwx.qlogo.cn/mmopen/vi_32/ZbibUK9Ywia2TtmQCxlyQPrxqKKzed1q4IWA5EUhMEgDiaKOnDODVrAvtKGE9qpFFZYoYfdsZrm63HKMKMA7on38A/132", + PrizeName: "白银王座", + LadderId: ladderId, + PrizeImg: "http://thirdwx.qlogo.cn/mmopen/vi_32/U8krFYdib9PITkDicbaNPnJHKpUMJ8unribzyPcUKWKGyJovoKmES6UHW1Zl6bVsUUtmFjyzsUTrajAJ53icZpEcgw/132", + }) + winners = append(winners, &LotteryUser{ + UserId: 4, + Username: "Liujw", + UserPhone: "18814098672", + Avatar: "http://thirdwx.qlogo.cn/mmopen/vi_32/ajNVdqHZLLCO4qnL4BtyfjDQHhYmU8MgUZK11cABc8KFY7oenQYNErtm0n2ibfFB4QkFXfT3tVNMGqibDb3Oib30Q/132", + PrizeName: "青铜王座", + LadderId: ladderId, + PrizeImg: "http://thirdwx.qlogo.cn/mmopen/vi_32/ajNVdqHZLLCO4qnL4BtyfjDQHhYmU8MgUZK11cABc8KFY7oenQYNErtm0n2ibfFB4QkFXfT3tVNMGqibDb3Oib30Q/132", + }) + im_service.SendGroupCustomMessage("admin", activityId, im_service.NoticeStatus(notice), + map[string]interface{}{ + "lottery_draw_ladder_id": ladderId, + "winners": winners, + "timestamp": time.Now().Unix(), + "desc": desc, + }) + + } else { + im_service.SendGroupCustomMessage("admin", activityId, im_service.NoticeStatus(notice), + map[string]interface{}{ + "lottery_draw_ladder_id": ladderId, + "timestamp": time.Now().Unix(), + "desc": desc, + }) + } + + t.SUCCESS("恭喜这B") +} diff --git a/controllers/pc/lottery_draw.go b/controllers/pc/lottery_draw.go index 8e4cda0..2dc069b 100644 --- a/controllers/pc/lottery_draw.go +++ b/controllers/pc/lottery_draw.go @@ -43,6 +43,52 @@ func (t *LotteryDrawCtl) Start() { map[string]interface{}{ "lottery_draw_ladder_id": ladder.Id, "timestamp": time.Now().Unix(), + "desc": "开始抽奖", + }) + t.SUCCESS("操作成功") +} + +// 滚动 +func (t *LotteryDrawCtl) StartRoll() { + ladderId := t.MustGetInt64("lottery_draw_ladder_id") + activityId := t.MustGetInt64("activity_id") + + ladder := new(models.LotteryDrawRuleLadder) + exist, err := models.GetById(ladder, ladderId) + t.CheckErr(err) + t.Assert(exist, code.MSG_LOTTERY_RULE_NOT_EXIST, "抽奖规则不存在") + + if ladder.Status != define.StatusRunning { + t.ERROR(fmt.Sprintf("该活动%s", ladder.Status), code.MSG_ERR) + } + // 通知直播开始抽奖 + im_service.SendGroupCustomMessage("admin", activityId, im_service.NoticeLotteryDrawRollStart, + map[string]interface{}{ + "lottery_draw_ladder_id": ladder.Id, + "timestamp": time.Now().Unix(), + "desc": "开始滚动", + }) + t.SUCCESS("操作成功") +} + +func (t *LotteryDrawCtl) StopRoll() { + ladderId := t.MustGetInt64("lottery_draw_ladder_id") + activityId := t.MustGetInt64("activity_id") + + ladder := new(models.LotteryDrawRuleLadder) + exist, err := models.GetById(ladder, ladderId) + t.CheckErr(err) + t.Assert(exist, code.MSG_LOTTERY_RULE_NOT_EXIST, "抽奖规则不存在") + + if ladder.Status != define.StatusRunning { + t.ERROR(fmt.Sprintf("该活动%s", ladder.Status), code.MSG_ERR) + } + // 通知直播开始抽奖 + im_service.SendGroupCustomMessage("admin", activityId, im_service.NoticeLotteryDrawRollStop, + map[string]interface{}{ + "lottery_draw_ladder_id": ladder.Id, + "timestamp": time.Now().Unix(), + "desc": "停止滚动", }) t.SUCCESS("操作成功") } @@ -72,6 +118,7 @@ func (t *LotteryDrawCtl) Stop() { map[string]interface{}{ "lottery_draw_ladder_id": ladder.Id, "timestamp": time.Now().Unix(), + "desc": "结束抽奖", }) t.SUCCESS("操作成功") @@ -329,9 +376,18 @@ func (t *LotteryDrawCtl) Lottery() { NotIn("user_id", recordIds).Find(&lotteryUsers) t.CheckErr(err) } else { + // 同轮次剔除中奖用户 + // 去除同规则中将用户 + recordIds := make([]int64, 0) + err = core.GetXormAuto().Table(new(models.LotteryDrawRecord)).Select("user_id"). + Where("lottery_draw_rule_ladder_id=? and rehearsal_id=? and area_id=? and is_delete=0", + ladderId, activity.RehearsalId, area.Id).Find(&recordIds) + t.CheckErr(err) + err = core.GetXormAuto().Table(new(models.SignHistory)).Select("user_id"). Where("is_delete=0 and rehearsal_id=? and area_id=?", - activity.RehearsalId, area.Id).In("sign_rule_id", signUpIds).Find(&lotteryUsers) + activity.RehearsalId, area.Id).In("sign_rule_id", signUpIds). + NotIn("user_id", recordIds).Find(&lotteryUsers) t.CheckErr(err) } if len(lotteryUsers) < number { @@ -397,9 +453,10 @@ func (t *LotteryDrawCtl) Lottery() { // 通知直播开始抽奖 im_service.SendGroupCustomMessage("admin", activityId, im_service.NoticeLotteryDrawResult, map[string]interface{}{ - "winners": winners, "lottery_draw_ladder_id": ladder.Id, + "winners": winners, "timestamp": time.Now().Unix(), + "desc": "抽奖结果", }) t.RAW(winners) diff --git a/services/im/im.go b/services/im/im.go index c369e7d..4e37dd0 100644 --- a/services/im/im.go +++ b/services/im/im.go @@ -22,6 +22,8 @@ const NoticeReward NoticeStatus = 261 // 打赏 const NoticeLotteryDrawStart = 262 // 抽奖开始 const NoticeLotteryDrawStop = 263 // 抽奖结束 const NoticeLotteryDrawResult = 264 // 抽奖结果 +const NoticeLotteryDrawRollStart = 265 // 开始滚动 +const NoticeLotteryDrawRollStop = 266 // 停止滚动 func SendNoticeByActivityId(activityId int64, _type NoticeStatus, data map[string]interface{}, members ...string) error { live := new(models.LiveConfig)