Browse Source

send red pack

master
黄梓健 5 years ago
parent
commit
e843b8b25f
  1. 1
      controllers/base.go
  2. 5
      controllers/client/live.go
  3. 5
      controllers/client/reward.go
  4. 8
      controllers/pc/reward.go
  5. 4
      models/live_config.go
  6. 3
      models/live_red_envelope_rule.go
  7. 9
      services/im/im.go
  8. 10
      test/config_test.go
  9. 11
      test/pay_test.go

1
controllers/base.go

@ -77,6 +77,7 @@ func (t *BaseCtl) GetInt64(key string) (int64, bool) {
if err != nil {
logger.Sugar.Infof("get int64 from request error", err)
t.ERROR(fmt.Sprintf("%v的数据类型不为int", key), code.MSG_ERR_Param)
return value, false
}
return value, true

5
controllers/client/live.go

@ -123,14 +123,15 @@ func (t *LiveCtl) SendLiveRedPack() {
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)
res, err = pay_service.UnifiedOrder("欧轩互动-直播红包", user.Openid, int64(amount*100), 3, userId, activityId)
t.CheckErr(err)
}
rule := models.LiveRedEnvelopeRule{}
rule.OutTradeNo = res["out_trade_no"].(string) // 彩排为空
rule.ActivityId = activityId
rule.ActivityId = activity.RehearsalId
rule.RehearsalId = activity.RehearsalId
rule.AreaId = areaId
rule.UserId = userId
rule.Amount = amount
rule.Num = num

5
controllers/client/reward.go

@ -28,6 +28,7 @@ func (t *RewardCtl) Reward() {
t.ERROR("打赏金额不能小于0", code.MSG_ERR_Param)
return
}
//检查内容是否包含敏感
if ok, _ := filter.Validate(content); !ok {
t.ERROR("内容包含敏感字", code.MSG_ERR)
@ -53,7 +54,8 @@ func (t *RewardCtl) Reward() {
t.CheckErr(err)
t.Assert(exist, code.MSG_USER_NOT_EXIST, "用户不存在")
var res map[string]interface{}
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), 2, user.Id, activityId)
t.CheckErr(err)
@ -76,6 +78,7 @@ func (t *RewardCtl) Reward() {
})
t.CheckErr(err)
res["rehearsal_id"] = activity.RehearsalId
t.JSON(res)
}

8
controllers/pc/reward.go

@ -115,12 +115,10 @@ func (t *RewardCtl) Review() {
t.CheckErr(err)
t.Assert(exist, code.MSG_USER_NOT_EXIST, "用户不存在")
go im_service.SendNoticeByActivityId(v.ActivityId, im.NoticeReward,
go im_service.SendGroupCustomMessage(fmt.Sprint(user.Id), v.ActivityId, im.NoticeReward,
map[string]interface{}{
"nickname": user.Nickname,
"avatar": user.Avatar,
"amount": v.Amount,
"content": v.Content,
"amount": v.Amount,
"content": v.Content,
})
if rehearsalId != 0 { // 彩排不需要金额
continue

4
models/live_config.go

@ -15,6 +15,7 @@ type LiveConfig struct {
LiveSwitch int `json:"live_switch" xorm:"not null default 0 comment('直播开关0关1开') INT(11)"`
ActivityId int64 `json:"activity_id" xorm:"not null default 0 comment('互动id') INT(11)"`
AreaId int64 `json:"area_id" xorm:"not null default 0 comment('地域') INT(11)"`
LiveRoomId string `json:"live_room_id" xorm:"not null default '' comment('直播间id') VARCHAR(128)"`
AdaptationFunc []interface{} `json:"adaptation_func" xorm:"json not null default '' comment('选中的适配功能及互动已买的服务id,json格式') VARCHAR(255)"`
StartTime time.Time `json:"start_time" xorm:"not null default '1970-01-01 08:00:00' comment('开播时间') DATETIME"`
@ -39,9 +40,6 @@ type LiveConfig struct {
LikeNum int `json:"like_num" xorm:"not null default 0 comment('点赞数') INT(11)"`
ImGroupId string `json:"im_group_id" xorm:"not null default '' comment('腾讯im聊天群id') VARCHAR(255)"`
ImGroupName string `json:"im_group_name" xorm:"not null default '' comment('聊天群名称') VARCHAR(255)"`
// 无关数据
AreaId int64 `json:"area_id" xorm:"-"`
}
func (t *LiveConfig) TableName() string {

3
models/live_red_envelope_rule.go

@ -16,6 +16,7 @@ type LiveRedEnvelopeRule struct {
UserId int64 `json:"user_id" xorm:"not null default 0 comment('用户id') INT(11)"`
ActivityId int64 `json:"activity_id" xorm:"not null default 0 comment('互动id') INT(11)"`
AreaId int64 `json:"area_id" xorm:"not null default 0 comment('地区id') INT(11)"`
RehearsalId int64 `json:"rehearsal_id" xorm:"not null default 0 comment('彩排id') INT(11)"`
GroupId string `json:"group_id" xorm:"not null default '' comment('聊天室地址') VARCHAR(128)"`
Prompt string `json:"prompt" xorm:"not null default 0 comment('祝福语') VARCHAR(255)"`
@ -39,6 +40,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).
return core.GetXormAuto().Where("is_delete=0 and out_trade_no=?", outTradeNo).
Cols("status").Update(t)
}

9
services/im/im.go

@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"hudongzhuanjia/libs/im"
"hudongzhuanjia/logger"
"hudongzhuanjia/models"
"hudongzhuanjia/utils"
"strconv"
@ -26,12 +27,12 @@ func SendNoticeByActivityId(activityId int64, _type im.NoticeStatus, data map[st
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 {
if err != nil || !exist {
err = fmt.Errorf("直播信息异常: err-> %v, exist->%v, activity_id-> %v", err, exist, activityId)
logger.Error(err.Error())
return err
}
if !exist {
return errors.New("直播信息不存在")
}
bs, err := json.Marshal(data)
if err != nil {
return err

10
test/config_test.go

@ -6,6 +6,7 @@ import (
"github.com/ouxuanserver/osmanthuswine/src/helper"
"github.com/panjf2000/ants"
. "github.com/smartystreets/goconvey/convey"
pay_service "hudongzhuanjia/services/pay"
"hudongzhuanjia/utils"
"hudongzhuanjia/utils/define"
"math/rand"
@ -13,7 +14,6 @@ import (
"regexp"
"runtime"
"sort"
"strings"
"sync"
"testing"
"time"
@ -196,12 +196,8 @@ func TestDuration(t *testing.T) {
//}
func TestRefundRedPack(t *testing.T) {
var a = `["姓名","电话"]`
fmt.Println(a[1 : len(a)-1])
as := strings.Split(a[1:len(a)-1], ",")
fmt.Printf("%+v\n", as)
fmt.Println(strings.Trim(as[1], "\"") == "电话")
fmt.Println(as[0] == "电话")
res, err := pay_service.Refund("退款", "RpY6pmvbZy9yPP8kPEzF5H7s27E3kW3E")
fmt.Printf("%+v, %v", res, err)
//res, err := pay_service.QueryRedPack("tDYW8edlzegSlVNaJMXsteZEeuVL")
//fmt.Printf("%+v, %+v", res, err)
}

11
test/pay_test.go

@ -53,11 +53,12 @@ func TestTimeExpire(t *testing.T) {
func TestSendNotice(t *testing.T) {
for {
err := im_service.SendGroupCustomMessage(fmt.Sprint(4), 118, im.NoticeLiveRedPackStart, map[string]interface{}{
"live_red_envelope_rule_id": 2,
"prompt": "恭喜你发出",
"timestamp": time.Now().Unix(),
})
err := im_service.SendGroupCustomMessage(fmt.Sprint(4), 118, im.NoticeReward,
map[string]interface{}{
"amount": 20.01,
"content": "恭喜你发出",
"timestamp": time.Now().Unix(),
})
fmt.Print(err)
}
}

Loading…
Cancel
Save