2026-06-25 21:30:26 +08:00

41 lines
1.7 KiB
Go

package wallet
import (
"context"
"hyapp/pkg/xerr"
"hyapp/services/wallet-service/internal/domain/ledger"
)
// DebitGift 校验送礼扣费命令,并交给 repository 做原子落账和幂等。
func (s *Service) DebitGift(ctx context.Context, command ledger.DebitGiftCommand) (ledger.Receipt, error) {
if s == nil || s.giftLedger == nil {
return ledger.Receipt{}, xerr.New(xerr.Unavailable, "wallet repository is not configured")
}
return s.giftLedger.DebitGift(ctx, command)
}
// DebitDirectGift 校验私聊送礼扣费命令,并标记为 direct gift 账务场景后复用同一条落账链路。
func (s *Service) DebitDirectGift(ctx context.Context, command ledger.DebitGiftCommand) (ledger.Receipt, error) {
if s == nil || s.giftLedger == nil {
return ledger.Receipt{}, xerr.New(xerr.Unavailable, "wallet repository is not configured")
}
command.DirectGift = true
return s.giftLedger.DebitGift(ctx, command)
}
// DebitRobotGift 校验机器人房间专用送礼扣费命令,并强制使用 ROBOT_COIN 账务语义。
func (s *Service) DebitRobotGift(ctx context.Context, command ledger.DebitGiftCommand) (ledger.Receipt, error) {
if s == nil || s.giftLedger == nil {
return ledger.Receipt{}, xerr.New(xerr.Unavailable, "wallet repository is not configured")
}
return s.giftLedger.DebitRobotGift(ctx, command)
}
// BatchDebitGift 校验多目标送礼扣费命令,并要求 repository 在同一事务中完成全部目标结算。
func (s *Service) BatchDebitGift(ctx context.Context, command ledger.BatchDebitGiftCommand) (ledger.BatchGiftReceipt, error) {
if s == nil || s.giftLedger == nil {
return ledger.BatchGiftReceipt{}, xerr.New(xerr.Unavailable, "wallet repository is not configured")
}
return s.giftLedger.BatchDebitGift(ctx, command)
}