package gmodel import ( "context" "errors" "gorm.io/gorm" ) // TODO: 使用model的属性做你想做的 func (u *FsFeishuUserModel) Create(ctx context.Context, data *FsFeishuUser) error { return u.db.WithContext(ctx).Model(&FsFeishuUser{}).Create(&data).Error } func (u *FsFeishuUserModel) Update(ctx context.Context, data *FsFeishuUser) error { return u.db.WithContext(ctx).Model(&FsFeishuUser{}).Where("`app_id` = ? and `open_id` = ?", data.AppId, data.OpenId).Updates(&data).Error } func (u *FsFeishuUserModel) Find(ctx context.Context, appId, openId string) (resp *FsFeishuUser, err error) { err = u.db.WithContext(ctx).Model(&FsFeishuUser{}).Where("`app_id` = ? and `open_id` = ?", appId, openId).Take(&resp).Error return resp, err } func (u *FsFeishuUserModel) CreateOrUpdate(ctx context.Context, appId, openId string, data *FsFeishuUser) error { _, err := u.Find(ctx, appId, openId) if err != nil { if errors.Is(err, gorm.ErrRecordNotFound) { return u.Create(ctx, data) } return err } data.Ctime = nil return u.Update(ctx, data) }