修复 Context 改造后的编译问题

This commit is contained in:
yml2213
2026-06-10 09:43:49 +08:00
parent b377f8350b
commit 334436f381
13 changed files with 193 additions and 189 deletions
+19 -18
View File
@@ -1,6 +1,7 @@
package payment
import (
"context"
"errors"
"strings"
)
@@ -33,81 +34,81 @@ func NewService(repo *Repository, appEnv ...string) *Service {
}
}
func (s *Service) Start(userID uint64, orderID uint64, req StartPaymentRequest, clientIP string) (*PaymentDTO, error) {
func (s *Service) Start(ctx context.Context, userID uint64, orderID uint64, req StartPaymentRequest, clientIP string) (*PaymentDTO, error) {
if s.repo == nil {
return nil, ErrDependencyUnavailable
}
if userID == 0 || orderID == 0 {
return nil, ErrPaymentCannotStart
}
return s.repo.Start(userID, orderID, req, clientIP)
return s.repo.Start(ctx, userID, orderID, req, clientIP)
}
func (s *Service) Query(userID uint64, orderID uint64) (*PaymentDTO, error) {
func (s *Service) Query(ctx context.Context, userID uint64, orderID uint64) (*PaymentDTO, error) {
if s.repo == nil {
return nil, ErrDependencyUnavailable
}
if userID == 0 || orderID == 0 {
return nil, ErrPaymentNotFound
}
return s.repo.Query(userID, orderID)
return s.repo.Query(ctx, userID, orderID)
}
func (s *Service) StartWalletRecharge(userID uint64, req WalletRechargePaymentRequest, clientIP string) (*PaymentDTO, error) {
func (s *Service) StartWalletRecharge(ctx context.Context, userID uint64, req WalletRechargePaymentRequest, clientIP string) (*PaymentDTO, error) {
if s.repo == nil {
return nil, ErrDependencyUnavailable
}
if !s.walletRechargeEnabled {
return nil, ErrWalletRechargeDisabled
}
return s.repo.StartWalletRecharge(userID, req, clientIP)
return s.repo.StartWalletRecharge(ctx, userID, req, clientIP)
}
func (s *Service) QueryWalletRecharge(userID uint64, paymentID uint64) (*PaymentDTO, error) {
func (s *Service) QueryWalletRecharge(ctx context.Context, userID uint64, paymentID uint64) (*PaymentDTO, error) {
if s.repo == nil {
return nil, ErrDependencyUnavailable
}
if userID == 0 || paymentID == 0 {
return nil, ErrPaymentNotFound
}
return s.repo.QueryWalletRecharge(userID, paymentID)
return s.repo.QueryWalletRecharge(ctx, userID, paymentID)
}
func (s *Service) HandleLeshuaNotify(params map[string]string, rawPayload string, contentType string) (*NotifyResult, error) {
func (s *Service) HandleLeshuaNotify(ctx context.Context, params map[string]string, rawPayload string, contentType string) (*NotifyResult, error) {
if s.repo == nil {
return nil, ErrDependencyUnavailable
}
return s.repo.HandleLeshuaNotify(params, rawPayload, contentType)
return s.repo.HandleLeshuaNotify(ctx, params, rawPayload, contentType)
}
func (s *Service) HandleNotify(provider string, params map[string]string, rawPayload string, contentType string, authorization string) (*NotifyResult, error) {
func (s *Service) HandleNotify(ctx context.Context, provider string, params map[string]string, rawPayload string, contentType string, authorization string) (*NotifyResult, error) {
if s.repo == nil {
return nil, ErrDependencyUnavailable
}
return s.repo.HandleNotify(provider, params, rawPayload, contentType, authorization)
return s.repo.HandleNotify(ctx, provider, params, rawPayload, contentType, authorization)
}
func (s *Service) StartRefund(orderID uint64, refundAmountCent int64, bizType string, remark string) (*RefundDTO, error) {
func (s *Service) StartRefund(ctx context.Context, orderID uint64, refundAmountCent int64, bizType string, remark string) (*RefundDTO, error) {
if s.repo == nil {
return nil, ErrDependencyUnavailable
}
if orderID == 0 || refundAmountCent <= 0 {
return nil, ErrRefundCannotStart
}
return s.repo.StartRefund(orderID, refundAmountCent, bizType, remark)
return s.repo.StartRefund(ctx, orderID, refundAmountCent, bizType, remark)
}
func (s *Service) QueryRefundStatus(orderID uint64) (*RefundDTO, error) {
func (s *Service) QueryRefundStatus(ctx context.Context, orderID uint64) (*RefundDTO, error) {
if s.repo == nil {
return nil, ErrDependencyUnavailable
}
if orderID == 0 {
return nil, ErrPaymentNotFound
}
return s.repo.QueryRefundStatus(orderID)
return s.repo.QueryRefundStatus(ctx, orderID)
}
func (s *Service) AdminList(query AdminPaymentQuery) (*PaginatedResult, error) {
func (s *Service) AdminList(ctx context.Context, query AdminPaymentQuery) (*PaginatedResult, error) {
if s.repo == nil {
return nil, ErrDependencyUnavailable
}
@@ -120,5 +121,5 @@ func (s *Service) AdminList(query AdminPaymentQuery) (*PaginatedResult, error) {
if query.PageSize > 100 {
query.PageSize = 100
}
return s.repo.AdminList(query)
return s.repo.AdminList(ctx, query)
}