203 lines
5.5 KiB
Go
203 lines
5.5 KiB
Go
package ledger
|
|
|
|
import "strings"
|
|
|
|
const (
|
|
// AssetCoin 是用户送礼消费资产。
|
|
AssetCoin = "COIN"
|
|
// AssetCoinSellerCoin 是币商专用金币资产,只能通过币商转账兑换成玩家普通 COIN。
|
|
AssetCoinSellerCoin = "COIN_SELLER_COIN"
|
|
// AssetGiftPoint 是主播礼物积分,不能直接消费或提现。
|
|
AssetGiftPoint = "GIFT_POINT"
|
|
// AssetDiamond 是后续兑换用资产,当前只在余额模型中保留。
|
|
AssetDiamond = "DIAMOND"
|
|
// AssetUSDBalance 是主播可提现美元余额,单位由后续提现策略固定。
|
|
AssetUSDBalance = "USD_BALANCE"
|
|
|
|
// StockTypeUSDTPurchase 表示币商线下 USDT 进货后发放专用金币库存。
|
|
StockTypeUSDTPurchase = "usdt_purchase"
|
|
// StockTypeCoinCompensation 表示平台人工补偿币商专用金币库存,不计入进货金额。
|
|
StockTypeCoinCompensation = "coin_compensation"
|
|
// PaidCurrencyUSDT 是首版币商进货支持的唯一线下付款币种。
|
|
PaidCurrencyUSDT = "USDT"
|
|
)
|
|
|
|
// DebitGiftCommand 是 room-service 送礼扣费的账务命令。
|
|
type DebitGiftCommand struct {
|
|
AppCode string
|
|
CommandID string
|
|
RoomID string
|
|
SenderUserID int64
|
|
TargetUserID int64
|
|
GiftID string
|
|
GiftCount int32
|
|
PriceVersion string
|
|
RegionID int64
|
|
}
|
|
|
|
// Receipt 是账务命令落账后的稳定回执。
|
|
type Receipt struct {
|
|
BillingReceiptID string
|
|
TransactionID string
|
|
CoinSpent int64
|
|
ChargeAssetType string
|
|
ChargeAmount int64
|
|
GiftPointAdded int64
|
|
HeatValue int64
|
|
PriceVersion string
|
|
BalanceAfter int64
|
|
}
|
|
|
|
// CoinSellerTransferCommand 是币商给玩家转普通金币的账务命令。
|
|
type CoinSellerTransferCommand struct {
|
|
AppCode string
|
|
CommandID string
|
|
SellerUserID int64
|
|
TargetUserID int64
|
|
SellerRegionID int64
|
|
TargetRegionID int64
|
|
Amount int64
|
|
Reason string
|
|
}
|
|
|
|
// CoinSellerTransferReceipt 是币商转账完成后的稳定回执。
|
|
type CoinSellerTransferReceipt struct {
|
|
TransactionID string
|
|
SellerBalanceAfter int64
|
|
TargetBalanceAfter int64
|
|
Amount int64
|
|
RechargeUSDMinor int64
|
|
RechargeCurrencyCode string
|
|
RechargePolicyID int64
|
|
RechargePolicyVersion string
|
|
RechargePolicyCoinAmount int64
|
|
RechargePolicyUSDMinorUnit int64
|
|
}
|
|
|
|
// CoinSellerStockCreditCommand 是后台给币商专用金币库存入账的最小账务命令。
|
|
type CoinSellerStockCreditCommand struct {
|
|
AppCode string
|
|
CommandID string
|
|
SellerUserID int64
|
|
StockType string
|
|
CoinAmount int64
|
|
PaidCurrencyCode string
|
|
PaidAmountMicro int64
|
|
PaymentRef string
|
|
EvidenceRef string
|
|
OperatorUserID int64
|
|
Reason string
|
|
}
|
|
|
|
// CoinSellerStockCreditReceipt 是币商库存入账成功后的稳定回执。
|
|
type CoinSellerStockCreditReceipt struct {
|
|
TransactionID string
|
|
SellerUserID int64
|
|
StockType string
|
|
CoinAmount int64
|
|
PaidCurrencyCode string
|
|
PaidAmountMicro int64
|
|
CountsAsSellerRecharge bool
|
|
BalanceAfter int64
|
|
CreatedAtMS int64
|
|
}
|
|
|
|
// RechargeBill 是充值账单的只读投影;充值事实由 wallet_recharge_records 保存。
|
|
type RechargeBill struct {
|
|
AppCode string
|
|
TransactionID string
|
|
CommandID string
|
|
RechargeType string
|
|
Status string
|
|
ExternalRef string
|
|
UserID int64
|
|
SellerUserID int64
|
|
SellerRegionID int64
|
|
TargetRegionID int64
|
|
PolicyID int64
|
|
PolicyVersion string
|
|
CurrencyCode string
|
|
CoinAmount int64
|
|
USDMinorAmount int64
|
|
ExchangeCoinAmount int64
|
|
ExchangeUSDMinorAmount int64
|
|
CreatedAtMS int64
|
|
}
|
|
|
|
// ListRechargeBillsQuery 是后台查询所有充值渠道账单的筛选条件。
|
|
type ListRechargeBillsQuery struct {
|
|
AppCode string
|
|
UserID int64
|
|
SellerUserID int64
|
|
RegionID int64
|
|
RechargeType string
|
|
Status string
|
|
Keyword string
|
|
StartAtMS int64
|
|
EndAtMS int64
|
|
Page int32
|
|
PageSize int32
|
|
}
|
|
|
|
// AssetBalance 是账户当前可用/冻结余额投影。
|
|
type AssetBalance struct {
|
|
AppCode string
|
|
UserID int64
|
|
AssetType string
|
|
AvailableAmount int64
|
|
FrozenAmount int64
|
|
Version int64
|
|
UpdatedAtMs int64
|
|
}
|
|
|
|
// AdminCreditAssetCommand 是后台手动入账的最小审计命令。
|
|
type AdminCreditAssetCommand struct {
|
|
AppCode string
|
|
CommandID string
|
|
TargetUserID int64
|
|
AssetType string
|
|
Amount int64
|
|
OperatorUserID int64
|
|
Reason string
|
|
EvidenceRef string
|
|
}
|
|
|
|
// ValidAssetType 限定账本允许落账的资产类型,避免写入任意字符串资产。
|
|
func ValidAssetType(assetType string) bool {
|
|
switch assetType {
|
|
case AssetCoin, AssetCoinSellerCoin, AssetGiftPoint, AssetDiamond, AssetUSDBalance:
|
|
return true
|
|
default:
|
|
return false
|
|
}
|
|
}
|
|
|
|
func NormalizeGiftChargeAssetType(assetType string) string {
|
|
switch strings.ToUpper(strings.TrimSpace(assetType)) {
|
|
case AssetDiamond:
|
|
return AssetDiamond
|
|
default:
|
|
return AssetCoin
|
|
}
|
|
}
|
|
|
|
func ValidGiftChargeAssetType(assetType string) bool {
|
|
switch strings.ToUpper(strings.TrimSpace(assetType)) {
|
|
case AssetCoin, AssetDiamond:
|
|
return true
|
|
default:
|
|
return false
|
|
}
|
|
}
|
|
|
|
func NormalizeCoinSellerStockType(stockType string) string {
|
|
switch strings.ToLower(strings.TrimSpace(stockType)) {
|
|
case StockTypeUSDTPurchase:
|
|
return StockTypeUSDTPurchase
|
|
case StockTypeCoinCompensation:
|
|
return StockTypeCoinCompensation
|
|
default:
|
|
return ""
|
|
}
|
|
}
|