fix(account): 删除账户时清理会话token避免残留
Build docker and publish / build (20.15.1) (push) Successful in 6m0s
Build docker and publish / build (20.15.1) (push) Successful in 6m0s
feat(order): 添加邀请双方赠送天数功能 refactor(invite): 移除绑定邀请码时的天数赠送逻辑
This commit is contained in:
@@ -5,6 +5,7 @@ package orderLogic
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"time"
|
||||
@@ -354,6 +355,7 @@ func (l *ActivateOrderLogic) createUserSubscription(ctx context.Context, orderIn
|
||||
// This runs asynchronously to avoid blocking the main order processing flow.
|
||||
func (l *ActivateOrderLogic) handleCommission(ctx context.Context, userInfo *user.User, orderInfo *order.Order) {
|
||||
if !l.shouldProcessCommission(userInfo, orderInfo.IsNew) {
|
||||
l.grantGiftDaysToBothParties(ctx, userInfo)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -421,6 +423,37 @@ func (l *ActivateOrderLogic) handleCommission(ctx context.Context, userInfo *use
|
||||
}
|
||||
}
|
||||
|
||||
func (l *ActivateOrderLogic) grantGiftDaysToBothParties(ctx context.Context, referee *user.User) {
|
||||
giftDays := l.svc.Config.Invite.GiftDays
|
||||
if giftDays <= 0 || referee == nil || referee.Id == 0 {
|
||||
return
|
||||
}
|
||||
_ = l.grantGiftDays(ctx, referee, int(giftDays))
|
||||
if referee.RefererId == 0 {
|
||||
return
|
||||
}
|
||||
referer, err := l.svc.UserModel.FindOne(ctx, referee.RefererId)
|
||||
if err != nil || referer == nil {
|
||||
return
|
||||
}
|
||||
_ = l.grantGiftDays(ctx, referer, int(giftDays))
|
||||
}
|
||||
|
||||
func (l *ActivateOrderLogic) grantGiftDays(ctx context.Context, u *user.User, days int) error {
|
||||
if u == nil || days <= 0 {
|
||||
return nil
|
||||
}
|
||||
activeSubscribe, err := l.svc.UserModel.FindActiveSubscribe(ctx, u.Id)
|
||||
if err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
}
|
||||
activeSubscribe.ExpireTime = activeSubscribe.ExpireTime.Add(time.Duration(days) * 24 * time.Hour)
|
||||
return l.svc.UserModel.UpdateSubscribe(ctx, activeSubscribe)
|
||||
}
|
||||
|
||||
// shouldProcessCommission determines if commission should be processed based on
|
||||
// referrer existence, commission settings, and order type
|
||||
func (l *ActivateOrderLogic) shouldProcessCommission(userInfo *user.User, isFirstPurchase bool) bool {
|
||||
|
||||
Reference in New Issue
Block a user