fix(order): align invite gift ownership
Build docker and publish / build (20.15.1) (push) Has been cancelled
Build docker and publish / build (20.15.1) (push) Has been cancelled
This commit is contained in:
@@ -1090,7 +1090,9 @@ func (l *ActivateOrderLogic) handleCommission(ctx context.Context, userInfo *use
|
||||
// 有佣金路径:邀请人拿佣金,被邀请用户(首单)拿天数
|
||||
if orderInfo.IsNew {
|
||||
giftTarget := l.resolveGiftTargetUser(ctx, userInfo, orderInfo.SubscriptionUserId)
|
||||
_ = l.grantGiftDays(ctx, giftTarget, int(l.svc.Config.Invite.GiftDays), orderInfo.OrderNo, "邀请赠送")
|
||||
if giftErr := l.grantGiftDays(ctx, giftTarget, int(l.svc.Config.Invite.GiftDays), orderInfo.OrderNo, "邀请赠送"); giftErr != nil {
|
||||
l.logGiftDaysError(ctx, giftErr, giftTarget, orderInfo, "commission_path_referee")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1100,7 +1102,9 @@ func (l *ActivateOrderLogic) grantGiftDaysToBothParties(ctx context.Context, ref
|
||||
return
|
||||
}
|
||||
refereeTarget := l.resolveGiftTargetUser(ctx, referee, orderInfo.SubscriptionUserId)
|
||||
_ = l.grantGiftDays(ctx, refereeTarget, int(giftDays), orderInfo.OrderNo, "邀请赠送")
|
||||
if err := l.grantGiftDays(ctx, refereeTarget, int(giftDays), orderInfo.OrderNo, "邀请赠送"); err != nil {
|
||||
l.logGiftDaysError(ctx, err, refereeTarget, orderInfo, "no_commission_referee")
|
||||
}
|
||||
if referee.RefererId == 0 {
|
||||
return
|
||||
}
|
||||
@@ -1109,7 +1113,9 @@ func (l *ActivateOrderLogic) grantGiftDaysToBothParties(ctx context.Context, ref
|
||||
return
|
||||
}
|
||||
refererTarget := l.resolveGiftTargetUser(ctx, referer, 0)
|
||||
_ = l.grantGiftDays(ctx, refererTarget, int(giftDays), orderInfo.OrderNo, "邀请赠送")
|
||||
if err = l.grantGiftDays(ctx, refererTarget, int(giftDays), orderInfo.OrderNo, "邀请赠送"); err != nil {
|
||||
l.logGiftDaysError(ctx, err, refererTarget, orderInfo, "no_commission_referer")
|
||||
}
|
||||
}
|
||||
|
||||
func (l *ActivateOrderLogic) resolveGiftTargetUser(ctx context.Context, source *user.User, forcedOwnerID int64) *user.User {
|
||||
@@ -1136,6 +1142,26 @@ func (l *ActivateOrderLogic) resolveGiftTargetUser(ctx context.Context, source *
|
||||
return target
|
||||
}
|
||||
|
||||
func (l *ActivateOrderLogic) logGiftDaysError(ctx context.Context, err error, target *user.User, orderInfo *order.Order, stage string) {
|
||||
if err == nil {
|
||||
return
|
||||
}
|
||||
var targetID int64
|
||||
if target != nil {
|
||||
targetID = target.Id
|
||||
}
|
||||
var orderNo string
|
||||
if orderInfo != nil {
|
||||
orderNo = orderInfo.OrderNo
|
||||
}
|
||||
logger.WithContext(ctx).Error("Grant invite gift days failed",
|
||||
logger.Field("error", err.Error()),
|
||||
logger.Field("stage", stage),
|
||||
logger.Field("target_user_id", targetID),
|
||||
logger.Field("order_no", orderNo),
|
||||
)
|
||||
}
|
||||
|
||||
func (l *ActivateOrderLogic) grantGiftDays(ctx context.Context, u *user.User, days int, orderNo string, remark string) error {
|
||||
if u == nil || days <= 0 {
|
||||
return nil
|
||||
@@ -1179,7 +1205,9 @@ func (l *ActivateOrderLogic) grantGiftDays(ctx context.Context, u *user.User, da
|
||||
}
|
||||
return err
|
||||
}
|
||||
activeSubscribe.ExpireTime = activeSubscribe.ExpireTime.Add(time.Duration(days) * 24 * time.Hour)
|
||||
if !activeSubscribe.ExpireTime.Equal(time.UnixMilli(0)) {
|
||||
activeSubscribe.ExpireTime = activeSubscribe.ExpireTime.Add(time.Duration(days) * 24 * time.Hour)
|
||||
}
|
||||
err = l.svc.UserModel.UpdateSubscribe(ctx, activeSubscribe)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
Reference in New Issue
Block a user