feat(tenant): 增加双站订单视图与租户统计
This commit is contained in:
@@ -206,6 +206,9 @@ func (s *Service) HandoffRecordsAdmin(ctx context.Context, orderID uint64) ([]Ha
|
||||
if s.repo == nil {
|
||||
return nil, ErrDependencyUnavailable
|
||||
}
|
||||
if err := s.ensureAdminOrderAccess(ctx, orderID); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return s.repo.HandoffRecordsAdmin(ctx, orderID)
|
||||
}
|
||||
|
||||
@@ -213,6 +216,9 @@ func (s *Service) ProcessEventsAdmin(ctx context.Context, orderID uint64) ([]Pro
|
||||
if s.repo == nil {
|
||||
return nil, ErrDependencyUnavailable
|
||||
}
|
||||
if err := s.ensureAdminOrderAccess(ctx, orderID); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return s.repo.ProcessEventsAdmin(ctx, orderID)
|
||||
}
|
||||
|
||||
@@ -223,6 +229,9 @@ func (s *Service) AdminClose(ctx context.Context, adminID uint64, orderID uint64
|
||||
if orderID == 0 || req.Reason == "" {
|
||||
return ErrOrderCannotComplete
|
||||
}
|
||||
if err := s.ensureAdminOrderAccess(ctx, orderID); err != nil {
|
||||
return err
|
||||
}
|
||||
return s.repo.AdminClose(ctx, adminID, orderID, req, meta)
|
||||
}
|
||||
|
||||
@@ -233,6 +242,9 @@ func (s *Service) AdminMarkAbnormal(ctx context.Context, adminID uint64, orderID
|
||||
if orderID == 0 || req.Reason == "" {
|
||||
return ErrOrderCannotComplete
|
||||
}
|
||||
if err := s.ensureAdminOrderAccess(ctx, orderID); err != nil {
|
||||
return err
|
||||
}
|
||||
return s.repo.AdminMarkAbnormal(ctx, adminID, orderID, req, meta)
|
||||
}
|
||||
|
||||
@@ -243,6 +255,9 @@ func (s *Service) AdminSeal(ctx context.Context, adminID uint64, orderID uint64,
|
||||
if orderID == 0 || req.Reason == "" {
|
||||
return ErrOrderCannotComplete
|
||||
}
|
||||
if err := s.ensureAdminOrderAccess(ctx, orderID); err != nil {
|
||||
return err
|
||||
}
|
||||
return s.repo.AdminSeal(ctx, adminID, orderID, req, meta)
|
||||
}
|
||||
|
||||
@@ -253,6 +268,9 @@ func (s *Service) AdminResetHandoff(ctx context.Context, adminID uint64, orderID
|
||||
if orderID == 0 || req.Reason == "" {
|
||||
return ErrOrderCannotResetHandoff
|
||||
}
|
||||
if err := s.ensureAdminOrderCapability(ctx, orderID, tenantOrderCapabilityHandoff); err != nil {
|
||||
return err
|
||||
}
|
||||
return s.repo.AdminResetHandoff(ctx, adminID, orderID, req, meta)
|
||||
}
|
||||
|
||||
@@ -263,6 +281,9 @@ func (s *Service) AdminPlatformHandoff(ctx context.Context, adminID uint64, orde
|
||||
if orderID == 0 || req.Content == "" || req.Reason == "" {
|
||||
return nil, ErrOrderCannotHandoff
|
||||
}
|
||||
if err := s.ensureAdminOrderCapability(ctx, orderID, tenantOrderCapabilityHandoff); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return s.repo.AdminPlatformHandoff(ctx, adminID, orderID, req, meta)
|
||||
}
|
||||
|
||||
@@ -273,6 +294,9 @@ func (s *Service) AdminForceHandoff(ctx context.Context, adminID uint64, orderID
|
||||
if orderID == 0 || req.Reason == "" {
|
||||
return ErrOrderCannotForceHandoff
|
||||
}
|
||||
if err := s.ensureAdminOrderCapability(ctx, orderID, tenantOrderCapabilityHandoff); err != nil {
|
||||
return err
|
||||
}
|
||||
return s.repo.AdminForceHandoff(ctx, adminID, orderID, req, meta)
|
||||
}
|
||||
|
||||
@@ -283,6 +307,9 @@ func (s *Service) AdminPlatformCheckoutConfirm(ctx context.Context, adminID uint
|
||||
if orderID == 0 || req.Reason == "" {
|
||||
return ErrCheckoutCannotConfirm
|
||||
}
|
||||
if err := s.ensureAdminOrderCapability(ctx, orderID, tenantOrderCapabilityCheckout); err != nil {
|
||||
return err
|
||||
}
|
||||
return s.repo.AdminPlatformCheckoutConfirm(ctx, adminID, orderID, req, meta)
|
||||
}
|
||||
|
||||
@@ -293,6 +320,9 @@ func (s *Service) AdminPlatformCheckoutCounter(ctx context.Context, adminID uint
|
||||
if orderID == 0 || req.Reason == "" {
|
||||
return nil, ErrCheckoutCannotCounter
|
||||
}
|
||||
if err := s.ensureAdminOrderCapability(ctx, orderID, tenantOrderCapabilityCheckout); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return s.repo.AdminPlatformCheckoutCounter(ctx, adminID, orderID, req, meta)
|
||||
}
|
||||
|
||||
@@ -303,6 +333,9 @@ func (s *Service) AdminPlatformCheckoutDispute(ctx context.Context, adminID uint
|
||||
if orderID == 0 || req.Reason == "" {
|
||||
return ErrCheckoutCannotCounter
|
||||
}
|
||||
if err := s.ensureAdminOrderCapability(ctx, orderID, tenantOrderCapabilityCheckout); err != nil {
|
||||
return err
|
||||
}
|
||||
return s.repo.AdminPlatformCheckoutDispute(ctx, adminID, orderID, req, meta)
|
||||
}
|
||||
|
||||
@@ -313,6 +346,9 @@ func (s *Service) AdminMarkOfflineSettlement(ctx context.Context, adminID uint64
|
||||
if orderID == 0 {
|
||||
return ErrOfflineSettlementCannotMark
|
||||
}
|
||||
if err := s.ensureAdminOrderCapability(ctx, orderID, tenantOrderCapabilityHandoff); err != nil {
|
||||
return err
|
||||
}
|
||||
return s.repo.AdminMarkOfflineSettlement(ctx, adminID, orderID, req, meta)
|
||||
}
|
||||
|
||||
@@ -323,6 +359,9 @@ func (s *Service) AdminHoldDeposit(ctx context.Context, adminID uint64, orderID
|
||||
if orderID == 0 || req.Reason == "" {
|
||||
return ErrDepositCannotHold
|
||||
}
|
||||
if err := s.ensureAdminOrderCapability(ctx, orderID, tenantOrderCapabilityRefund); err != nil {
|
||||
return err
|
||||
}
|
||||
return s.repo.AdminHoldDeposit(ctx, adminID, orderID, req, meta)
|
||||
}
|
||||
|
||||
@@ -333,6 +372,9 @@ func (s *Service) AdminReleaseDeposit(ctx context.Context, adminID uint64, order
|
||||
if orderID == 0 || req.Reason == "" {
|
||||
return ErrDepositCannotHold
|
||||
}
|
||||
if err := s.ensureAdminOrderCapability(ctx, orderID, tenantOrderCapabilityRefund); err != nil {
|
||||
return err
|
||||
}
|
||||
return s.repo.AdminReleaseDeposit(ctx, adminID, orderID, req, meta)
|
||||
}
|
||||
|
||||
@@ -343,6 +385,9 @@ func (s *Service) AdminRefund(ctx context.Context, orderID uint64) (*RefundStatu
|
||||
if orderID == 0 {
|
||||
return nil, ErrOrderCannotComplete
|
||||
}
|
||||
if err := s.ensureAdminOrderCapability(ctx, orderID, tenantOrderCapabilityRefund); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return s.repo.AdminRefund(ctx, orderID)
|
||||
}
|
||||
|
||||
@@ -353,6 +398,9 @@ func (s *Service) AdminRefundStatus(ctx context.Context, orderID uint64) (*Refun
|
||||
if orderID == 0 {
|
||||
return nil, ErrOrderCannotComplete
|
||||
}
|
||||
if err := s.ensureAdminOrderCapability(ctx, orderID, tenantOrderCapabilityRefund); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return s.repo.AdminRefundStatus(ctx, orderID)
|
||||
}
|
||||
|
||||
@@ -363,6 +411,9 @@ func (s *Service) AdminApproveRefund(ctx context.Context, orderID uint64) error
|
||||
if orderID == 0 {
|
||||
return ErrOrderCannotComplete
|
||||
}
|
||||
if err := s.ensureAdminOrderCapability(ctx, orderID, tenantOrderCapabilityRefund); err != nil {
|
||||
return err
|
||||
}
|
||||
return s.repo.AdminApproveRefund(ctx, orderID)
|
||||
}
|
||||
|
||||
@@ -373,6 +424,9 @@ func (s *Service) AdminRejectRefund(ctx context.Context, orderID uint64, action
|
||||
if orderID == 0 {
|
||||
return ErrOrderCannotComplete
|
||||
}
|
||||
if err := s.ensureAdminOrderCapability(ctx, orderID, tenantOrderCapabilityRefund); err != nil {
|
||||
return err
|
||||
}
|
||||
return s.repo.AdminRejectRefund(ctx, orderID, action)
|
||||
}
|
||||
|
||||
@@ -396,3 +450,23 @@ func (s *Service) FindForUser(ctx context.Context, userID uint64, orderID uint64
|
||||
}
|
||||
return s.repo.FindForUser(ctx, userID, orderID, siteCode...)
|
||||
}
|
||||
|
||||
func (s *Service) ensureAdminOrderAccess(ctx context.Context, orderID uint64) error {
|
||||
if s.repo == nil {
|
||||
return ErrDependencyUnavailable
|
||||
}
|
||||
if orderID == 0 {
|
||||
return ErrOrderCannotComplete
|
||||
}
|
||||
return s.repo.EnsureAdminOrderAccess(ctx, orderID)
|
||||
}
|
||||
|
||||
func (s *Service) ensureAdminOrderCapability(ctx context.Context, orderID uint64, capability string) error {
|
||||
if s.repo == nil {
|
||||
return ErrDependencyUnavailable
|
||||
}
|
||||
if orderID == 0 {
|
||||
return ErrOrderCannotComplete
|
||||
}
|
||||
return s.repo.EnsureAdminOrderCapability(ctx, orderID, capability)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user