All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 7m57s
165 lines
9.3 KiB
Go
165 lines
9.3 KiB
Go
package model
|
||
|
||
import (
|
||
"time"
|
||
|
||
"gorm.io/gorm"
|
||
)
|
||
|
||
// Order 订单模型
|
||
// 记录套餐购买订单信息,支持单卡购买和设备购买两种类型
|
||
// 买家可以是个人客户(使用卡/设备钱包)或代理商(使用店铺钱包)
|
||
type Order struct {
|
||
gorm.Model
|
||
BaseModel `gorm:"embedded"`
|
||
|
||
// 订单基础信息
|
||
OrderNo string `gorm:"column:order_no;type:varchar(30);uniqueIndex:idx_order_no,where:deleted_at IS NULL;not null;comment:订单号(ORD+时间戳+6位随机数)" json:"order_no"`
|
||
OrderType string `gorm:"column:order_type;type:varchar(20);not null;comment:订单类型 single_card-单卡购买 device-设备购买" json:"order_type"`
|
||
|
||
// 买家信息
|
||
BuyerType string `gorm:"column:buyer_type;type:varchar(20);not null;comment:买家类型 personal-个人客户 agent-代理商" json:"buyer_type"`
|
||
BuyerID uint `gorm:"column:buyer_id;index:idx_order_buyer;not null;comment:买家ID(个人客户ID或店铺ID)" json:"buyer_id"`
|
||
BuyerPhone *string `gorm:"column:buyer_phone;type:varchar(20);comment:下单时买家主手机号快照" json:"buyer_phone"`
|
||
BuyerNickname *string `gorm:"column:buyer_nickname;type:varchar(100);comment:下单时买家昵称快照" json:"buyer_nickname"`
|
||
|
||
// 关联资源
|
||
IotCardID *uint `gorm:"column:iot_card_id;index;comment:IoT卡ID(单卡购买时有值)" json:"iot_card_id,omitempty"`
|
||
DeviceID *uint `gorm:"column:device_id;index;comment:设备ID(设备购买时有值)" json:"device_id,omitempty"`
|
||
AssetIdentifier string `gorm:"column:asset_identifier;type:varchar(100);comment:下单时资产的标识符快照(ICCID 或 VirtualNo)" json:"asset_identifier,omitempty"`
|
||
|
||
// 金额信息
|
||
TotalAmount int64 `gorm:"column:total_amount;type:bigint;not null;comment:订单总金额(分)" json:"total_amount"`
|
||
|
||
// 支付信息
|
||
PaymentMethod string `gorm:"column:payment_method;type:varchar(20);comment:支付方式 wallet-钱包 wechat-微信 alipay-支付宝" json:"payment_method"`
|
||
PaymentStatus int `gorm:"column:payment_status;type:int;default:1;not null;index:idx_order_payment_status;comment:支付状态 1-待支付 2-已支付 3-已取消 4-已退款" json:"payment_status"`
|
||
PaidAt *time.Time `gorm:"column:paid_at;comment:支付时间" json:"paid_at,omitempty"`
|
||
|
||
// 佣金信息
|
||
CommissionStatus int `gorm:"column:commission_status;type:int;default:1;not null;comment:佣金流程状态 1-待计算 2-已完成 3-待人工处理" json:"commission_status"`
|
||
CommissionResult int `gorm:"column:commission_result;type:int;default:0;not null;comment:佣金业务结果 0-未知 1-有佣金 2-无佣金 3-链路异常" json:"commission_result"`
|
||
CommissionConfigVersion int `gorm:"column:commission_config_version;type:int;default:0;comment:佣金配置版本(订单创建时快照)" json:"commission_config_version"`
|
||
SellerShopID *uint `gorm:"column:seller_shop_id;index;comment:销售店铺ID(用于成本价差佣金计算)" json:"seller_shop_id,omitempty"`
|
||
SellerCostPrice int64 `gorm:"column:seller_cost_price;type:bigint;default:0;comment:销售成本价(分,用于计算利润)" json:"seller_cost_price"`
|
||
SeriesID *uint `gorm:"column:series_id;index;comment:系列ID(用于查询分配配置)" json:"series_id,omitempty"`
|
||
|
||
// 订单来源和世代
|
||
Source string `gorm:"column:source;type:varchar(20);not null;default:'admin';comment:订单来源 admin-后台 client-客户端" json:"source"`
|
||
Generation int `gorm:"column:generation;type:int;not null;default:1;comment:资产世代编号" json:"generation"`
|
||
|
||
// 代购信息
|
||
IsPurchaseOnBehalf bool `gorm:"column:is_purchase_on_behalf;type:boolean;default:false;comment:是否为代购订单" json:"is_purchase_on_behalf"`
|
||
|
||
// 操作者信息(谁下的单)
|
||
OperatorAccountID *uint `gorm:"column:operator_account_id;index:idx_orders_operator_account_id;comment:操作者账号ID(权威字段)" json:"operator_account_id,omitempty"`
|
||
OperatorAccountType string `gorm:"column:operator_account_type;type:varchar(32);default:'';not null;comment:操作者账号类型(platform/agent/enterprise/personal_customer)" json:"operator_account_type,omitempty"`
|
||
OperatorAccountName string `gorm:"column:operator_account_name;type:varchar(255);default:'';not null;comment:操作者名称快照" json:"operator_account_name,omitempty"`
|
||
OperatorID *uint `gorm:"column:operator_id;index:idx_orders_operator_id;comment:操作者ID(历史兼容字段,旧语义可能保存代理店铺ID)" json:"operator_id,omitempty"`
|
||
OperatorType string `gorm:"column:operator_type;type:varchar(20);comment:操作者类型(历史兼容字段,旧语义为platform/agent)" json:"operator_type,omitempty"`
|
||
|
||
// 实际支付金额(可能与订单金额不同,如代理代购场景)
|
||
ActualPaidAmount *int64 `gorm:"column:actual_paid_amount;type:bigint;comment:实际支付金额(分)" json:"actual_paid_amount,omitempty"`
|
||
|
||
// 订单角色(标识订单中的买卖关系)
|
||
PurchaseRole string `gorm:"column:purchase_role;type:varchar(50);index:idx_orders_purchase_role;comment:订单角色(self_purchase/purchased_by_parent/purchased_by_platform/purchase_for_subordinate)" json:"purchase_role,omitempty"`
|
||
|
||
// 订单超时信息
|
||
ExpiresAt *time.Time `gorm:"column:expires_at;comment:订单过期时间(NULL表示不过期)" json:"expires_at,omitempty"`
|
||
|
||
// 支付配置
|
||
PaymentConfigID *uint `gorm:"column:payment_config_id;index;comment:支付配置ID(关联tb_wechat_config.id)" json:"payment_config_id,omitempty"`
|
||
|
||
// 线下支付凭证对象存储 file_key(仅线下支付订单必填)
|
||
PaymentVoucherKey string `gorm:"column:payment_voucher_key;type:varchar(500);comment:线下支付凭证对象存储file_key" json:"payment_voucher_key,omitempty"`
|
||
}
|
||
|
||
// TableName 指定表名
|
||
func (Order) TableName() string {
|
||
return "tb_order"
|
||
}
|
||
|
||
// 订单类型常量
|
||
const (
|
||
OrderTypeSingleCard = "single_card" // 单卡购买
|
||
OrderTypeDevice = "device" // 设备购买
|
||
)
|
||
|
||
// 买家类型常量
|
||
const (
|
||
BuyerTypePersonal = "personal" // 个人客户
|
||
BuyerTypeAgent = "agent" // 代理商
|
||
)
|
||
|
||
// 支付方式常量
|
||
const (
|
||
PaymentMethodWallet = "wallet" // 钱包支付
|
||
PaymentMethodWechat = "wechat" // 微信支付
|
||
PaymentMethodAlipay = "alipay" // 支付宝支付
|
||
PaymentMethodOffline = "offline" // 线下支付(仅平台代购使用)
|
||
)
|
||
|
||
// 支付状态常量
|
||
const (
|
||
PaymentStatusPending = 1 // 待支付
|
||
PaymentStatusPaid = 2 // 已支付
|
||
PaymentStatusCancelled = 3 // 已取消
|
||
PaymentStatusRefunded = 4 // 已退款
|
||
)
|
||
|
||
// 佣金流程状态常量
|
||
const (
|
||
CommissionStatusPending = 1 // 待计算
|
||
CommissionStatusCompleted = 2 // 已完成
|
||
CommissionStatusPendingReview = 3 // 待人工处理
|
||
|
||
// CommissionStatusCalculated 兼容旧命名,语义已调整为“已完成”
|
||
CommissionStatusCalculated = CommissionStatusCompleted
|
||
)
|
||
|
||
// 佣金业务结果常量
|
||
const (
|
||
CommissionResultUnknown = 0 // 未知(历史兼容态)
|
||
CommissionResultHasAmount = 1 // 有佣金
|
||
CommissionResultNoAmount = 2 // 无佣金
|
||
CommissionResultChainBroken = 3 // 链路异常
|
||
)
|
||
|
||
// 订单角色常量
|
||
const (
|
||
PurchaseRoleSelfPurchase = "self_purchase" // 自己购买
|
||
PurchaseRolePurchasedByParent = "purchased_by_parent" // 上级代理购买
|
||
PurchaseRolePurchasedByPlatform = "purchased_by_platform" // 平台代购
|
||
PurchaseRolePurchaseForSubordinate = "purchase_for_subordinate" // 给下级购买
|
||
)
|
||
|
||
// 操作者账号类型常量
|
||
const (
|
||
OperatorAccountTypePlatform = "platform" // 平台账号
|
||
OperatorAccountTypeAgent = "agent" // 代理账号
|
||
OperatorAccountTypeEnterprise = "enterprise" // 企业账号
|
||
OperatorAccountTypePersonalCustomer = "personal_customer" // 个人客户
|
||
)
|
||
|
||
// OrderItem 订单明细模型
|
||
// 记录订单中购买的套餐明细,支持一个订单购买多个套餐
|
||
type OrderItem struct {
|
||
gorm.Model
|
||
BaseModel `gorm:"embedded"`
|
||
|
||
OrderID uint `gorm:"column:order_id;index:idx_order_item_order_id;not null;comment:订单ID" json:"order_id"`
|
||
PackageID uint `gorm:"column:package_id;index;not null;comment:套餐ID" json:"package_id"`
|
||
PackageName string `gorm:"column:package_name;type:varchar(100);not null;comment:套餐名称(快照)" json:"package_name"`
|
||
PackageType *string `gorm:"column:package_type;type:varchar(20);comment:套餐类型快照 formal-正式套餐 addon-加油包" json:"package_type"`
|
||
Quantity int `gorm:"column:quantity;type:int;default:1;not null;comment:数量" json:"quantity"`
|
||
UnitPrice int64 `gorm:"column:unit_price;type:bigint;not null;comment:单价(分)" json:"unit_price"`
|
||
Amount int64 `gorm:"column:amount;type:bigint;not null;comment:小计金额(分)" json:"amount"`
|
||
PackagePriceConfigStatus int `gorm:"column:package_price_config_status;type:int;default:0;not null;comment:套餐价格配置状态快照 0-未配置 1-赠送0价 2-已配置非0" json:"package_price_config_status"`
|
||
PackageIsGift bool `gorm:"column:package_is_gift;type:boolean;default:false;not null;comment:套餐是否赠送快照 true-赠送 false-普通可售" json:"package_is_gift"`
|
||
}
|
||
|
||
// TableName 指定表名
|
||
func (OrderItem) TableName() string {
|
||
return "tb_order_item"
|
||
}
|