2026-07-12 17:38:48 +08:00

58 lines
2.9 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package grpc
import (
"context"
walletv1 "hyapp.local/api/proto/wallet/v1"
"hyapp/pkg/xerr"
"hyapp/services/wallet-service/internal/domain/ledger"
)
// ListPointWithdrawalCoinSellers 返回 wallet 侧已执行 app/status/国家过滤的可信白名单。
func (s *Server) ListPointWithdrawalCoinSellers(ctx context.Context, req *walletv1.ListPointWithdrawalCoinSellersRequest) (*walletv1.ListPointWithdrawalCoinSellersResponse, error) {
items, err := s.svc.ListPointWithdrawalCoinSellers(ctx, req.GetAppCode(), req.GetCountryCode(), req.GetIncludeDisabled())
if err != nil {
return nil, xerr.ToGRPCError(err)
}
response := &walletv1.ListPointWithdrawalCoinSellersResponse{Sellers: make([]*walletv1.PointWithdrawalCoinSellerConfig, 0, len(items))}
for _, item := range items {
response.Sellers = append(response.Sellers, &walletv1.PointWithdrawalCoinSellerConfig{
AppCode: item.AppCode, SellerUserId: item.SellerUserID, SortOrder: int32(item.SortOrder),
PointAmount: item.PointAmount, SellerCoinAmount: item.SellerCoinAmount,
ServiceCountryCodes: append([]string(nil), item.ServiceCountryCodes...), Status: item.Status,
CreatedAtMs: item.CreatedAtMS, UpdatedAtMs: item.UpdatedAtMS,
})
}
return response, nil
}
// TransferPointToCoinSeller 不接受兑换比例字段,确保所有调用方都只能使用数据库白名单快照。
func (s *Server) TransferPointToCoinSeller(ctx context.Context, req *walletv1.TransferPointToCoinSellerRequest) (*walletv1.TransferPointToCoinSellerResponse, error) {
receipt, err := s.svc.TransferPointToCoinSeller(ctx, ledger.PointToCoinSellerCommand{
AppCode: req.GetAppCode(), CommandID: req.GetCommandId(), SourceUserID: req.GetSourceUserId(),
SellerUserID: req.GetSellerUserId(), PointAmount: req.GetPointAmount(),
SourceCountryCode: req.GetSourceCountryCode(), Reason: req.GetReason(),
})
if err != nil {
return nil, xerr.ToGRPCError(err)
}
return &walletv1.TransferPointToCoinSellerResponse{
TransactionId: receipt.TransactionID, SourcePointBalanceAfter: receipt.SourcePointBalanceAfter,
SellerBalanceAfter: receipt.SellerBalanceAfter, PointAmount: receipt.PointAmount,
SellerCoinAmount: receipt.SellerCoinAmount, RatioPointAmount: receipt.RatioPointAmount,
RatioSellerCoinAmount: receipt.RatioSellerCoinAmount,
}, nil
}
// GetPointWithdrawalConfig 暴露政策编译后的最小运行参数H5 不解析 Admin rule_json。
func (s *Server) GetPointWithdrawalConfig(ctx context.Context, req *walletv1.GetPointWithdrawalConfigRequest) (*walletv1.GetPointWithdrawalConfigResponse, error) {
config, err := s.svc.GetPointWithdrawalConfig(ctx, req.GetAppCode(), req.GetRegionId(), req.GetNowMs())
if err != nil {
return nil, xerr.ToGRPCError(err)
}
return &walletv1.GetPointWithdrawalConfigResponse{
Found: config.Found, PointsPerUsd: config.PointsPerUSD, FeeBps: int32(config.FeeBPS),
MinimumPoints: config.MinimumPoints, PolicyInstanceCode: config.PolicyInstanceCode,
}, nil
}