This commit is contained in:
@@ -6,6 +6,8 @@ import (
|
||||
"math"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
|
||||
commonLogic "github.com/perfect-panel/server/internal/logic/common"
|
||||
"github.com/perfect-panel/server/internal/model/log"
|
||||
"github.com/perfect-panel/server/pkg/constant"
|
||||
@@ -31,7 +33,7 @@ type PurchaseLogic struct {
|
||||
}
|
||||
|
||||
const (
|
||||
CloseOrderTimeMinutes = 5
|
||||
CloseOrderTimeMinutes = 15
|
||||
)
|
||||
|
||||
// NewPurchaseLogic creates a new purchase logic instance for subscription purchase operations.
|
||||
@@ -54,8 +56,10 @@ func (l *PurchaseLogic) Purchase(req *types.PurchaseOrderRequest) (resp *types.P
|
||||
logger.Error("current user is not found in context")
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.InvalidAccess), "Invalid Access")
|
||||
}
|
||||
if err = commonLogic.DenyIfFamilyMemberReadonly(l.ctx, l.svcCtx.DB, u.Id); err != nil {
|
||||
return nil, err
|
||||
// Resolve entitlement: member's subscription goes to owner
|
||||
entitlement, entErr := commonLogic.ResolveEntitlementUser(l.ctx, l.svcCtx.DB, u.Id)
|
||||
if entErr != nil {
|
||||
return nil, entErr
|
||||
}
|
||||
|
||||
if req.Quantity <= 0 {
|
||||
@@ -221,8 +225,9 @@ func (l *PurchaseLogic) Purchase(req *types.PurchaseOrderRequest) (resp *types.P
|
||||
}
|
||||
// create order
|
||||
orderInfo := &order.Order{
|
||||
UserId: u.Id,
|
||||
ParentId: parentOrderID,
|
||||
UserId: u.Id,
|
||||
SubscriptionUserId: entitlement.EffectiveUserID,
|
||||
ParentId: parentOrderID,
|
||||
OrderNo: tool.GenerateTradeNo(),
|
||||
Type: orderType,
|
||||
Quantity: req.Quantity,
|
||||
@@ -237,8 +242,9 @@ func (l *PurchaseLogic) Purchase(req *types.PurchaseOrderRequest) (resp *types.P
|
||||
FeeAmount: feeAmount,
|
||||
Status: 1,
|
||||
IsNew: isNew,
|
||||
SubscribeId: targetSubscribeID,
|
||||
SubscribeToken: subscribeToken,
|
||||
SubscribeId: targetSubscribeID,
|
||||
SubscribeToken: subscribeToken,
|
||||
AppAccountToken: uuid.New().String(),
|
||||
}
|
||||
if isSingleModeRenewal {
|
||||
l.Infow("[Purchase] single mode purchase order created as renewal",
|
||||
@@ -368,6 +374,7 @@ func (l *PurchaseLogic) Purchase(req *types.PurchaseOrderRequest) (resp *types.P
|
||||
}
|
||||
|
||||
return &types.PurchaseOrderResponse{
|
||||
OrderNo: orderInfo.OrderNo,
|
||||
OrderNo: orderInfo.OrderNo,
|
||||
AppAccountToken: orderInfo.AppAccountToken,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -6,6 +6,8 @@ import (
|
||||
"math"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
|
||||
commonLogic "github.com/perfect-panel/server/internal/logic/common"
|
||||
"github.com/perfect-panel/server/internal/model/log"
|
||||
"github.com/perfect-panel/server/pkg/constant"
|
||||
@@ -182,8 +184,9 @@ func (l *RenewalLogic) Renewal(req *types.RenewalOrderRequest) (resp *types.Rene
|
||||
Method: canonicalOrderMethod(payment.Platform),
|
||||
FeeAmount: feeAmount,
|
||||
Status: 1,
|
||||
SubscribeId: userSubscribe.SubscribeId,
|
||||
SubscribeToken: userSubscribe.Token,
|
||||
SubscribeId: userSubscribe.SubscribeId,
|
||||
SubscribeToken: userSubscribe.Token,
|
||||
AppAccountToken: uuid.New().String(),
|
||||
}
|
||||
// Database transaction
|
||||
err = l.svcCtx.DB.Transaction(func(db *gorm.DB) error {
|
||||
@@ -239,6 +242,7 @@ func (l *RenewalLogic) Renewal(req *types.RenewalOrderRequest) (resp *types.Rene
|
||||
l.Infow("[Renewal] Enqueue task success", logger.Field("TaskID", taskInfo.ID))
|
||||
}
|
||||
return &types.RenewalOrderResponse{
|
||||
OrderNo: orderInfo.OrderNo,
|
||||
OrderNo: orderInfo.OrderNo,
|
||||
AppAccountToken: orderInfo.AppAccountToken,
|
||||
}, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user