2026-07-05 14:55:37 +08:00

134 lines
3.2 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 resource
import (
"hyapp/services/wallet-service/internal/domain/ledger"
"strings"
)
type Resource struct {
AppCode string
ResourceID int64
ResourceCode string
ResourceType string
Name string
Status string
Grantable bool
GrantStrategy string
WalletAssetType string
WalletAssetAmount int64
PriceType string
CoinPrice int64
// GiftPointAmount 是历史字段GIFT_POINT 已下线,新资源和礼物配置只保留真实 COIN 价格。
GiftPointAmount int64
UsageScopes []string
AssetURL string
PreviewURL string
AnimationURL string
MetadataJSON string
SortOrder int32
CreatedByUserID int64
UpdatedByUserID int64
CreatedAtMS int64
UpdatedAtMS int64
ManagerGrantEnabled bool
}
type ListResourcesQuery struct {
AppCode string
ResourceType string
Status string
Keyword string
Page int32
PageSize int32
ActiveOnly bool
ManagerGrantOnly bool
}
type ResourceCommand struct {
AppCode string
ResourceID int64
ResourceCode string
ResourceType string
Name string
Status string
Grantable bool
GrantStrategy string
WalletAssetType string
WalletAssetAmount int64
PriceType string
CoinPrice int64
// GiftPointAmount 是历史字段;保存资源时固定为 0保留字段只兼容旧表结构。
GiftPointAmount int64
UsageScopes []string
AssetURL string
PreviewURL string
AnimationURL string
MetadataJSON string
SortOrder int32
OperatorUserID int64
ManagerGrantEnabled bool
}
type StatusCommand struct {
AppCode string
ID int64
StringID string
Status string
OperatorUserID int64
}
type BatchDeleteResourcesCommand struct {
AppCode string
ResourceIDs []int64
OperatorUserID int64
}
func NormalizeStatus(value string) string {
value = strings.ToLower(strings.TrimSpace(value))
if value == "" {
return StatusActive
}
return value
}
func NormalizeGrantSource(value string) string {
value = strings.ToLower(strings.TrimSpace(value))
if value == "" {
return GrantSourceAdmin
}
return value
}
func ValidResourceType(value string) bool {
switch strings.ToLower(strings.TrimSpace(value)) {
case TypeAvatarFrame, TypeProfileCard, TypeCoin, TypeVehicle, TypeChatBubble, TypeBadge, TypeFloatingScreen, TypeGift, TypeMicSeatIcon, TypeMicSeatAnimation, TypeEmojiPack:
return true
default:
return false
}
}
func NormalizeResourceType(value string) string {
return strings.ToLower(strings.TrimSpace(value))
}
func NormalizeGrantStrategy(value string) string {
return strings.ToLower(strings.TrimSpace(value))
}
func NormalizeWalletAssetType(value string) string {
return strings.ToUpper(strings.TrimSpace(value))
}
func IsWalletCredit(resource Resource) bool {
return NormalizeGrantStrategy(resource.GrantStrategy) == GrantStrategyWalletCredit
}
func IsCoinResource(resource Resource) bool {
return NormalizeResourceType(resource.ResourceType) == TypeCoin
}
func WalletAssetForCoin() string {
return ledger.AssetCoin
}