This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"encoding/json"
|
||||
"math"
|
||||
|
||||
commonLogic "github.com/perfect-panel/server/internal/logic/common"
|
||||
"github.com/perfect-panel/server/internal/model/order"
|
||||
"github.com/perfect-panel/server/pkg/tool"
|
||||
|
||||
@@ -52,25 +53,30 @@ func (l *PreCreateOrderLogic) PreCreateOrder(req *types.PurchaseOrderRequest) (r
|
||||
|
||||
targetSubscribeID := req.SubscribeId
|
||||
isSingleModeRenewal := false
|
||||
if l.svcCtx.Config.Subscribe.SingleModel {
|
||||
anchorSub, anchorErr := l.svcCtx.UserModel.FindSingleModeAnchorSubscribe(l.ctx, u.Id)
|
||||
switch {
|
||||
case anchorErr == nil && anchorSub != nil:
|
||||
targetSubscribeID = anchorSub.SubscribeId
|
||||
isSingleModeRenewal = true
|
||||
if req.SubscribeId != targetSubscribeID {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SingleSubscribePlanMismatch), "single subscribe mode plan mismatch")
|
||||
}
|
||||
decision, routeErr := commonLogic.ResolvePurchaseRoute(
|
||||
l.ctx,
|
||||
l.svcCtx.Config.Subscribe.SingleModel,
|
||||
u.Id,
|
||||
req.SubscribeId,
|
||||
l.svcCtx.UserModel.FindSingleModeAnchorSubscribe,
|
||||
)
|
||||
switch {
|
||||
case errors.Is(routeErr, commonLogic.ErrSingleModePlanMismatch):
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SingleSubscribePlanMismatch), "single subscribe mode plan mismatch")
|
||||
case errors.Is(routeErr, gorm.ErrRecordNotFound):
|
||||
case routeErr != nil:
|
||||
l.Errorw("[PreCreateOrder] Database query error", logger.Field("error", routeErr.Error()), logger.Field("user_id", u.Id))
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DatabaseQueryError), "find single mode anchor subscribe error: %v", routeErr.Error())
|
||||
case decision != nil:
|
||||
targetSubscribeID = decision.ResolvedSubscribeID
|
||||
isSingleModeRenewal = decision.Route == commonLogic.PurchaseRoutePurchaseToRenewal
|
||||
if isSingleModeRenewal && decision.Anchor != nil {
|
||||
l.Infow("[PreCreateOrder] single mode purchase routed to renewal preview",
|
||||
logger.Field("mode", "single"),
|
||||
logger.Field("route", "purchase_to_renewal"),
|
||||
logger.Field("anchor_user_subscribe_id", anchorSub.Id),
|
||||
logger.Field("anchor_user_subscribe_id", decision.Anchor.Id),
|
||||
logger.Field("user_id", u.Id),
|
||||
)
|
||||
case errors.Is(anchorErr, gorm.ErrRecordNotFound):
|
||||
case anchorErr != nil:
|
||||
l.Errorw("[PreCreateOrder] Database query error", logger.Field("error", anchorErr.Error()), logger.Field("user_id", u.Id))
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DatabaseQueryError), "find single mode anchor subscribe error: %v", anchorErr.Error())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"math"
|
||||
"time"
|
||||
|
||||
commonLogic "github.com/perfect-panel/server/internal/logic/common"
|
||||
"github.com/perfect-panel/server/internal/model/log"
|
||||
"github.com/perfect-panel/server/pkg/constant"
|
||||
|
||||
@@ -71,30 +72,35 @@ func (l *PurchaseLogic) Purchase(req *types.PurchaseOrderRequest) (resp *types.P
|
||||
subscribeToken := ""
|
||||
anchorUserSubscribeID := int64(0)
|
||||
isSingleModeRenewal := false
|
||||
if l.svcCtx.Config.Subscribe.SingleModel {
|
||||
anchorSub, anchorErr := l.svcCtx.UserModel.FindSingleModeAnchorSubscribe(l.ctx, u.Id)
|
||||
switch {
|
||||
case anchorErr == nil && anchorSub != nil:
|
||||
if req.SubscribeId != anchorSub.SubscribeId {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SingleSubscribePlanMismatch), "single subscribe mode plan mismatch")
|
||||
}
|
||||
targetSubscribeID = anchorSub.SubscribeId
|
||||
decision, routeErr := commonLogic.ResolvePurchaseRoute(
|
||||
l.ctx,
|
||||
l.svcCtx.Config.Subscribe.SingleModel,
|
||||
u.Id,
|
||||
req.SubscribeId,
|
||||
l.svcCtx.UserModel.FindSingleModeAnchorSubscribe,
|
||||
)
|
||||
switch {
|
||||
case errors.Is(routeErr, commonLogic.ErrSingleModePlanMismatch):
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SingleSubscribePlanMismatch), "single subscribe mode plan mismatch")
|
||||
case errors.Is(routeErr, gorm.ErrRecordNotFound):
|
||||
case routeErr != nil:
|
||||
l.Errorw("[Purchase] Database query error", logger.Field("error", routeErr.Error()), logger.Field("user_id", u.Id))
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DatabaseQueryError), "find single mode anchor subscribe error: %v", routeErr.Error())
|
||||
case decision != nil:
|
||||
targetSubscribeID = decision.ResolvedSubscribeID
|
||||
isSingleModeRenewal = decision.Route == commonLogic.PurchaseRoutePurchaseToRenewal
|
||||
if isSingleModeRenewal && decision.Anchor != nil {
|
||||
orderType = 2
|
||||
parentOrderID = anchorSub.OrderId
|
||||
subscribeToken = anchorSub.Token
|
||||
anchorUserSubscribeID = anchorSub.Id
|
||||
isSingleModeRenewal = true
|
||||
parentOrderID = decision.Anchor.OrderId
|
||||
subscribeToken = decision.Anchor.Token
|
||||
anchorUserSubscribeID = decision.Anchor.Id
|
||||
l.Infow("[Purchase] single mode purchase routed to renewal",
|
||||
logger.Field("mode", "single"),
|
||||
logger.Field("route", "purchase_to_renewal"),
|
||||
logger.Field("anchor_user_subscribe_id", anchorSub.Id),
|
||||
logger.Field("anchor_user_subscribe_id", decision.Anchor.Id),
|
||||
logger.Field("order_no", "pending"),
|
||||
logger.Field("user_id", u.Id),
|
||||
)
|
||||
case errors.Is(anchorErr, gorm.ErrRecordNotFound):
|
||||
case anchorErr != nil:
|
||||
l.Errorw("[Purchase] Database query error", logger.Field("error", anchorErr.Error()), logger.Field("user_id", u.Id))
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DatabaseQueryError), "find single mode anchor subscribe error: %v", anchorErr.Error())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user