aozhiwei bc888c9dc4 1
2024-11-29 11:21:46 +08:00

49 lines
1.3 KiB
Go

package model
import (
"f5"
"errors"
"main/constant"
"gorm.io/gorm"
)
type InAppOrder struct {
Idx int64 `gorm:"column:idx;AUTO_INCREMENT;primaryKey"`
OrderId string `gorm:"column:order_id"`
SpOrderId string `gorm:"column:sp_order_id"`
AccountId string `gorm:"column:account_id;<-:create"`
GoodsId int32 `gorm:"column:goods_id;<-:create"`
Status int32 `gorm:"column:status"`
CreateTime int32 `gorm:"column:createtime;<-:create"`
ModifyTime int32 `gorm:"column:modifytime"`
}
func (this *InAppOrder) TableName() string {
return "t_inapp_order"
}
func (this *InAppOrder) Create() error {
if result := f5.GetApp().GetOrmDb(constant.WHEEL_DB).Create(this); result.Error != nil {
return result.Error
}
return nil
}
func (this *InAppOrder) UpdateFields(fields []string) error {
if result := f5.GetApp().GetOrmDb(constant.WHEEL_DB).Model(this).Select(
fields).Updates(this); result.Error != nil {
return result.Error
}
return nil
}
func (this *InAppOrder) Find(accountId string, orderId string) (error, bool) {
if result := f5.GetApp().GetOrmDb(constant.WHEEL_DB).Table(this.TableName()).Take(
this, "account_id = ? AND order_id = ?", accountId, orderId); result.Error != nil &&
!errors.Is(result.Error, gorm.ErrRecordNotFound) {
return result.Error, false
} else {
return nil, result.RowsAffected > 0
}
}