99 lines
3.9 KiB
Go
99 lines
3.9 KiB
Go
package fields
|
||
|
||
import (
|
||
"encoding/json"
|
||
"time"
|
||
|
||
"quyun/v2/pkg/consts"
|
||
)
|
||
|
||
// OrdersSnapshot 是 orders.snapshot 的统一包裹结构(判别联合)。
|
||
//
|
||
// 设计目标:
|
||
// - 同一字段支持多种快照结构(按 kind 区分)。
|
||
// - 查询/展示时可以先看 kind,再按需解析 data。
|
||
// - 兼容历史数据:如果旧数据没有 kind/data,则按 legacy 处理(data = 原始 JSON)。
|
||
type OrdersSnapshot struct {
|
||
// Kind 快照类型:建议与订单类型对齐(例如 content_purchase)。
|
||
Kind string `json:"kind"`
|
||
// Data 具体快照数据(按 Kind 对应不同结构)。
|
||
Data json.RawMessage `json:"data"`
|
||
}
|
||
|
||
type ordersSnapshotWire struct {
|
||
Kind string `json:"kind"`
|
||
Data json.RawMessage `json:"data"`
|
||
}
|
||
|
||
func (snapshot *OrdersSnapshot) UnmarshalJSON(raw []byte) error {
|
||
var wire ordersSnapshotWire
|
||
if err := json.Unmarshal(raw, &wire); err == nil && (wire.Kind != "" || wire.Data != nil) {
|
||
snapshot.Kind = wire.Kind
|
||
snapshot.Data = wire.Data
|
||
|
||
return nil
|
||
}
|
||
|
||
// 兼容旧结构:旧 snapshot 通常是一个扁平对象(没有 kind/data)。
|
||
snapshot.Kind = "legacy"
|
||
snapshot.Data = append(snapshot.Data[:0], raw...)
|
||
|
||
return nil
|
||
}
|
||
|
||
// OrdersContentPurchaseSnapshot 为“内容购买订单”的下单快照(用于历史展示与争议审计)。
|
||
type OrdersContentPurchaseSnapshot struct {
|
||
// ContentID 内容ID。
|
||
ContentID int64 `json:"content_id"`
|
||
// ContentTitle 内容标题(下单时快照,避免事后改名影响历史订单展示)。
|
||
ContentTitle string `json:"content_title"`
|
||
// ContentUserID 内容作者用户ID(用于审计与后续分成扩展)。
|
||
ContentUserID int64 `json:"content_user_id"`
|
||
// ContentVisibility 下单时的可见性快照。
|
||
ContentVisibility consts.ContentVisibility `json:"content_visibility"`
|
||
// PreviewSeconds 下单时的试看秒数快照。
|
||
PreviewSeconds int32 `json:"preview_seconds"`
|
||
// PreviewDownloadable 下单时的试看是否可下载快照(当前固定为 false)。
|
||
PreviewDownloadable bool `json:"preview_downloadable"`
|
||
// Currency 币种:当前固定 CNY(金额单位为分)。
|
||
Currency consts.Currency `json:"currency"`
|
||
// PriceAmount 基础价格(分)。
|
||
PriceAmount int64 `json:"price_amount"`
|
||
// DiscountType 折扣类型(none/percent/amount)。
|
||
DiscountType consts.DiscountType `json:"discount_type"`
|
||
// DiscountValue 折扣值(percent=0-100;amount=分)。
|
||
DiscountValue int64 `json:"discount_value"`
|
||
// DiscountStartAt 折扣开始时间(可选)。
|
||
DiscountStartAt *time.Time `json:"discount_start_at,omitempty"`
|
||
// DiscountEndAt 折扣结束时间(可选)。
|
||
DiscountEndAt *time.Time `json:"discount_end_at,omitempty"`
|
||
// AmountOriginal 原价金额(分)。
|
||
AmountOriginal int64 `json:"amount_original"`
|
||
// AmountDiscount 优惠金额(分)。
|
||
AmountDiscount int64 `json:"amount_discount"`
|
||
// AmountPaid 实付金额(分)。
|
||
AmountPaid int64 `json:"amount_paid"`
|
||
// PurchaseAt 下单时间(逻辑时间)。
|
||
PurchaseAt time.Time `json:"purchase_at"`
|
||
// PurchaseIdempotency 幂等键(可选)。
|
||
PurchaseIdempotency string `json:"purchase_idempotency_key,omitempty"`
|
||
// PurchasePricingNotes 价格计算补充说明(可选,便于排查争议)。
|
||
PurchasePricingNotes string `json:"purchase_pricing_notes,omitempty"`
|
||
}
|
||
|
||
// OrdersWithdrawalSnapshot 为“创作者提现订单”的快照信息(用于打款核对与审计追溯)。
|
||
type OrdersWithdrawalSnapshot struct {
|
||
// Method 提现方式(wallet/external)。
|
||
Method string `json:"method"`
|
||
// AccountID 收款账户ID(来源 payout_accounts)。
|
||
AccountID int64 `json:"account_id"`
|
||
// AccountType 收款账户类型(bank/alipay)。
|
||
AccountType string `json:"account_type"`
|
||
// AccountName 收款账户名称/开户行。
|
||
AccountName string `json:"account_name"`
|
||
// Account 收款账号。
|
||
Account string `json:"account"`
|
||
// AccountRealname 收款人姓名。
|
||
AccountRealname string `json:"account_realname"`
|
||
}
|