114 lines
5.1 KiB
Go
114 lines
5.1 KiB
Go
package model
|
|
|
|
import (
|
|
"time"
|
|
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
// 用户角色
|
|
const (
|
|
RoleAdmin = "admin" // 管理员
|
|
RoleDistributor = "distributor" // 分销商
|
|
)
|
|
|
|
// User 系统用户
|
|
type User struct {
|
|
ID uint `gorm:"primarykey" json:"id"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
|
|
|
|
Username string `gorm:"uniqueIndex;size:64;not null" json:"username"`
|
|
PasswordHash string `gorm:"size:255;not null" json:"-"`
|
|
Nickname string `gorm:"size:64" json:"nickname"`
|
|
Role string `gorm:"size:32;not null;default:distributor" json:"role"`
|
|
Status int `gorm:"default:1" json:"status"` // 1启用 0禁用
|
|
InviteCode string `gorm:"uniqueIndex;size:32" json:"invite_code"`
|
|
ParentID *uint `gorm:"index" json:"parent_id"` // 上级分销商
|
|
}
|
|
|
|
// Skin 游戏皮肤商品
|
|
type Skin struct {
|
|
ID uint `gorm:"primarykey" json:"id"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
|
|
|
|
MerchantID uint `gorm:"index;uniqueIndex:idx_skins_merchant_sku;not null;default:0" json:"merchant_id"`
|
|
Name string `gorm:"size:128;not null" json:"name"` // 中文名(展示用,保持原名)
|
|
SKU string `gorm:"uniqueIndex:idx_skins_merchant_sku;size:64;not null" json:"sku"` // 英文固定标识
|
|
Game string `gorm:"size:64;index" json:"game"` // 所属游戏
|
|
Category string `gorm:"size:64;index" json:"category"` // 品类:套装/背包/...
|
|
CoverURL string `gorm:"size:512" json:"cover_url"`
|
|
Price float64 `gorm:"not null;default:0" json:"price"` // 售价
|
|
CostPrice float64 `gorm:"default:0" json:"cost_price"` // 成本价
|
|
Commission float64 `gorm:"default:0" json:"commission"` // 佣金比例 0-1
|
|
Stock int `gorm:"default:0" json:"stock"` // -1 无限
|
|
Status int `gorm:"default:1" json:"status"` // 1上架 0下架
|
|
Description string `gorm:"type:text" json:"description"`
|
|
}
|
|
|
|
// Order 订单
|
|
type Order struct {
|
|
ID uint `gorm:"primarykey" json:"id"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
|
|
|
|
MerchantID uint `gorm:"index;not null;default:0" json:"merchant_id"`
|
|
OrderNo string `gorm:"uniqueIndex;size:64;not null" json:"order_no"`
|
|
SkinID uint `gorm:"index;not null" json:"skin_id"`
|
|
Skin *Skin `gorm:"foreignKey:SkinID" json:"skin,omitempty"`
|
|
DistributorID uint `gorm:"index;not null" json:"distributor_id"`
|
|
Distributor *User `gorm:"foreignKey:DistributorID" json:"distributor,omitempty"`
|
|
BuyerName string `gorm:"size:64" json:"buyer_name"`
|
|
Amount float64 `gorm:"not null" json:"amount"`
|
|
CommissionAmt float64 `gorm:"default:0" json:"commission_amt"`
|
|
Status string `gorm:"size:32;default:pending;index" json:"status"`
|
|
Remark string `gorm:"size:255" json:"remark"`
|
|
|
|
// 发货相关(上游皮肤源头对接)
|
|
ProviderOrderNo string `gorm:"size:64;index" json:"provider_order_no"` // 上游单号
|
|
ShippedAt *time.Time `json:"shipped_at"` // 发货成功时间
|
|
ShipFailReason string `gorm:"size:512" json:"ship_fail_reason"` // 最近一次失败原因
|
|
|
|
GameChannel string `gorm:"size:64" json:"game_channel"` // 账号区服(安卓/IOS-微信/QQ)
|
|
GameUID string `gorm:"size:128" json:"game_uid"` // 游戏角色UUID
|
|
RoleName string `gorm:"size:64" json:"role_name"` // 角色名
|
|
PayScore int `gorm:"default:0" json:"pay_score"` // 消耗积分
|
|
}
|
|
|
|
// 订单状态
|
|
const (
|
|
OrderStatusPending = "pending" // 待支付
|
|
OrderStatusPaid = "paid" // 已支付,可发货
|
|
OrderStatusDelivering = "delivering" // 发货中
|
|
OrderStatusDelivered = "delivered" // 已交付
|
|
OrderStatusShipFailed = "ship_failed" // 发货失败(可重试)
|
|
OrderStatusCancelled = "cancelled" // 已取消
|
|
)
|
|
|
|
// 上游推送的发货状态
|
|
const (
|
|
ShipNotifySuccess = "success"
|
|
ShipNotifyFailed = "failed"
|
|
ShipNotifyProcessing = "processing"
|
|
)
|
|
|
|
// ShipLog 发货推送记录(上游回调留痕)
|
|
type ShipLog struct {
|
|
ID uint `gorm:"primarykey" json:"id"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
|
|
MerchantID uint `gorm:"index;not null;default:0" json:"merchant_id"`
|
|
OrderNo string `gorm:"size:64;index;not null" json:"order_no"`
|
|
OrderID uint `gorm:"index" json:"order_id"`
|
|
ShipStatus string `gorm:"size:32;not null" json:"ship_status"` // success/failed/processing
|
|
ProviderOrderNo string `gorm:"size:64" json:"provider_order_no"`
|
|
FailReason string `gorm:"size:512" json:"fail_reason"`
|
|
Payload string `gorm:"type:text" json:"payload"` // 原始请求 JSON
|
|
ResultStatus string `gorm:"size:32" json:"result_status"` // 处理后订单状态
|
|
Message string `gorm:"size:255" json:"message"`
|
|
}
|