diff --git a/controllers/client/live.go b/controllers/client/live.go index 5bc8542..701835b 100644 --- a/controllers/client/live.go +++ b/controllers/client/live.go @@ -1,6 +1,7 @@ package client import ( + "fmt" "hudongzhuanjia/controllers" "hudongzhuanjia/libs/filter" "hudongzhuanjia/libs/im" @@ -119,8 +120,9 @@ func (t *LiveCtl) SendLiveRedPack() { t.CheckErr(err) t.Assert(exist, code.MSG_USER_NOT_EXIST, "用户不存在") - var res map[string]interface{} - if activity.RehearsalId != 0 { + var res = make(map[string]interface{}, 0) + res["out_trade_no"] = "" + if activity.RehearsalId == 0 { res, err = pay_service.UnifiedOrder("欧轩互动-直播红包", user.Openid, int64(amount*100), 3, activityId, userId) t.CheckErr(err) } @@ -145,7 +147,7 @@ func (t *LiveCtl) SendLiveRedPack() { t.CheckErr(err) if activity.RehearsalId != 0 { // 彩排不过钱 - err = im_service.SendGroupCustomMessage(activityId, im.NoticeLiveRedPackStart, + err = im_service.SendGroupCustomMessage(fmt.Sprint(user.Id), activityId, im.NoticeLiveRedPackStart, map[string]interface{}{ "live_red_envelope_rule_id": rule.Id, "prompt": rule.Prompt, @@ -179,7 +181,7 @@ func (t *LiveCtl) SendLiveRedPack() { // 领取红包 func (t *LiveCtl) GetLiveRedPack() { - ruleId := t.MustGetInt64("live_red_pack_rule_id") + ruleId := t.MustGetInt64("live_red_envelope_rule_id") userId := t.MustGetUID() rule := new(models.LiveRedEnvelopeRule) diff --git a/controllers/client/reward.go b/controllers/client/reward.go index 5cdcf7e..ec44e3f 100644 --- a/controllers/client/reward.go +++ b/controllers/client/reward.go @@ -61,6 +61,7 @@ func (t *RewardCtl) Reward() { _, err = core.GetXormAuto().InsertOne(&models.RewardHistory{ OutTradeNo: res["out_trade_no"].(string), + ActivityId: activityId, RewardServerId: rewardServer.Id, CustomerId: activity.CustomerId, UserId: user.Id, diff --git a/controllers/common/im.go b/controllers/common/im.go index 63d8236..2f1f9c2 100644 --- a/controllers/common/im.go +++ b/controllers/common/im.go @@ -1,6 +1,7 @@ package common import ( + "fmt" "hudongzhuanjia/controllers" "hudongzhuanjia/libs/im" im_service "hudongzhuanjia/services/im" @@ -15,7 +16,7 @@ func (t *ImTestCtl) SendNotice() { activityId := t.MustGetInt64("activity_id") status := t.MustGetInt("status") - im_service.SendGroupCustomMessage(activityId, im.NoticeStatus(status), map[string]interface{}{ + im_service.SendGroupCustomMessage(fmt.Sprint(1), activityId, im.NoticeStatus(status), map[string]interface{}{ "customer_id": 16, "shake_red_envelope_rule_id": 5, "timestamp": time.Now().Unix(), @@ -27,7 +28,7 @@ func (t *ImTestCtl) SendRedPack() { activityId := t.MustGetInt64("activity_id") prompt := t.MustGet("prompt") - im_service.SendGroupCustomMessage(activityId, im.NoticeLiveRedPackStart, + im_service.SendGroupCustomMessage(fmt.Sprint(1), activityId, im.NoticeLiveRedPackStart, map[string]interface{}{ "live_red_envelope_rule_id": 1, "prompt": prompt, diff --git a/controllers/pc/reward.go b/controllers/pc/reward.go index 4bbb233..0478a4b 100644 --- a/controllers/pc/reward.go +++ b/controllers/pc/reward.go @@ -3,8 +3,10 @@ package pc import ( "fmt" "hudongzhuanjia/controllers" + "hudongzhuanjia/libs/im" "hudongzhuanjia/models" bully_reward_service "hudongzhuanjia/services/bully_reward" + im_service "hudongzhuanjia/services/im" "hudongzhuanjia/services/pay" "hudongzhuanjia/utils" "hudongzhuanjia/utils/code" @@ -92,7 +94,7 @@ func (t *RewardCtl) Review() { // 回退金额给用户 // 应该微信退款 - _, err := v.UpdateStatus(v.Id, 1) + _, err = v.UpdateStatus(v.Id, 1) t.CheckErr(err) if rehearsalId != 0 { // 彩排不需要金额 @@ -103,17 +105,30 @@ func (t *RewardCtl) Review() { t.CheckErr(err) } else { + var exist bool //增加客户的金额 - _, err := v.UpdateStatus(v.Id, 2) + _, err = v.UpdateStatus(v.Id, 2) t.CheckErr(err) + user := new(models.User) + exist, err = models.GetById(user, v.UserId) + t.CheckErr(err) + t.Assert(exist, code.MSG_USER_NOT_EXIST, "用户不存在") + + go im_service.SendNoticeByActivityId(v.ActivityId, im.NoticeReward, + map[string]interface{}{ + "nickname": user.Nickname, + "avatar": user.Avatar, + "amount": v.Amount, + "content": v.Content, + }) if rehearsalId != 0 { // 彩排不需要金额 continue } uid := t.MustGetUID() customer := new(models.Customer) - exist, err := models.GetById(customer, uid) + exist, err = models.GetById(customer, uid) t.CheckErr(err) t.Assert(exist, code.MSG_CUSTOMER_NOT_EXIST, "客户不存在") diff --git a/controllers/pc/shake_red_envelope.go b/controllers/pc/shake_red_envelope.go index 2f35634..2f17f78 100644 --- a/controllers/pc/shake_red_envelope.go +++ b/controllers/pc/shake_red_envelope.go @@ -82,7 +82,7 @@ func (t *ShakeRedEnvelopeCtl) Start() { _, err = rule.UpdateStatus(ruleId, define.StatusRunning) t.CheckErr(err) - go im_service.SendGroupCustomMessage(envelope.ActivityId, im.NoticeShakeRedPackStart, + go im_service.SendGroupCustomMessage("admin", envelope.ActivityId, im.NoticeShakeRedPackStart, map[string]interface{}{ "customer_id": uid, "shake_red_envelope_rule_id": rule.Id, @@ -111,7 +111,7 @@ func (t *ShakeRedEnvelopeCtl) Stop() { _, err = rule.UpdateStatus(ruleId, rule.ShakeRedEnvelopeStatus) t.CheckErr(err) - go im_service.SendGroupCustomMessage(envelope.ActivityId, im.NoticeShakeRedPackEnd, + go im_service.SendGroupCustomMessage("admin", envelope.ActivityId, im.NoticeShakeRedPackEnd, map[string]interface{}{ "customer_id": uid, "shake_red_envelope_rule_id": rule.Id, diff --git a/libs/im/im.go b/libs/im/im.go index c723ae5..a3e4ad7 100644 --- a/libs/im/im.go +++ b/libs/im/im.go @@ -104,7 +104,7 @@ type SendGroupMessageParam struct { Random int `json:"Random"` MsgPriority string `json:"MsgPriority,omitempty"` MsgBody []MsgBody `json:"MsgBody"` - FromAccount string `json:"FromAccount,omitempty"` + FromAccount string `json:"From_Account,omitempty"` OfflinePushInfo interface{} `json:"OfflinePushInfo,omitempty"` ForbidCallbackControl interface{} `json:"ForbidCallbackControl,omitempty"` OnlineOnlyFlag int `json:"OnlineOnlyFlag,omitempty"` diff --git a/libs/im/status.go b/libs/im/status.go index 5bf4268..f3b0bab 100644 --- a/libs/im/status.go +++ b/libs/im/status.go @@ -8,3 +8,4 @@ const NoticeLiveRedPackEnd NoticeStatus = 257 // 通知直播用户红包结 const NoticeLiveRedPackGet NoticeStatus = 258 // 某人摇中红包 const NoticeShakeRedPackStart NoticeStatus = 259 // 通知摇红包开始了 const NoticeShakeRedPackEnd NoticeStatus = 260 // 通知摇红包结束了 +const NoticeReward NoticeStatus = 261 // 打赏 diff --git a/models/live_red_envelope_rule.go b/models/live_red_envelope_rule.go index 2697d11..c977b91 100644 --- a/models/live_red_envelope_rule.go +++ b/models/live_red_envelope_rule.go @@ -39,5 +39,6 @@ func (t *LiveRedEnvelopeRule) GetByOutTradeNo(outTradeNo string) (bool, error) { func (t *LiveRedEnvelopeRule) UpdateStatusByOutTradeNo(outTradeNo string, status int) (int64, error) { t.Status = status - return core.GetXormAuto().Where("is_delete=0 and out_trade_no=?", status, outTradeNo).Update(t) + return core.GetXormAuto().Where("is_delete=0 and out_trade_no=?", status, outTradeNo). + Cols("status").Update(t) } diff --git a/models/reward_history.go b/models/reward_history.go index 7071746..237ca58 100644 --- a/models/reward_history.go +++ b/models/reward_history.go @@ -18,6 +18,7 @@ type RewardHistory struct { OutTradeNo string `json:"out_trade_no" xorm:"not null default '' comment('微信订单号') VARCHAR(128)"` CustomerId int64 `json:"customer_id" xorm:"not null default 0 comment('客户id') INT(11)"` RewardServerId int64 `json:"reward_server_id" xorm:"not null default 0 comment('打赏服务id') INT(11)"` + ActivityId int64 `json:"activity_id" xorm:"not null default 0 comment('主活动id') INT(11)"` RehearsalId int64 `json:"rehearsal_id" xorm:"not null default 0 comment('彩排id/0正式') INT(11)"` UserId int64 `json:"user_id" xorm:"not null default 0 comment('用户得id') INT(11)"` Content string `json:"content" xorm:"not null comment('内容') text"` diff --git a/services/im/im.go b/services/im/im.go index cd73c8d..e70e502 100644 --- a/services/im/im.go +++ b/services/im/im.go @@ -23,7 +23,7 @@ func SendNoticeByActivityId(activityId int64, _type im.NoticeStatus, data map[st return im.SendGroupSystemNotification(groupId, _type, data, members...) } -func SendGroupCustomMessage(activityId int64, _type im.NoticeStatus, data map[string]interface{}) error { +func SendGroupCustomMessage(userId string, activityId int64, _type im.NoticeStatus, data map[string]interface{}) error { live := new(models.LiveConfig) exist, err := live.GetByActivityId(activityId) if err != nil { @@ -42,6 +42,7 @@ func SendGroupCustomMessage(activityId int64, _type im.NoticeStatus, data map[st GroupId: groupId, Random: utils.RandomInt(6), MsgPriority: "High", + FromAccount: userId, MsgBody: []im.MsgBody{ { MsgType: "TIMCustomElem", diff --git a/services/pay/handle.go b/services/pay/handle.go index 1e31524..059fee1 100644 --- a/services/pay/handle.go +++ b/services/pay/handle.go @@ -91,7 +91,16 @@ func HandleSuccess(param *orderDelayQueueParam) (err error) { return } - err = im_service.SendGroupCustomMessage(param.Order.ActivityId, im.NoticeLiveRedPackStart, + user := new(models.User) + exist, err = models.GetById(user, info.UserId) + if err != nil || !exist { + err = fmt.Errorf("直播红包用户信息异常: err-> %v, exist->%v, status->%v, out_trade_no->%v", + err, exist, info.Status, param.Order.OutTradeNo) + logger.Error(err.Error()) + return + } + + err = im_service.SendGroupCustomMessage(fmt.Sprint(info.UserId), param.Order.ActivityId, im.NoticeLiveRedPackStart, map[string]interface{}{ "live_red_envelope_rule_id": info.Id, "prompt": info.Prompt, diff --git a/test/pay_test.go b/test/pay_test.go index f65efb7..0f07616 100644 --- a/test/pay_test.go +++ b/test/pay_test.go @@ -53,15 +53,19 @@ func TestTimeExpire(t *testing.T) { func TestSendNotice(t *testing.T) { for { - err := im_service.SendGroupCustomMessage(114, im.NoticeShakeRedPackStart, map[string]interface{}{ - "customer_id": 1, - "shake_red_envelope_rule_id": 2, - "timestamp": time.Now().Unix(), + err := im_service.SendGroupCustomMessage(fmt.Sprint(4), 118, im.NoticeLiveRedPackStart, map[string]interface{}{ + "live_red_envelope_rule_id": 2, + "prompt": "恭喜你发出", + "timestamp": time.Now().Unix(), }) fmt.Print(err) } } +func TestGenSig(t *testing.T) { + fmt.Print(im.GenSig("admin")) +} + // 地球半径,单位米 const R = 6367000