From 43ddcab0af3daba0113d50c4e2d8373c220f4d3d Mon Sep 17 00:00:00 2001 From: tommy <3405129587@qq.com> Date: Fri, 29 May 2020 16:35:00 +0800 Subject: [PATCH] =?UTF-8?q?=E9=80=82=E9=85=8D=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controllers/common/im.go | 121 ----------------------------------- controllers/common/wechat_oauth.go | 17 ----- controllers/pc/lottery_draw.go | 97 +++++++++++++++++----------- controllers/pc/shake_red_envelope.go | 34 ++++++---- models/live_config.go | 5 ++ services/pay/handle.go | 14 +--- 6 files changed, 90 insertions(+), 198 deletions(-) diff --git a/controllers/common/im.go b/controllers/common/im.go index 532dc4c..7ef5626 100644 --- a/controllers/common/im.go +++ b/controllers/common/im.go @@ -2,129 +2,8 @@ package common import ( "hudongzhuanjia/controllers" - "hudongzhuanjia/logger" - "hudongzhuanjia/models" - im_service "hudongzhuanjia/services/im" - "time" ) type ImTestCtl struct { controllers.BaseCtl } - -func (t *ImTestCtl) SendNotice() { - activityId := t.MustGetInt64("activity_id") - status := t.MustGetInt("status") - - im_service.SendGroupCustomMessage(1, activityId, im_service.NoticeStatus(status), map[string]interface{}{ - "customer_id": 16, - "shake_red_envelope_rule_id": 5, - "timestamp": time.Now().Unix(), - }) - t.SUCCESS("发送成功") -} - -func (t *ImTestCtl) SendRedPack() { - activityId := t.MustGetInt64("activity_id") - prompt := t.MustGet("prompt") - - im_service.SendGroupCustomMessage(1, activityId, im_service.NoticeLiveRedPackStart, - map[string]interface{}{ - "live_red_envelope_rule_id": 1, - "prompt": prompt, - "timestamp": time.Now().Unix(), - }) - 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 { - num := t.MustGetInt("num") - im_service.SendGroupCustomMessage("admin", activityId, im_service.NoticeStatus(notice), - map[string]interface{}{ - "lottery_draw_ladder_id": ladderId, - "timestamp": time.Now().Unix(), - "desc": desc, - "number": num, - }) - } - - t.SUCCESS("恭喜这B") -} - -func (t *ImTestCtl) SendGood() { - userId := t.MustGetInt64("user_id") - orderNo := t.MustGet("order_no") - activityId := t.MustGetInt64("activity_id") - - subs, err := models.GetCustomerOrderSubsByOrderNos(orderNo) - if err != nil { - logger.Error("商品子订单查询异常", err) - } - for _, sub := range subs { - err = im_service.SendGroupCustomMessage(userId, activityId, im_service.NoticeLiveGoodBuy, - map[string]interface{}{ - "goods_pic_url": sub["goods_pic_url"], - "goods_num": sub["goods_num"], - "good_name": sub["good_name"], - "good_price": sub["good_price"], - "goods_id": sub["goods_id"], - "timestamp": time.Now().Unix(), - }) - if err != nil { - logger.Error("直播商品子订单信息发送异常异常", err) - } - } - t.SUCCESS("发送成功") -} diff --git a/controllers/common/wechat_oauth.go b/controllers/common/wechat_oauth.go index 4603cfd..2a35c8c 100644 --- a/controllers/common/wechat_oauth.go +++ b/controllers/common/wechat_oauth.go @@ -118,20 +118,3 @@ func (t *WeChatOauthCtl) CallbackRefund() { logger.Error(fmt.Sprintf("微信响应次数: %v", counter.Load())) t.XML(xmlRes) } - -// -//func (t *WeChatOauthCtl) SendRedPack() { -// user := new(models.User) -// exist, err := models.GetById(user, 234) -// t.CheckErr(err) -// if !exist { -// t.ERROR(fmt.Sprintf("error occur: %s", err), 120) -// } -// res, err := pay_service.SendRedPack("欧轩互动", user.Openid, "测试", "123.207.246.51", -// "测试", "测试", 100, 1, 1, user.Id, 1) -// t.CheckErr(err) -// fmt.Printf("%+v", res) -// t.JSON(map[string]interface{}{ -// "result": res, -// }) -//} diff --git a/controllers/pc/lottery_draw.go b/controllers/pc/lottery_draw.go index 58976fd..11c5d50 100644 --- a/controllers/pc/lottery_draw.go +++ b/controllers/pc/lottery_draw.go @@ -43,12 +43,17 @@ func (t *LotteryDrawCtl) Start() { t.CheckErr(err) // 通知直播开始抽奖 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": "开始抽奖", - }) + live := new(models.LiveConfig) + exist, err := live.GetByActivityId(activity.Id) + t.CheckErr(err) + if exist && live.HaveModule(define.MODULE_LOTTERY) { + 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("操作成功") @@ -79,14 +84,19 @@ func (t *LotteryDrawCtl) StartRoll() { // 通知直播开始抽奖 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, - }) + live := new(models.LiveConfig) + exist, err := live.GetByActivityId(activity.Id) + t.CheckErr(err) + if exist && live.HaveModule(define.MODULE_LOTTERY) { + 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("操作成功") } @@ -112,14 +122,19 @@ func (t *LotteryDrawCtl) StopRoll() { } // 通知直播开始抽奖 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, - }) + live := new(models.LiveConfig) + exist, err := live.GetByActivityId(activity.Id) + t.CheckErr(err) + if exist && live.HaveModule(define.MODULE_LOTTERY) { + 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("操作成功") } @@ -152,12 +167,17 @@ func (t *LotteryDrawCtl) Stop() { // 通知直播开始抽奖 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": "结束抽奖", - }) + live := new(models.LiveConfig) + exist, err := live.GetByActivityId(activity.Id) + t.CheckErr(err) + if exist && live.HaveModule(define.MODULE_LOTTERY) { + 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("操作成功") } @@ -343,14 +363,19 @@ func (t *LotteryDrawCtl) Lottery() { // 通知直播开始抽奖 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": "抽奖结果", - }) + live := new(models.LiveConfig) + exist, err := live.GetByActivityId(activity.Id) + t.CheckErr(err) + if exist && live.HaveModule(define.MODULE_LOTTERY) { + go 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 4aaee3d..1a2feff 100644 --- a/controllers/pc/shake_red_envelope.go +++ b/controllers/pc/shake_red_envelope.go @@ -88,12 +88,17 @@ func (t *ShakeRedEnvelopeCtl) Start() { // 彩排不用发送到直播间 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(), - }) + live := new(models.LiveConfig) + exist, err := live.GetByActivityId(activity.Id) + t.CheckErr(err) + if exist && live.HaveModule(define.MODULE_SHAKRB) { + 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") @@ -125,12 +130,17 @@ func (t *ShakeRedEnvelopeCtl) Stop() { t.CheckErr(err) 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(), - }) + live := new(models.LiveConfig) + exist, err := live.GetByActivityId(activity.Id) + t.CheckErr(err) + if exist && live.HaveModule(define.MODULE_SHAKRB) { + 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") diff --git a/models/live_config.go b/models/live_config.go index b382e4c..7ac18f9 100644 --- a/models/live_config.go +++ b/models/live_config.go @@ -55,3 +55,8 @@ func (t *LiveConfig) GetByActivityId(aid interface{}) (bool, error) { func (t *LiveConfig) Like(aid interface{}) (int64, error) { return core.GetXormAuto().Where("is_delete=0 and activity_id=?", aid).Incr("like_num").Update(t) } + +func (t *LiveConfig) HaveModule(module string) bool { + exist, _ := core.GetXormAuto().Where("is_delete=0 name=?", module).In("id", t.AdaptationFunc).Exist(&ModuleService{}) + return exist +} diff --git a/services/pay/handle.go b/services/pay/handle.go index e0ce743..6bfefc3 100644 --- a/services/pay/handle.go +++ b/services/pay/handle.go @@ -110,7 +110,7 @@ func HandleSuccess(order *models.UserOrder) error { return err } for _, sub := range subs { - err = im_service.SendGroupCustomMessage(customerOrder.BuyerId, order.ActivityId, im_service.NoticeLiveGoodBuy, + go im_service.SendGroupCustomMessage(customerOrder.BuyerId, order.ActivityId, im_service.NoticeLiveGoodBuy, map[string]interface{}{ "goods_pic_url": sub["goods_pic_url"], "goods_num": sub["goods_num"], @@ -119,10 +119,6 @@ func HandleSuccess(order *models.UserOrder) error { "goods_id": sub["goods_id"], "timestamp": time.Now().Unix(), }) - if err != nil { - logger.Error("直播商品子订单信息发送异常异常", err) - return err - } } activity := new(models.Activity) @@ -198,18 +194,12 @@ func HandleSuccess(order *models.UserOrder) error { return err } - err = im_service.SendGroupCustomMessage(info.UserId, order.ActivityId, im_service.NoticeLiveRedPackStart, + go im_service.SendGroupCustomMessage(info.UserId, order.ActivityId, im_service.NoticeLiveRedPackStart, map[string]interface{}{ "live_red_envelope_rule_id": info.Id, "prompt": info.Prompt, "timestamp": time.Now().Unix(), }) - if err != nil { - err = fmt.Errorf("发送腾讯im信息出现错误: err->%v, info_id->%v, out_trade_no->%v", - err, info.Id, order.OutTradeNo) - logger.Error(err.Error()) - return err - } } else if order.GoodType == 2 { // 打赏 history := new(models.RewardHistory) exist, err := history.GetByOutTradeNo(order.OutTradeNo)