互动
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

73 lines
3.6 KiB

package models
import (
"github.com/ouxuanserver/osmanthuswine/src/core"
"time"
)
const UserOrderTableName = TableNamePrefix + "user_order"
type UserOrder struct {
Id int64 `json:"id" xorm:"not null pk autoincr INT(11)"`
IsDelete bool `json:"is_delete" xorm:"not null default(0) comment('是否删除') TINYINT(1)" description:"是否删除"`
CreatedAt time.Time `json:"created_at" xorm:"not null created comment('创建时间') DATETIME" description:"创建时间"`
UpdatedAt time.Time `json:"updated_at" xorm:"not null updated comment('更新时间') DATETIME" description:"更新时间"`
// 订单信息
DeviceInfo string `json:"device_info" xorm:"not null default('') comment('设备号') VARCHAR(32)"`
GoodType int64 `json:"good_type" xorm:"not null default(0) comment('1霸屏2打赏3直播红包4商品订单')"`
Body string `json:"body" xorm:"not null default('') comment('') VARCHAR(128)"`
OutTradeNo string `json:"out_trade_no" xorm:"not null default('') comment('商户订单号') VARCHAR(32)"`
FeeType string `json:"fee_type" xorm:"not null default('CNY') comment('货币种类') VARCHAR(16)"`
TotalFee int64 `json:"total_fee" xorm:"not null default(0) comment('订单总金额,单位是分') INT(88)"`
TradeType string `json:"trade_type" xorm:"not null default('JSAPI') comment('交易类型') VARCHAR(16)"`
OpenId string `json:"open_id" xorm:"not null default('') comment('用户标识') VARCHAR(128)"`
UserId int64 `json:"user_id" xorm:"not null default(0) comment('用户id') INT(11)"`
ActivityId int64 `json:"activity_id" xorm:"not null default(0) comment('活动id') INT(11)"`
TransactionId string `json:"transaction_id" xorm:"not null default('') comment('微信支付订单号') VARCHAR(32)"`
ExpireAt int64 `json:"time_expire" xorm:"not null default('0') comment('交易过期') INT(20)"`
PrepayId string `json:"prepay_id" xorm:"not null default('') comment('预支付交易会话标识') VARCHAR(64)"`
Status int `json:"status" xorm:"not null default(0) comment('0尚未支付/支付中1支付成功2已完成3转入退款4退款成功5订单关闭') TINYINT(1)"`
// 退款
RefundRecvAccount string `json:"refund_recv_account" xorm:"not null default '' comment('入账账号') VARCHAR(64)"`
RefundAccount string `json:"refund_account" xorm:"not null default '' comment('入账账号') VARCHAR(64)"`
}
func (t *UserOrder) TableName() string {
return UserOrderTableName
}
func (t *UserOrder) AliasName(alias string) string {
return AliasTableName(t, alias)
}
func (t *UserOrder) AddUserOrder() (int64, error) {
return core.GetXormAuto().InsertOne(t)
}
func (t *UserOrder) GetByOutTradeNo(no string) (bool, error) {
return core.GetXormAuto().Where("is_delete=0 and out_trade_no=?", no).Get(t)
}
func (t *UserOrder) UpdateStatusByOutTradeNo(outTradeNo interface{}, status int) (int64, error) {
t.Status = status
return core.GetXormAuto().Where("out_trade_no=? and is_delete=0", outTradeNo).
Cols("status").Update(t)
}
func (t *UserOrder) UpdateByOutTradeNo(outTradeNo interface{}, filed ...string) (int64, error) {
return core.GetXormAuto().Where("out_trade_no=?", outTradeNo).Cols(filed...).Update(t)
}
//
//func (t *UserOrder) UpdateRefundByOutTradeNo(outTradeNo interface{}) (int64, error) {
// return core.GetXormAuto().Where("out_trade_no=?", outTradeNo).
// Cols("status", "refund_recv_account", "refund_account").Update(t)
//}
func GetUserOrdersByStatus(status ...int) ([]*UserOrder, error) {
orders := make([]*UserOrder, 0)
err := core.GetXormAuto().Where("is_delete=0").In("status", status).Find(&orders)
return orders, err
}