refactor: 改造订单和资产充值 Service,支持动态支付配置

- order/service.go: 注入 wechatConfigService,CreateH5Order/CreateAdminOrder 下单时查询 active 配置并记录 payment_config_id;无配置时拒绝第三方支付;WechatPayJSAPI/WechatPayH5/FuiouPayJSAPI/FuiouPayMiniApp 添加 TODO 留桩
- recharge/service.go: Create 方法记录 payment_config_id,HandlePaymentCallback 留桩

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
2026-03-16 23:30:05 +08:00
parent 1980c846f2
commit 269769bfe4
2 changed files with 72 additions and 1 deletions

View File

@@ -28,6 +28,11 @@ type ForceRechargeRequirement struct {
FirstCommissionPaid bool `json:"first_commission_paid"` // 一次性佣金是否已发放
}
// WechatConfigServiceInterface 支付配置服务接口
type WechatConfigServiceInterface interface {
GetActiveConfig(ctx context.Context) (*model.WechatConfig, error)
}
// Service 充值服务
// 负责资产钱包IoT卡/设备)的充值订单创建、预检、支付回调处理等业务逻辑
type Service struct {
@@ -40,6 +45,7 @@ type Service struct {
shopSeriesAllocationStore *postgres.ShopSeriesAllocationStore
packageSeriesStore *postgres.PackageSeriesStore
commissionRecordStore *postgres.CommissionRecordStore
wechatConfigService WechatConfigServiceInterface
logger *zap.Logger
}
@@ -54,6 +60,7 @@ func New(
shopSeriesAllocationStore *postgres.ShopSeriesAllocationStore,
packageSeriesStore *postgres.PackageSeriesStore,
commissionRecordStore *postgres.CommissionRecordStore,
wechatConfigService WechatConfigServiceInterface,
logger *zap.Logger,
) *Service {
return &Service{
@@ -66,6 +73,7 @@ func New(
shopSeriesAllocationStore: shopSeriesAllocationStore,
packageSeriesStore: packageSeriesStore,
commissionRecordStore: commissionRecordStore,
wechatConfigService: wechatConfigService,
logger: logger,
}
}
@@ -114,7 +122,19 @@ func (s *Service) Create(ctx context.Context, req *dto.CreateRechargeRequest, us
// 4. 生成充值订单号
rechargeNo := s.generateRechargeNo()
// 5. 创建充值订单
// 5. 查询当前生效的支付配置
var paymentConfigID *uint
if req.PaymentMethod == "wechat" || req.PaymentMethod == "alipay" {
activeConfig, err := s.wechatConfigService.GetActiveConfig(ctx)
if err != nil {
s.logger.Warn("查询生效支付配置失败", zap.Error(err))
}
if activeConfig != nil {
paymentConfigID = &activeConfig.ID
}
}
// 6. 创建充值订单
recharge := &model.AssetRechargeRecord{
UserID: userID,
AssetWalletID: wallet.ID,
@@ -123,6 +143,7 @@ func (s *Service) Create(ctx context.Context, req *dto.CreateRechargeRequest, us
RechargeNo: rechargeNo,
Amount: req.Amount,
PaymentMethod: req.PaymentMethod,
PaymentConfigID: paymentConfigID,
Status: constants.RechargeStatusPending,
ShopIDTag: wallet.ShopIDTag,
EnterpriseIDTag: wallet.EnterpriseIDTag,
@@ -247,6 +268,7 @@ func (s *Service) List(ctx context.Context, req *dto.RechargeListRequest, userID
// HandlePaymentCallback 支付回调处理
// 支持幂等性检查、事务处理、更新余额、触发佣金
// TODO: 按 payment_config_id 加载配置验签(当前留桩,验签由外层处理)
func (s *Service) HandlePaymentCallback(ctx context.Context, rechargeNo string, paymentMethod string, paymentTransactionID string) error {
// 1. 查询充值订单
recharge, err := s.assetRechargeStore.GetByRechargeNo(ctx, rechargeNo)