|
|
@ -3,7 +3,6 @@ package pay_service |
|
|
|
import ( |
|
|
|
"errors" |
|
|
|
"fmt" |
|
|
|
"github.com/ouxuanserver/osmanthuswine/src/core" |
|
|
|
"hudongzhuanjia/logger" |
|
|
|
"hudongzhuanjia/models" |
|
|
|
im_service "hudongzhuanjia/services/im" |
|
|
@ -13,14 +12,14 @@ import ( |
|
|
|
//处理支付成功之后的回调问题
|
|
|
|
|
|
|
|
// 直播红包
|
|
|
|
func HandleSuccess(param *OrderDelayQueueParam) error { |
|
|
|
if param.Order.GoodType == 4 { // 直播商品
|
|
|
|
func HandleSuccess(order *models.UserOrder) error { |
|
|
|
if order.GoodType == 4 { // 直播商品
|
|
|
|
customerOrder := new(models.CustomerOrder) |
|
|
|
_, err := customerOrder.UpdateStatusBy(param.Order.OutTradeNo, 0, 1) |
|
|
|
_, err := customerOrder.UpdateStatusBy(order.OutTradeNo, 0, 1) |
|
|
|
if err != nil { |
|
|
|
return errors.New("更新状态发送错误") |
|
|
|
} |
|
|
|
customerOrder.GetByOutTradeNO(param.Order.OutTradeNo) |
|
|
|
customerOrder.GetByOutTradeNO(order.OutTradeNo) |
|
|
|
if customerOrder.Status != 1 { |
|
|
|
return errors.New("商品订单状态信息出现异常") |
|
|
|
} |
|
|
@ -30,7 +29,7 @@ func HandleSuccess(param *OrderDelayQueueParam) error { |
|
|
|
return err |
|
|
|
} |
|
|
|
for _, sub := range subs { |
|
|
|
err = im_service.SendGroupCustomMessage(customerOrder.BuyerId, param.Order.ActivityId, im_service.NoticeLiveGoodBuy, |
|
|
|
err = im_service.SendGroupCustomMessage(customerOrder.BuyerId, order.ActivityId, im_service.NoticeLiveGoodBuy, |
|
|
|
map[string]interface{}{ |
|
|
|
"goods_pic_url": sub.GoodsPicUrl, |
|
|
|
"goods_num": sub.GoodsNum, |
|
|
@ -46,13 +45,13 @@ func HandleSuccess(param *OrderDelayQueueParam) error { |
|
|
|
} |
|
|
|
|
|
|
|
activity := new(models.Activity) |
|
|
|
exist, err := models.Get(activity, param.Order.ActivityId) |
|
|
|
exist, err := models.Get(activity, order.ActivityId) |
|
|
|
if err != nil || !exist { |
|
|
|
return errors.New("互动信息异常") |
|
|
|
} |
|
|
|
|
|
|
|
gift := new(models.OrderGift) |
|
|
|
exist, err = gift.GetByActivityId(param.Order.ActivityId) |
|
|
|
exist, err = gift.GetByActivityId(order.ActivityId) |
|
|
|
if err != nil { |
|
|
|
err = fmt.Errorf("获取订单送礼错误: err-> %v, activity_id-> %v", err, activity.Id) |
|
|
|
logger.Error(err) |
|
|
@ -64,8 +63,8 @@ func HandleSuccess(param *OrderDelayQueueParam) error { |
|
|
|
} |
|
|
|
|
|
|
|
prize := new(models.UserPrize) |
|
|
|
prize.UserId = param.Order.UserId |
|
|
|
prize.ActivityId = param.Order.ActivityId |
|
|
|
prize.UserId = order.UserId |
|
|
|
prize.ActivityId = order.ActivityId |
|
|
|
prize.RehearsalId = activity.RehearsalId |
|
|
|
prize.ActivityName = activity.Name |
|
|
|
prize.PrizeName = gift.GiftName |
|
|
@ -79,7 +78,7 @@ func HandleSuccess(param *OrderDelayQueueParam) error { |
|
|
|
count, err := new(models.CustomerOrder). |
|
|
|
Count(activity.Id, activity.RehearsalId, customerOrder.CreatedAt) |
|
|
|
if err != nil { |
|
|
|
err = fmt.Errorf("订单人数统计失败: err->%v, out_trade_no->%v", err, param.Order.OutTradeNo) |
|
|
|
err = fmt.Errorf("订单人数统计失败: err->%v, out_trade_no->%v", err, order.OutTradeNo) |
|
|
|
logger.Error(err) |
|
|
|
return err |
|
|
|
} |
|
|
@ -90,7 +89,7 @@ func HandleSuccess(param *OrderDelayQueueParam) error { |
|
|
|
} |
|
|
|
_, err = prize.Add() |
|
|
|
if err != nil { |
|
|
|
err = fmt.Errorf("奖品添加失败: err->%v, out_trade_no->%v", err, param.Order.OutTradeNo) |
|
|
|
err = fmt.Errorf("奖品添加失败: err->%v, out_trade_no->%v", err, order.OutTradeNo) |
|
|
|
logger.Error(err) |
|
|
|
return err |
|
|
|
} |
|
|
@ -98,27 +97,27 @@ func HandleSuccess(param *OrderDelayQueueParam) error { |
|
|
|
customerOrder.UserPrizeId = prize.Id |
|
|
|
_, err = models.Update(customerOrder.Id, customerOrder, "user_prize_id") |
|
|
|
if err != nil { |
|
|
|
err = fmt.Errorf("奖品记录添加失败: err-> %v, out_trade_no-> %v, prize_id->%v", err, param.Order.OutTradeNo, prize.Id) |
|
|
|
err = fmt.Errorf("奖品记录添加失败: err-> %v, out_trade_no-> %v, prize_id->%v", err, order.OutTradeNo, prize.Id) |
|
|
|
logger.Error(err) |
|
|
|
return err |
|
|
|
} |
|
|
|
} else if param.Order.GoodType == 3 { // 直播红包
|
|
|
|
} else if order.GoodType == 3 { // 直播红包
|
|
|
|
info := new(models.LiveRedEnvelopeRule) |
|
|
|
_, err := info.UpdateStatusByOutTradeNo(param.Order.OutTradeNo, 1) |
|
|
|
_, err := info.UpdateStatusByOutTradeNo(order.OutTradeNo, 1) |
|
|
|
if err != nil { |
|
|
|
err = fmt.Errorf("状态改变出现错误: err->%v, out_trade_no->%v", err, param.Order.OutTradeNo) |
|
|
|
err = fmt.Errorf("状态改变出现错误: err->%v, out_trade_no->%v", err, order.OutTradeNo) |
|
|
|
logger.Error(err.Error()) |
|
|
|
return err |
|
|
|
} |
|
|
|
exist, err := info.GetByOutTradeNo(param.Order.OutTradeNo) |
|
|
|
exist, err := info.GetByOutTradeNo(order.OutTradeNo) |
|
|
|
if err != nil || !exist || info.Status != 1 { |
|
|
|
err = fmt.Errorf("直播红包信息异常: err-> %v, exist->%v, status->%v, out_trade_no->%v", |
|
|
|
err, exist, info.Status, param.Order.OutTradeNo) |
|
|
|
err, exist, info.Status, order.OutTradeNo) |
|
|
|
logger.Error(err.Error()) |
|
|
|
return err |
|
|
|
} |
|
|
|
|
|
|
|
err = im_service.SendGroupCustomMessage(info.UserId, param.Order.ActivityId, im_service.NoticeLiveRedPackStart, |
|
|
|
err = im_service.SendGroupCustomMessage(info.UserId, order.ActivityId, im_service.NoticeLiveRedPackStart, |
|
|
|
map[string]interface{}{ |
|
|
|
"live_red_envelope_rule_id": info.Id, |
|
|
|
"prompt": info.Prompt, |
|
|
@ -126,65 +125,64 @@ func HandleSuccess(param *OrderDelayQueueParam) error { |
|
|
|
}) |
|
|
|
if err != nil { |
|
|
|
err = fmt.Errorf("发送腾讯im信息出现错误: err->%v, info_id->%v, out_trade_no->%v", |
|
|
|
err, info.Id, param.Order.OutTradeNo) |
|
|
|
err, info.Id, order.OutTradeNo) |
|
|
|
logger.Error(err.Error()) |
|
|
|
return err |
|
|
|
} |
|
|
|
} else if param.Order.GoodType == 2 { // 打赏
|
|
|
|
} else if order.GoodType == 2 { // 打赏
|
|
|
|
history := new(models.RewardHistory) |
|
|
|
exist, err := history.GetByOutTradeNo(param.Order.OutTradeNo) |
|
|
|
exist, err := history.GetByOutTradeNo(order.OutTradeNo) |
|
|
|
if err != nil || !exist || history.Status != -1 { |
|
|
|
err = fmt.Errorf("打赏历史异常: err->%v, out_trade_no %v", err, param.Order.OutTradeNo) |
|
|
|
err = fmt.Errorf("打赏历史异常: err->%v, out_trade_no %v", err, order.OutTradeNo) |
|
|
|
logger.Error(err.Error()) |
|
|
|
return err |
|
|
|
} |
|
|
|
_, err = history.UpdateStatus(history.Id, 0) |
|
|
|
if err != nil { |
|
|
|
err = fmt.Errorf("打赏状态发送变化: err->%v, out_trade_no %v", err, param.Order.OutTradeNo) |
|
|
|
err = fmt.Errorf("打赏状态发送变化: err->%v, out_trade_no %v", err, order.OutTradeNo) |
|
|
|
logger.Error(err.Error()) |
|
|
|
return err |
|
|
|
} |
|
|
|
} else if param.Order.GoodType == 1 { // 霸屏
|
|
|
|
} else if order.GoodType == 1 { // 霸屏
|
|
|
|
history := new(models.BullyScreenHistory) |
|
|
|
exist, err := history.GetByOutTradeNo(param.Order.OutTradeNo) |
|
|
|
exist, err := history.GetByOutTradeNo(order.OutTradeNo) |
|
|
|
if err != nil || !exist || history.Status != -1 { |
|
|
|
err = fmt.Errorf("打赏历史异常: err->%v, out_trade_no %v", err, param.Order.OutTradeNo) |
|
|
|
err = fmt.Errorf("打赏历史异常: err->%v, out_trade_no %v", err, order.OutTradeNo) |
|
|
|
logger.Error(err.Error()) |
|
|
|
return err |
|
|
|
} |
|
|
|
|
|
|
|
_, err = history.UpdateStatus(history.Id, 0) |
|
|
|
if err != nil { |
|
|
|
err = fmt.Errorf("霸屏状态发送变化: err->%v, out_trade_no %v", err, param.Order.OutTradeNo) |
|
|
|
err = fmt.Errorf("霸屏状态发送变化: err->%v, out_trade_no %v", err, order.OutTradeNo) |
|
|
|
logger.Error(err.Error()) |
|
|
|
} |
|
|
|
} |
|
|
|
return nil |
|
|
|
} |
|
|
|
|
|
|
|
func HandleFailed(param *OrderDelayQueueParam) (err error) { |
|
|
|
var exist bool |
|
|
|
func HandleFailed(order *models.UserOrder) error { |
|
|
|
// 退还库存
|
|
|
|
if param.Order.GoodType == 4 { |
|
|
|
order := new(models.CustomerOrder) |
|
|
|
exist, err = order.GetByOutTradeNO(param.Order.OutTradeNo) |
|
|
|
if order.GoodType == 4 { |
|
|
|
customerOrder := new(models.CustomerOrder) |
|
|
|
exist, err := customerOrder.GetByOutTradeNO(order.OutTradeNo) |
|
|
|
if err != nil || !exist { |
|
|
|
err = fmt.Errorf("不存在客户订单: err-> %v, out_trade_no->%v", err, param.Order.OutTradeNo) |
|
|
|
err = fmt.Errorf("不存在客户订单: err-> %v, out_trade_no->%v", err, order.OutTradeNo) |
|
|
|
logger.Error(err.Error()) |
|
|
|
return |
|
|
|
return err |
|
|
|
} |
|
|
|
subs := make([]*models.CustomerOrderSub, 0) |
|
|
|
err = core.GetXormAuto().Where("is_delete=0 and order_no=?", order.OrderNo).Find(&subs) |
|
|
|
subs, err := models.GetCustomerOrderSubsByOrderNos(customerOrder.OrderNo) |
|
|
|
if err != nil { |
|
|
|
err = fmt.Errorf("不存在客户子订单: err-> %v, out_trade_no->%v", err, param.Order.OutTradeNo) |
|
|
|
err = fmt.Errorf("不存在客户子订单: err-> %v, out_trade_no->%v", err, order.OutTradeNo) |
|
|
|
return err |
|
|
|
} |
|
|
|
for _, sub := range subs { |
|
|
|
_, err = core.GetXormAuto().Where("id=?", sub.GoodsId). |
|
|
|
Incr("stock", sub.GoodsNum).Update(&models.CustomerGoods{}) |
|
|
|
_, err = new(models.CustomerGoods).IncrStockById(sub.GoodsId, sub.GoodsNum) |
|
|
|
if err != nil { |
|
|
|
err = fmt.Errorf("库存返回失败: err->%v, out_trade_no->%v, sub_id->%v", err, param.Order.OutTradeNo, sub.Id) |
|
|
|
err = fmt.Errorf("库存返回失败: err->%v, out_trade_no->%v, sub_id->%v", err, order.OutTradeNo, sub.Id) |
|
|
|
return err |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return |
|
|
|
return nil |
|
|
|
} |