138 lines
3.1 KiB
Go
138 lines
3.1 KiB
Go
package resource
|
||
|
||
import (
|
||
"hyapp/services/wallet-service/internal/domain/ledger"
|
||
"strings"
|
||
)
|
||
|
||
type ResourceShopItem struct {
|
||
AppCode string
|
||
ShopItemID int64
|
||
ResourceID int64
|
||
Resource Resource
|
||
Status string
|
||
DurationDays int32
|
||
PriceType string
|
||
CoinPrice int64
|
||
EffectiveFromMS int64
|
||
EffectiveToMS int64
|
||
SortOrder int32
|
||
CreatedByUserID int64
|
||
UpdatedByUserID int64
|
||
CreatedAtMS int64
|
||
UpdatedAtMS int64
|
||
}
|
||
|
||
type ResourceShopPurchaseOrder struct {
|
||
AppCode string
|
||
OrderID string
|
||
CommandID string
|
||
UserID int64
|
||
ShopItemID int64
|
||
ResourceID int64
|
||
Resource Resource
|
||
ResourceSnapshotJSON string
|
||
DurationDays int32
|
||
PriceCoin int64
|
||
Status string
|
||
WalletTransactionID string
|
||
ResourceGrantID string
|
||
EntitlementID string
|
||
CreatedAtMS int64
|
||
UpdatedAtMS int64
|
||
}
|
||
|
||
type ResourceShopItemInput struct {
|
||
ShopItemID int64
|
||
ResourceID int64
|
||
Status string
|
||
DurationDays int32
|
||
// CoinPrice 新建为 0 时使用资源列表价,更新已有规格为 0 时保留当前售价;落库后各规格价格互相独立。
|
||
CoinPrice int64
|
||
EffectiveFromMS int64
|
||
EffectiveToMS int64
|
||
SortOrder int32
|
||
}
|
||
|
||
type ListResourceShopItemsQuery struct {
|
||
AppCode string
|
||
ResourceType string
|
||
Status string
|
||
Keyword string
|
||
Page int32
|
||
PageSize int32
|
||
ActiveOnly bool
|
||
}
|
||
|
||
type ListResourceShopPurchaseOrdersQuery struct {
|
||
AppCode string
|
||
UserID int64
|
||
ResourceType string
|
||
Status string
|
||
Keyword string
|
||
Page int32
|
||
PageSize int32
|
||
}
|
||
|
||
type ResourceShopItemsCommand struct {
|
||
AppCode string
|
||
Items []ResourceShopItemInput
|
||
OperatorUserID int64
|
||
}
|
||
|
||
type ResourceShopItemStatusCommand struct {
|
||
AppCode string
|
||
ShopItemID int64
|
||
Status string
|
||
OperatorUserID int64
|
||
}
|
||
|
||
type ResourceShopPurchaseCommand struct {
|
||
AppCode string
|
||
CommandID string
|
||
UserID int64
|
||
ShopItemID int64
|
||
}
|
||
|
||
type ResourceShopPurchaseReceipt struct {
|
||
OrderID string
|
||
TransactionID string
|
||
ShopItem ResourceShopItem
|
||
Resource UserResourceEntitlement
|
||
Balance ledger.AssetBalance
|
||
CoinSpent int64
|
||
GrantID string
|
||
}
|
||
|
||
func ResourceTypeSellableInShop(value string) bool {
|
||
switch NormalizeResourceType(value) {
|
||
// 飘窗是有期限的用户装扮,购买后下发 entitlement;不能按 gift 等消耗品处理。
|
||
case TypeAvatarFrame, TypeProfileCard, TypeVehicle, TypeChatBubble, TypeBadge, TypeFloatingScreen, TypeMicSeatIcon, TypeMicSeatAnimation:
|
||
return true
|
||
default:
|
||
return false
|
||
}
|
||
}
|
||
|
||
func ValidShopDurationDays(value int32) bool {
|
||
switch value {
|
||
case ShopDurationOneDay, ShopDurationThreeDays, ShopDurationSevenDays:
|
||
return true
|
||
default:
|
||
return false
|
||
}
|
||
}
|
||
|
||
func NormalizePriceType(value string) string {
|
||
return strings.ToLower(strings.TrimSpace(value))
|
||
}
|
||
|
||
func ValidPriceType(value string) bool {
|
||
switch NormalizePriceType(value) {
|
||
case PriceTypeCoin, PriceTypeFree:
|
||
return true
|
||
default:
|
||
return false
|
||
}
|
||
}
|