|
|
package pay_service
import ( "errors" "fmt" "github.com/ouxuanserver/osmanthuswine/src/core" "hudongzhuanjia/libs/im" "hudongzhuanjia/logger" "hudongzhuanjia/models" im_service "hudongzhuanjia/services/im" "time" )
//处理支付成功之后的回调问题
// 直播红包
func HandleSuccess(param *orderDelayQueueParam) (err error) { var exist bool if param.Order.GoodType == 4 { // 直播商品
customerOrder := new(models.CustomerOrder) //exist, err := customerOrder.GetByOutTradeNO(order.OutTradeNo)
//if err != nil || !exist {
// return errors.New("直播商品信息异常")
//}
if customerOrder.Status == 1 { return errors.New("商品已经支付") }
_, err := customerOrder.UpdateStatusBy(param.Order.OutTradeNo, 0, 1) if err != nil { return errors.New("更新状态发送错误") }
//activity := new(models.Activity)
//exist, err = models.GetById(activity, order.ActivityId)
//if err != nil || !exist {
// return errors.New("互动信息异常")
//}
//
//gift := new(models.OrderGift)
//exist, err = gift.GetByActivityId(order.ActivityId)
//if err != nil {
// return err
//}
//
//prize := new(models.UserPrize)
//prize.UserId = order.UserId
//prize.ActivityId = order.ActivityId
//prize.RehearsalId = activity.RehearsalId
//prize.ActivityName = activity.Name
//prize.PrizeName = gift.GiftName
//prize.PrizeImg = gift.GiftPicUrl
//prize.PrizeType = 4
//prize.IsDelete = false
//prize.CreatedAt = time.Now()
//prize.UpdatedAt = time.Now()
//if exist {
// if gift.Num < 0 {
// } else if gift.Num > 0 {
// count, err := new(models.CustomerOrder).
// Count(activity.Id, activity.RehearsalId, customerOrder.CreatedAt)
// if err != nil {
// return err
// }
//
// if gift.Num <= int(count) { // 人数足够
// return nil
// }
// }
// // gift.Num = 0 and
// _, err = prize.Add()
// if err != nil {
// return err
// }
//}
} else if param.Order.GoodType == 3 { // 直播红包
info := new(models.LiveRedEnvelopeRule) _, err = info.UpdateStatusByOutTradeNo(param.Order.OutTradeNo, 1) if err != nil { err = fmt.Errorf("状态改变出现错误: err->%v, out_trade_no->%v", err, param.Order.OutTradeNo) logger.Error(err.Error()) return } exist, err = info.GetByOutTradeNo(param.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) logger.Error(err.Error()) return }
err = im_service.SendGroupCustomMessage(param.Order.ActivityId, im.NoticeLiveRedPackStart, map[string]interface{}{ "live_red_envelope_rule_id": info.Id, "prompt": info.Prompt, "timestamp": time.Now().Unix(), }) if err != nil { err = fmt.Errorf("发送腾讯im信息出现错误: err->%v, info_id->%v, out_trade_no->%v", err, info.Id, param.Order.OutTradeNo) logger.Error(err.Error()) } } else if param.Order.GoodType == 2 { // 打赏
history := new(models.RewardHistory) exist, err = history.GetByOutTradeNo(param.Order.OutTradeNo) if err != nil || !exist || history.Status != -1 { err = fmt.Errorf("打赏历史异常: err->%v, out_trade_no %v", err, param.Order.OutTradeNo) logger.Error(err.Error()) return } _, err = history.UpdateStatus(history.Id, 0) if err != nil { err = fmt.Errorf("打赏状态发送变化: err->%v, out_trade_no %v", err, param.Order.OutTradeNo) logger.Error(err.Error()) } } else if param.Order.GoodType == 1 { // 霸屏
history := new(models.BullyScreenHistory) exist, err = history.GetByOutTradeNo(param.Order.OutTradeNo) if err != nil || !exist || history.Status != -1 { err = fmt.Errorf("打赏历史异常: err->%v, out_trade_no %v", err, param.Order.OutTradeNo) logger.Error(err.Error()) return }
_, err = history.UpdateStatus(history.Id, 0) if err != nil { err = fmt.Errorf("霸屏状态发送变化: err->%v, out_trade_no %v", err, param.Order.OutTradeNo) logger.Error(err.Error()) } } return }
func HandleFailed(param *orderDelayQueueParam) (err error) { var exist bool // 退还库存
if param.Order.GoodType == 4 { order := new(models.CustomerOrder) exist, err = order.GetByOutTradeNO(param.Order.OutTradeNo) if err != nil || !exist { err = fmt.Errorf("不存在客户订单: err-> %v, out_trade_no->%v", err, param.Order.OutTradeNo) logger.Error(err.Error()) return } subs := make([]*models.CustomerOrderSub, 0) err = core.GetXormAuto().Where("is_delete=0 and order_no=?", order.OrderNo).Find(&subs) if err != nil { err = fmt.Errorf("不存在客户子订单: err-> %v, out_trade_no->%v", err, param.Order.OutTradeNo) } for _, sub := range subs { _, err = core.GetXormAuto().Where("id=?", sub.GoodsId). Incr("stock", sub.GoodsNum).Update(&models.CustomerGoods{}) if err != nil { err = fmt.Errorf("库存返回失败: err->%v, out_trade_no->%v, sub_id->%v", err, param.Order.OutTradeNo, sub.Id) } } } return }
|