This commit is contained in:
laodaming 2023-11-10 15:53:46 +08:00
parent ca6f0c51e5
commit 81f3eb6675

View File

@ -8,14 +8,14 @@ import (
// TODO: 使用model的属性做你想做的
func (u *LdapUsersModel) CreateOrUpdate(ctx context.Context, appId string, openId string, data *LdapUsers) error {
func (u *LdapUsersModel) CreateOrUpdate(ctx context.Context, openId string, data *LdapUsers) error {
var info LdapUsers
err := u.db.WithContext(ctx).Where("app_id = ? and open_id = ?", appId, openId).Take(&info).Error
err := u.db.WithContext(ctx).Where("open_id = ?", 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
return u.db.WithContext(ctx).Where("open_id = ?", openId).Updates(&data).Error
}