package model import ( "gorm.io/gorm" "hospital-admin-api/global" "time" ) // Order 订单表 type Order struct { OrderId int64 `gorm:"column:order_id;type:bigint(19);primary_key;comment:主键id" json:"order_id"` UserId int64 `gorm:"column:user_id;type:bigint(19);comment:用户id-患者;NOT NULL" json:"user_id"` PatientId int64 `gorm:"column:patient_id;type:bigint(19);comment:患者id;NOT NULL" json:"patient_id"` DoctorId int64 `gorm:"column:doctor_id;type:bigint(19);comment:医生id(存在为null的情况)" json:"doctor_id"` OrderType int `gorm:"column:order_type;type:tinyint(1);comment:订单类型(1:问诊订单 2:药品订单 3:检测订单 4:随访包订单 5:健康包订单);NOT NULL" json:"order_type"` IsDelete int `gorm:"column:is_delete;type:tinyint(1);default:0;comment:删除状态(0:否 1:是)" json:"is_delete"` PayChannel int `gorm:"column:pay_channel;type:tinyint(1);default:1;comment:支付渠道(1:小程序支付 2:微信扫码支付 3:模拟支付);NOT NULL" json:"pay_channel"` PayStatus int `gorm:"column:pay_status;type:tinyint(1);default:1;comment:支付状态(1:未支付 2:已支付 3:支付中 4:支付失败 5:支付超时 6:支付关闭 7:已撤销 8:转入退款);NOT NULL" json:"pay_status"` PayTime LocalTime `gorm:"column:pay_time;type:datetime;comment:支付时间" json:"pay_time"` RefundStatus int `gorm:"column:refund_status;type:tinyint(1);default:0;comment:订单退款状态(0:无退款 1:申请退款 2:退款中 3:退款成功 4:拒绝退款 5:退款关闭 6:退款异常 7:部分退款);NOT NULL" json:"refund_status"` OrderNo string `gorm:"column:order_no;type:varchar(30);comment:系统订单编号;NOT NULL" json:"order_no"` EscrowTradeNo string `gorm:"column:escrow_trade_no;type:varchar(100);comment:第三方支付流水号" json:"escrow_trade_no"` AmountTotal float64 `gorm:"column:amount_total;type:decimal(10,2) unsigned;default:0.00;comment:订单金额" json:"amount_total"` CouponAmountTotal float64 `gorm:"column:coupon_amount_total;type:decimal(10,2) unsigned;default:0.00;comment:优惠卷总金额" json:"coupon_amount_total"` PaymentAmountTotal float64 `gorm:"column:payment_amount_total;type:decimal(10,2) unsigned;default:0.00;comment:实际付款金额" json:"payment_amount_total"` CancelStatus int `gorm:"column:cancel_status;type:tinyint(1);default:0;comment:取消状态(0:否 1:是)" json:"cancel_status"` CancelTime LocalTime `gorm:"column:cancel_time;type:datetime;comment:订单取消时间" json:"cancel_time"` CancelRemarks string `gorm:"column:cancel_remarks;type:varchar(255);comment:取消订单备注" json:"cancel_remarks"` OrderRemarks string `gorm:"column:order_remarks;type:varchar(255);comment:订单备注" json:"order_remarks"` IsWithdrawal int `gorm:"column:is_withdrawal;type:tinyint(1);default:0;comment:是否提现(0:否 1:是 2:提现中 3:无需提现)" json:"is_withdrawal"` WithdrawalTime LocalTime `gorm:"column:withdrawal_time;type:datetime;comment:提现时间" json:"withdrawal_time"` OrderInquiry *OrderInquiry `gorm:"foreignKey:OrderId;references:order_id" json:"order_inquiry"` OrderServicePackage *OrderServicePackage `gorm:"foreignKey:OrderId;references:order_id" json:"order_service_package"` User *User `gorm:"foreignKey:UserId;references:user_id" json:"user"` Model } func (m *Order) TableName() string { return "gdxz_order" } func (m *Order) BeforeCreate(tx *gorm.DB) error { if m.OrderId == 0 { m.OrderId = global.Snowflake.Generate().Int64() } m.CreatedAt = LocalTime(time.Now()) tx.Statement.SetColumn("CreatedAt", m.CreatedAt) m.UpdatedAt = LocalTime(time.Now()) tx.Statement.SetColumn("UpdatedAt", m.UpdatedAt) return nil }