package models import ( "github.com/beego/beego/v2/client/orm" "time" ) type OrderStatus string type RefundStatus string type PaymentWay string const ( //订单状态 OrderStatusPending OrderStatus = "pending" OrderStatusProcessing OrderStatus = "processing" OrderStatusPaid OrderStatus = "paid" OrderStatusClosed OrderStatus = "closed" OrderStatusRefund OrderStatus = "refund" //退款状态 RefundStatusSuccess RefundStatus = "success" RefundStatusPending RefundStatus = "pending" RefundStatusFailed RefundStatus = "failed" RefundStatusProcessing RefundStatus = "processing" WechatPayWay PaymentWay = "wechat" AliPayWay PaymentWay = "alipay" detailColumn = "id,order_id,user_id,template_user_id,product_id,status,created_time,updated_time,total_amount" ) type ProductOrderView struct { OrderID string RealName string Mobile string ProductType string ProductName string TotalAmount string ValidDuration string PaymentAmount string TradeNO string RefundTradeId string RefundAmount string PaymentWay string PaymentTime string Status string RefundStatus string RefundFinishTime string Remark string CreatedTime string } type ProductOrder struct { Id int `gorm:"column:id;primaryKey;autoIncrement" json:"id"` OrderId string `gorm:"column:order_id;size:255;comment:'订单编号'" json:"order_id"` UserId int `gorm:"column:user_id;default:null;comment:'用户id'" json:"user_id"` TemplateUserId int `gorm:"column:template_user_id;default:null;comment:'临时用户id'" json:"template_user_id"` RealName string `gorm:"column:real_name;default:null;comment:'临时用户id'" json:"real_name"` AreaCode string `gorm:"column:area_code;default:null;comment:'临时用户id'" json:"area_code"` Mobile string `gorm:"column:mobile;default:null;comment:'临时用户id'" json:"mobile"` ProductId int `gorm:"column:product_id;default:null;comment:'产品id'" json:"product_id"` ProductType MerchantProductType `gorm:"column:product_type;default:null;comment:'产品类型'" json:"product_type"` ProductName string `gorm:"column:product_name;default:null;comment:'商品名称'" json:"product_name"` TotalAmount string `gorm:"column:total_amount;size:255;default:null;comment:'金额'" json:"total_amount"` TradeId int `gorm:"column:trade_id;default:null;comment:'支付订单'" json:"trade_id"` TradeNo string `gorm:"column:trade_no;default:null;comment:'支付订单'" json:"trade_no"` RefundTradeId string `column:"refund_trade_id;null;comment:'退款金额'" json:"refund_trade_id"` RefundAmount string `gorm:"column:refund_amount;size:255;default:null;comment:'退款金额'" json:"refund_amount"` PaymentAmount string `gorm:"column:payment_amount;size:255;default:null;comment:'支付金额'" json:"payment_amount"` PaymentWay PaymentWay `gorm:"column:payment_way;enum('wechat','alipay');default:null;comment:'支付渠道'"` PaymentTime time.Time `gorm:"column:payment_time;default:null;comment:'支付时间'" json:"payment_time"` ExpiredTime time.Time `gorm:"column:expired_time;default:null;comment:'超时时间'" json:"expired_time"` Status OrderStatus `gorm:"column:status;type:enum('pending','processing','paid','closed','refund');default:'pending';comment:'订单状态'" json:"status"` RefundStatus RefundStatus `gorm:"column:refund_status;type:enum('pending','processing','failed','success');default:null;comment:'退款状态'" json:"refund_status"` RefundFinishTime time.Time `gorm:"column:refund_finish_time;default:null;comment:'退款完成时间'" json:"refund_finish_time"` ValidDuration string `gorm:"column:valid_duration;default:null;comment:'订单有效期'" json:"valid_duration"` Remark string `gorm:"column:remark;size:255;default:null;comment:'备注'" json:"remark"` IsDeleted int `gorm:"column:is_deleted;size:1;default:0;comment:'是否删除'" json:"is_deleted"` CreatedTime time.Time `gorm:"column:created_time;default:null;comment:'创建时间'" json:"created_time"` UpdatedTime time.Time `gorm:"column:updated_time;default:null;comment:'更新时间'" json:"updated_time"` } func (m *ProductOrder) TableName() string { return "product_orders" } func GetProductOrderByCondition(condition string, sortCondition string, startSize int, pageSize int) (list []*ProductOrder, err error) { o := orm.NewOrm() sql := `select * from product_orders where is_deleted=0` if condition != "" { sql += condition } if sortCondition != "" { sql += sortCondition } sql += ` LIMIT ?,?` _, err = o.Raw(sql, startSize, pageSize).QueryRows(&list) return } func GetProductOrderListByCondition(condition string, sortCondition string) (list []*ProductOrder, err error) { o := orm.NewOrm() sql := `select * from product_orders where is_deleted=0` if condition != "" { sql += condition } if sortCondition != "" { sql += sortCondition } _, err = o.Raw(sql).QueryRows(&list) return } func GetProductOrderCountByCondition(condition string) (total int, err error) { o := orm.NewOrm() err = o.Raw("select count(*) from product_orders where is_deleted=0" + condition).QueryRow(&total) return } func GetProductOrderByID(orderNo string) (order *ProductOrder, err error) { o := orm.NewOrm() err = o.Raw("select * from product_orders where is_deleted=0 and order_id =?", orderNo).QueryRow(&order) return }