aozhiwei b587ff9842 1
2024-11-22 16:44:53 +08:00

61 lines
1.7 KiB
Go

package model
import (
"f5"
"errors"
"main/constant"
"gorm.io/gorm"
)
type Buff struct {
Idx int64 `gorm:"column:idx;AUTO_INCREMENT;primaryKey"`
AccountId string `gorm:"column:account_id"`
BuffId int32 `gorm:"column:buff_id"`
ExpiresTime int32 `gorm:"column:expires_time"`
CreateTime int32 `gorm:"column:createtime;<-:create"`
ModifyTime int32 `gorm:"column:modifytime"`
}
func (this *Buff) TableName() string {
return "t_buff"
}
func (this *Buff) Create() error {
if result := f5.GetApp().GetOrmDb(constant.WHEEL_DB).Create(this); result.Error != nil {
return result.Error
}
return nil
}
func (this *Buff) 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 *Buff) FindByBuffUniId(accountId string, buffUniId int64) (error, bool) {
if result := f5.GetApp().GetOrmDb(constant.WHEEL_DB).Table(this.TableName()).Take(
this, "account_id = ? and idx = ?", accountId, buffUniId); result.Error != nil &&
!errors.Is(result.Error, gorm.ErrRecordNotFound) {
return result.Error, false
} else {
return nil, result.RowsAffected > 0
}
}
func (this *Buff) FindByBuffId(accountId string, buffId int32) (error, bool) {
if result := f5.GetApp().GetOrmDb(constant.WHEEL_DB).Table(this.TableName()).Take(
this, "account_id = ? and buff_id = ?", accountId, buffId); result.Error != nil &&
!errors.Is(result.Error, gorm.ErrRecordNotFound) {
return result.Error, false
} else {
return nil, result.RowsAffected > 0
}
}
func (this *Buff) UpdateExpireTime() error {
return this.UpdateFields([]string{"expires_time", "modifytime"})
}