package gmodel import ( "context" "errors" "gorm.io/gorm" ) // TODO: 使用model的属性做你想做的 func (u *LdapUsersModel) CreateOrUpdate(ctx context.Context, appId string, openId string, data *LdapUsers) error { var info LdapUsers err := u.db.WithContext(ctx).Where("app_id = ? and open_id = ?", appId, openId).Take(&info).Error if err != nil { if errors.Is(err, gorm.ErrRecordNotFound) { return u.db.WithContext(ctx).Create(&data).Error } return err } return u.db.WithContext(ctx).Where("app_id = ? and open_id = ?", appId, openId).Updates(&data).Error }