Browse Source

适配功能

master
黄梓健 5 years ago
parent
commit
43ddcab0af
  1. 121
      controllers/common/im.go
  2. 17
      controllers/common/wechat_oauth.go
  3. 97
      controllers/pc/lottery_draw.go
  4. 34
      controllers/pc/shake_red_envelope.go
  5. 5
      models/live_config.go
  6. 14
      services/pay/handle.go

121
controllers/common/im.go

@ -2,129 +2,8 @@ package common
import ( import (
"hudongzhuanjia/controllers" "hudongzhuanjia/controllers"
"hudongzhuanjia/logger"
"hudongzhuanjia/models"
im_service "hudongzhuanjia/services/im"
"time"
) )
type ImTestCtl struct { type ImTestCtl struct {
controllers.BaseCtl 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("发送成功")
}

17
controllers/common/wechat_oauth.go

@ -118,20 +118,3 @@ func (t *WeChatOauthCtl) CallbackRefund() {
logger.Error(fmt.Sprintf("微信响应次数: %v", counter.Load())) logger.Error(fmt.Sprintf("微信响应次数: %v", counter.Load()))
t.XML(xmlRes) 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,
// })
//}

97
controllers/pc/lottery_draw.go

@ -43,12 +43,17 @@ func (t *LotteryDrawCtl) Start() {
t.CheckErr(err) t.CheckErr(err)
// 通知直播开始抽奖 // 通知直播开始抽奖
if activity.RehearsalId == 0 { 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("操作成功") t.SUCCESS("操作成功")
@ -79,14 +84,19 @@ func (t *LotteryDrawCtl) StartRoll() {
// 通知直播开始抽奖 // 通知直播开始抽奖
if activity.RehearsalId == 0 { 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("操作成功") t.SUCCESS("操作成功")
} }
@ -112,14 +122,19 @@ func (t *LotteryDrawCtl) StopRoll() {
} }
// 通知直播开始抽奖 // 通知直播开始抽奖
if activity.RehearsalId == 0 { 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("操作成功") t.SUCCESS("操作成功")
} }
@ -152,12 +167,17 @@ func (t *LotteryDrawCtl) Stop() {
// 通知直播开始抽奖 // 通知直播开始抽奖
if activity.RehearsalId == 0 { 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("操作成功") t.SUCCESS("操作成功")
} }
@ -343,14 +363,19 @@ func (t *LotteryDrawCtl) Lottery() {
// 通知直播开始抽奖 // 通知直播开始抽奖
if activity.RehearsalId == 0 { 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) t.JSON(winners)

34
controllers/pc/shake_red_envelope.go

@ -88,12 +88,17 @@ func (t *ShakeRedEnvelopeCtl) Start() {
// 彩排不用发送到直播间 // 彩排不用发送到直播间
if activity.RehearsalId == 0 { 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") t.SUCCESS("success")
@ -125,12 +130,17 @@ func (t *ShakeRedEnvelopeCtl) Stop() {
t.CheckErr(err) t.CheckErr(err)
if activity.RehearsalId == 0 { 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") t.SUCCESS("success")

5
models/live_config.go

@ -55,3 +55,8 @@ func (t *LiveConfig) GetByActivityId(aid interface{}) (bool, error) {
func (t *LiveConfig) Like(aid interface{}) (int64, 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) 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
}

14
services/pay/handle.go

@ -110,7 +110,7 @@ func HandleSuccess(order *models.UserOrder) error {
return err return err
} }
for _, sub := range subs { 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{}{ map[string]interface{}{
"goods_pic_url": sub["goods_pic_url"], "goods_pic_url": sub["goods_pic_url"],
"goods_num": sub["goods_num"], "goods_num": sub["goods_num"],
@ -119,10 +119,6 @@ func HandleSuccess(order *models.UserOrder) error {
"goods_id": sub["goods_id"], "goods_id": sub["goods_id"],
"timestamp": time.Now().Unix(), "timestamp": time.Now().Unix(),
}) })
if err != nil {
logger.Error("直播商品子订单信息发送异常异常", err)
return err
}
} }
activity := new(models.Activity) activity := new(models.Activity)
@ -198,18 +194,12 @@ func HandleSuccess(order *models.UserOrder) error {
return err 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{}{ map[string]interface{}{
"live_red_envelope_rule_id": info.Id, "live_red_envelope_rule_id": info.Id,
"prompt": info.Prompt, "prompt": info.Prompt,
"timestamp": time.Now().Unix(), "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 { // 打赏 } else if order.GoodType == 2 { // 打赏
history := new(models.RewardHistory) history := new(models.RewardHistory)
exist, err := history.GetByOutTradeNo(order.OutTradeNo) exist, err := history.GetByOutTradeNo(order.OutTradeNo)

Loading…
Cancel
Save