package gmodel import ( "context" "errors" "gorm.io/gorm" ) type FsCanteenType struct { Id int64 `gorm:"primary_key" json:"id"` // ID Name *string `gorm:"default:''" json:"name"` // 餐厅名字 Sort *int64 `gorm:"default:0" json:"sort"` // 排序 Status *int64 `gorm:"default:1" json:"status"` // 状态位 1启用0停用 Ctime *int64 `gorm:"default:0" json:"ctime"` // 添加时间 } type FsCanteenTypeModel struct { db *gorm.DB } func NewFsCanteenTypeModel(db *gorm.DB) *FsCanteenTypeModel { return &FsCanteenTypeModel{db} } func (c *FsCanteenTypeModel) FindOne(ctx context.Context, id int64) (resp FsCanteenType, err error) { err = c.db.WithContext(ctx).Model(&FsCanteenType{}).Where("`id` = ? and `status` = ? ", id, 1).First(&resp).Error if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) { return FsCanteenType{}, err } return resp, nil }