diff --git a/controllers/client/order_entry.go b/controllers/client/order_entry.go index ac76ade..286606a 100644 --- a/controllers/client/order_entry.go +++ b/controllers/client/order_entry.go @@ -97,7 +97,6 @@ func (t *OrderEntryCtl) Order() { session.Rollback() t.CheckErr(err) } - } else if gift.Num > 0 { count, err := core.GetXormAuto().Where("activity_id=? and rehearsal_id=? and is_delete=0", activityId, activity.RehearsalId).Count(new(models.CustomerOrder)) @@ -119,10 +118,10 @@ func (t *OrderEntryCtl) Order() { order.UserPrizeId = prize.Id order.AreaId = entryPerson.AreaId order.AreaName = area.Name - order.RehearsalId = activity.RehearsalId order.BuyerId = userId order.GoodsId = goodId order.ActivityId = activityId + order.RehearsalId = activity.RehearsalId order.OrderEntryPersonId = entryPerson.Id order.GoodsName = good.Name order.TotalAmount = good.Price diff --git a/services/pay/handle.go b/services/pay/handle.go index 56c17a3..968823d 100644 --- a/services/pay/handle.go +++ b/services/pay/handle.go @@ -17,11 +17,6 @@ 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("商品已经支付") } @@ -31,49 +26,50 @@ func HandleSuccess(param *OrderDelayQueueParam) (err error) { 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 - // } - //} + activity := new(models.Activity) + exist, err = models.GetById(activity, param.Order.ActivityId) + if err != nil || !exist { + return errors.New("互动信息异常") + } + + gift := new(models.OrderGift) + exist, err = gift.GetByActivityId(param.Order.ActivityId) + if err != nil { + return err + } + prize := new(models.UserPrize) + prize.UserId = param.Order.UserId + prize.ActivityId = param.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 { + err = fmt.Errorf("订单人数统计失败: err->%v, out_trade_no->%v", err, param.Order.OutTradeNo) + return err + } + + if gift.Num <= int(count) { // 人数足够 + return nil + } + } + // gift.Num = 0 and + _, err = prize.Add() + if err != nil { + err = fmt.Errorf("奖品添加失败: err->%v, out_trade_no->%v", err, param.Order.OutTradeNo) + return err + } + } } else if param.Order.GoodType == 3 { // 直播红包 info := new(models.LiveRedEnvelopeRule) _, err = info.UpdateStatusByOutTradeNo(param.Order.OutTradeNo, 1)