From b0643cb0738346afae0f684f371154089ad9321d Mon Sep 17 00:00:00 2001 From: tommy <3405129587@qq.com> Date: Fri, 29 May 2020 16:09:15 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8A=BD=E5=A5=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controllers/pc/lottery_draw.go | 114 +++++++++++++++++++++++------------ controllers/pc/shake_red_envelope.go | 35 +++++++---- 2 files changed, 97 insertions(+), 52 deletions(-) diff --git a/controllers/pc/lottery_draw.go b/controllers/pc/lottery_draw.go index d0bccf6..58976fd 100644 --- a/controllers/pc/lottery_draw.go +++ b/controllers/pc/lottery_draw.go @@ -27,6 +27,12 @@ func (t *LotteryDrawCtl) Start() { t.CheckErr(err) t.Assert(exist, code.MSG_LOTTERY_RULE_NOT_EXIST, "抽奖规则不存在") + activity := new(models.Activity) + exist, err = models.Get(activity, activityId) + t.CheckErr(err) + t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在") + t.CheckRunning(activity.Status) + if ladder.Status != define.StatusNotBegin { t.ERROR(fmt.Sprintf("该活动%s", ladder.Status), code.MSG_ERR) } @@ -36,12 +42,15 @@ func (t *LotteryDrawCtl) Start() { _, err = models.Update(ladder.Id, ladder, "status", "roll_num", "updated_at") t.CheckErr(err) // 通知直播开始抽奖 - im_service.SendGroupCustomMessage("admin", activityId, im_service.NoticeLotteryDrawStart, - map[string]interface{}{ - "lottery_draw_ladder_id": ladder.Id, - "timestamp": time.Now().Unix(), - "desc": "开始抽奖", - }) + if activity.RehearsalId == 0 { + go im_service.SendGroupCustomMessage("admin", activityId, im_service.NoticeLotteryDrawStart, + map[string]interface{}{ + "lottery_draw_ladder_id": ladder.Id, + "timestamp": time.Now().Unix(), + "desc": "开始抽奖", + }) + } + t.SUCCESS("操作成功") } @@ -51,8 +60,14 @@ func (t *LotteryDrawCtl) StartRoll() { activityId := t.MustGetInt64("activity_id") num := t.MustGetInt64("num") + activity := new(models.Activity) + exist, err := models.Get(activity, activityId) + t.CheckErr(err) + t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在") + t.CheckRunning(activity.Status) + ladder := new(models.LotteryDrawRuleLadder) - exist, err := models.Get(ladder, ladderId) + exist, err = models.Get(ladder, ladderId) t.CheckErr(err) t.Assert(exist, code.MSG_LOTTERY_RULE_NOT_EXIST, "抽奖规则不存在") @@ -63,14 +78,16 @@ func (t *LotteryDrawCtl) StartRoll() { _, err = models.Update(ladder.Id, ladder, "roll_num") // 通知直播开始抽奖 - im_service.SendGroupCustomMessage("admin", activityId, im_service.NoticeLotteryDrawRollStart, - map[string]interface{}{ - "lottery_draw_ladder_id": ladder.Id, - "timestamp": time.Now().Unix(), - "roll_num": ladder.RollNum, - "desc": "开始滚动", - "number": num, - }) + if activity.RehearsalId == 0 { + go im_service.SendGroupCustomMessage("admin", activityId, im_service.NoticeLotteryDrawRollStart, + map[string]interface{}{ + "lottery_draw_ladder_id": ladder.Id, + "timestamp": time.Now().Unix(), + "roll_num": ladder.RollNum, + "desc": "开始滚动", + "number": num, + }) + } t.SUCCESS("操作成功") } @@ -79,8 +96,14 @@ func (t *LotteryDrawCtl) StopRoll() { activityId := t.MustGetInt64("activity_id") num := t.MustGetInt64("num") + activity := new(models.Activity) + exist, err := models.Get(activity, activityId) + t.CheckErr(err) + t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在") + t.CheckRunning(activity.Status) + ladder := new(models.LotteryDrawRuleLadder) - exist, err := models.Get(ladder, ladderId) + exist, err = models.Get(ladder, ladderId) t.CheckErr(err) t.Assert(exist, code.MSG_LOTTERY_RULE_NOT_EXIST, "抽奖规则不存在") @@ -88,14 +111,16 @@ func (t *LotteryDrawCtl) StopRoll() { 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(), - "roll_num": ladder.RollNum, - "desc": "停止滚动", - "number": num, - }) + if activity.RehearsalId == 0 { + go im_service.SendGroupCustomMessage("admin", activityId, im_service.NoticeLotteryDrawRollStop, + map[string]interface{}{ + "lottery_draw_ladder_id": ladder.Id, + "timestamp": time.Now().Unix(), + "roll_num": ladder.RollNum, + "desc": "停止滚动", + "number": num, + }) + } t.SUCCESS("操作成功") } @@ -104,8 +129,14 @@ func (t *LotteryDrawCtl) Stop() { ladderId := t.MustGetInt64("lottery_draw_ladder_id") activityId := t.MustGetInt64("activity_id") + activity := new(models.Activity) + exist, err := models.Get(activity, activityId) + t.CheckErr(err) + t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在") + t.CheckRunning(activity.Status) + ladder := new(models.LotteryDrawRuleLadder) - exist, err := models.Get(ladder, ladderId) + exist, err = models.Get(ladder, ladderId) t.CheckErr(err) t.Assert(exist, code.MSG_LOTTERY_RULE_NOT_EXIST, "抽奖规则不存在") @@ -120,13 +151,14 @@ func (t *LotteryDrawCtl) Stop() { t.CheckErr(err) // 通知直播开始抽奖 - im_service.SendGroupCustomMessage("admin", activityId, im_service.NoticeLotteryDrawStop, - map[string]interface{}{ - "lottery_draw_ladder_id": ladder.Id, - "timestamp": time.Now().Unix(), - "desc": "结束抽奖", - }) - + if activity.RehearsalId == 0 { + go im_service.SendGroupCustomMessage("admin", activityId, im_service.NoticeLotteryDrawStop, + map[string]interface{}{ + "lottery_draw_ladder_id": ladder.Id, + "timestamp": time.Now().Unix(), + "desc": "结束抽奖", + }) + } t.SUCCESS("操作成功") } @@ -310,14 +342,16 @@ func (t *LotteryDrawCtl) Lottery() { } // 通知直播开始抽奖 - im_service.SendGroupCustomMessage("admin", activityId, im_service.NoticeLotteryDrawResult, - map[string]interface{}{ - "lottery_draw_ladder_id": ladder.Id, - "winners": winners, - "roll_num": ladder.RollNum, - "timestamp": time.Now().Unix(), - "desc": "抽奖结果", - }) + if activity.RehearsalId == 0 { + im_service.SendGroupCustomMessage("admin", activityId, im_service.NoticeLotteryDrawResult, + map[string]interface{}{ + "lottery_draw_ladder_id": ladder.Id, + "winners": winners, + "roll_num": ladder.RollNum, + "timestamp": time.Now().Unix(), + "desc": "抽奖结果", + }) + } t.JSON(winners) } diff --git a/controllers/pc/shake_red_envelope.go b/controllers/pc/shake_red_envelope.go index 7543b51..4aaee3d 100644 --- a/controllers/pc/shake_red_envelope.go +++ b/controllers/pc/shake_red_envelope.go @@ -86,12 +86,15 @@ func (t *ShakeRedEnvelopeCtl) Start() { err = red_envelope_service.GenRedEnvelope(activity.Id, activity.Name, activity.RehearsalId, rule) t.CheckErr(err) - go im_service.SendGroupCustomMessage("admin", envelope.ActivityId, im_service.NoticeShakeRedPackStart, - map[string]interface{}{ - "customer_id": uid, - "shake_red_envelope_rule_id": rule.Id, - "timestamp": time.Now().Unix(), - }) + // 彩排不用发送到直播间 + if activity.RehearsalId == 0 { + go im_service.SendGroupCustomMessage("admin", envelope.ActivityId, im_service.NoticeShakeRedPackStart, + map[string]interface{}{ + "customer_id": uid, + "shake_red_envelope_rule_id": rule.Id, + "timestamp": time.Now().Unix(), + }) + } t.SUCCESS("success") } @@ -111,16 +114,24 @@ func (t *ShakeRedEnvelopeCtl) Stop() { t.CheckErr(err) t.Assert(exist, code.MSG_SHAKERB_NOT_EXIST, "摇红包不存在") + activity := new(models.Activity) + exist, err = models.Get(activity, envelope.ActivityId) + t.CheckErr(err) + t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在") + t.CheckRunning(activity.Status) + rule.ShakeRedEnvelopeStatus = define.StatusEnding _, err = rule.UpdateStatus(ruleId, rule.ShakeRedEnvelopeStatus) t.CheckErr(err) - go im_service.SendGroupCustomMessage("admin", envelope.ActivityId, im_service.NoticeShakeRedPackEnd, - map[string]interface{}{ - "customer_id": uid, - "shake_red_envelope_rule_id": rule.Id, - "timestamp": time.Now().Unix(), - }) + if activity.RehearsalId == 0 { + go im_service.SendGroupCustomMessage("admin", envelope.ActivityId, im_service.NoticeShakeRedPackEnd, + map[string]interface{}{ + "customer_id": uid, + "shake_red_envelope_rule_id": rule.Id, + "timestamp": time.Now().Unix(), + }) + } t.SUCCESS("success") }