|
|
@ -82,56 +82,71 @@ func (t *LiveCtl) LoopQuery() { |
|
|
|
// 下单发送红包
|
|
|
|
// 维护一个队列进行循环, 遍历是否付款成功
|
|
|
|
func (t *LiveCtl) SendLiveRedPack() { |
|
|
|
userId := t.MustGetUID() // 用户 uid
|
|
|
|
activityId := t.MustGetInt64("activity_id") // activity_id
|
|
|
|
num := t.MustGetInt("num") // 红包数量
|
|
|
|
amount := t.MustGetInt64("amount") // 金额
|
|
|
|
prompt := t.MustGet("prompt") // 提示
|
|
|
|
userId := t.MustGetUID() // 用户 uid
|
|
|
|
activityId := t.MustGetInt64("activity_id") // activity_id
|
|
|
|
num := t.MustGetInt("num") // 红包数量
|
|
|
|
prompt := t.MustGet("prompt") // 提示
|
|
|
|
amount := utils.Float64CusDecimal(t.MustGetDouble("amount"), 2) // 金额
|
|
|
|
areaId := t.MustGetInt64("area_id") |
|
|
|
|
|
|
|
activity := new(models.Activity) |
|
|
|
exist, err := models.GetById(activity, activityId) |
|
|
|
t.CheckErr(err) |
|
|
|
t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在") |
|
|
|
|
|
|
|
area := new(models.AreaStore) |
|
|
|
exist, err = models.GetById(area, areaId) |
|
|
|
t.CheckErr(err) |
|
|
|
t.Assert(exist, code.MSG_AREASTORE_NOT_EXIST, "地区不存在") |
|
|
|
|
|
|
|
user := models.User{} |
|
|
|
exist, err := models.GetById(&user, userId) |
|
|
|
exist, err = models.GetById(&user, userId) |
|
|
|
t.CheckErr(err) |
|
|
|
t.Assert(exist, code.MSG_USER_NOT_EXIST, "用户不存在") |
|
|
|
|
|
|
|
ip := strings.Split(t.Request.OriginRequest.RemoteAddr, ":") |
|
|
|
res, err := pay_service.UnifiedOrder("欧轩互动-直播红包", ip[0], user.Openid, amount, 3, activityId, userId) |
|
|
|
t.CheckErr(err) |
|
|
|
|
|
|
|
info := models.LiveRedPackInfo{} |
|
|
|
info.OutTradeNo = res["out_trade_no"].(string) |
|
|
|
info.Amount = amount |
|
|
|
info.UserId = userId |
|
|
|
info.ActivityId = activityId |
|
|
|
info.Prompt = filter.Replace(prompt) |
|
|
|
info.IsDelete = false |
|
|
|
info.UpdatedAt = time.Now() |
|
|
|
info.CreatedAt = time.Now() |
|
|
|
_, err = info.Add() |
|
|
|
t.CheckErr(err) |
|
|
|
|
|
|
|
redPacks := red_envelope_service.GenRedPack(int(amount), num) |
|
|
|
for _, v := range redPacks { |
|
|
|
redPack := new(models.LiveRedPack) |
|
|
|
redPack.LiveRedPackInfoId = info.Id |
|
|
|
redPack.ActivityId = activityId |
|
|
|
redPack.Receiver = 0 |
|
|
|
redPack.Amount = v |
|
|
|
redPack.CreatedAt = time.Now() |
|
|
|
redPack.UpdatedAt = time.Now() |
|
|
|
_, err = redPack.Add() |
|
|
|
res, err := pay_service.UnifiedOrder("欧轩互动-直播红包", ip[0], user.Openid, int64(amount*100), 3, activityId, userId) |
|
|
|
t.CheckErr(err) |
|
|
|
|
|
|
|
rule := models.LiveRedEnvelopeRule{} |
|
|
|
rule.OutTradeNo = res["out_trade_no"].(string) |
|
|
|
rule.Amount = amount |
|
|
|
rule.UserId = userId |
|
|
|
rule.ActivityId = activityId |
|
|
|
rule.Prompt = filter.Replace(prompt) |
|
|
|
rule.IsDelete = false |
|
|
|
rule.UpdatedAt = time.Now() |
|
|
|
rule.CreatedAt = time.Now() |
|
|
|
_, err = rule.Add() |
|
|
|
t.CheckErr(err) |
|
|
|
|
|
|
|
records := red_envelope_service.GenRedPack(int(amount*100), num) |
|
|
|
for _, v := range records { |
|
|
|
record := new(models.ShakeRedEnvelopeRecord) |
|
|
|
record.AreaId = area.Id |
|
|
|
record.AreaName = area.Name |
|
|
|
record.LiveRedEnvelopeRuleId = rule.Id |
|
|
|
record.ActivityId = activityId |
|
|
|
record.Name = activity.Name |
|
|
|
record.UserId = 0 |
|
|
|
record.Amount = utils.Float64CusDecimal(float64(v)/float64(100), 2) |
|
|
|
record.CreatedAt = time.Now() |
|
|
|
record.UpdatedAt = time.Now() |
|
|
|
_, err = record.Add() |
|
|
|
t.CheckErr(err) |
|
|
|
} |
|
|
|
|
|
|
|
res["red_pack_info_id"] = info.Id |
|
|
|
res["red_pack_info_id"] = rule.Id |
|
|
|
t.JSON(res) |
|
|
|
} |
|
|
|
|
|
|
|
// 支付之后可以遍历查询是否成功 -- 前端发送消息
|
|
|
|
// 不建议, 通过im 系统进行通知
|
|
|
|
func (t *LiveCtl) QueryLiveRedPack() { |
|
|
|
outTradeNo := t.MustGet("out_trade_no") |
|
|
|
res, err := pay_service.OrderQuery(outTradeNo) |
|
|
|
t.CheckErr(err) |
|
|
|
info := new(models.LiveRedPackInfo) |
|
|
|
info := new(models.LiveRedEnvelopeRule) |
|
|
|
exist, err := info.GetByOutTradeNo(outTradeNo) |
|
|
|
t.CheckErr(err) |
|
|
|
t.Assert(exist, code.MSG_LIVE_RED_PACK_INFO_NOT_EXIST, "直播红包信息不存在") |
|
|
@ -160,7 +175,7 @@ func (t *LiveCtl) GetLiveRedPack() { |
|
|
|
t.CheckErr(err) |
|
|
|
t.Assert(exist, code.MSG_USER_NOT_EXIST, "不存在用户") |
|
|
|
|
|
|
|
redPack := new(models.LiveRedPack) |
|
|
|
redPack := new(models.ShakeRedEnvelopeRecord) |
|
|
|
exist, err = redPack.GetByInfoId(liveRedPackInfoId) |
|
|
|
t.CheckErr(err) |
|
|
|
if !exist { |
|
|
|