Merge branch 'develop' of https://gitee.com/fusenpack/fusenapi into develop

This commit is contained in:
eson
2023-10-25 16:40:43 +08:00
13 changed files with 74 additions and 276 deletions

View File

@@ -62,7 +62,7 @@ func (m *FsUserInfoModel) GetProfile(ctx context.Context, pkey string, userId in
}
rawsql := fmt.Sprintf("select JSON_EXTRACT(metadata,'$%s') as query from %s where user_id = ? and module = 'profile' order by ctime DESC limit 1", pkey, tname)
err := m.db.Raw(rawsql, userId).Take(&baseinfo).Error
err := m.db.WithContext(ctx).Raw(rawsql, userId).Take(&baseinfo).Error
if err != nil {
return nil, err
}
@@ -87,3 +87,32 @@ func (m *FsUserInfoModel) FindOneByUser(ctx context.Context, userId, guestId int
}
return resp, err
}
func (m *FsUserInfoModel) GetProfileByUserIdGuestId(ctx context.Context, pkey string, userId, guestId int64) (map[string]any, error) {
var baseinfo map[string]any
tname := fssql.GetGormTableName(m.db, FsUserInfo{})
if pkey == "." {
pkey = ""
} else {
pkey = "." + pkey
}
rawsql := fmt.Sprintf("select JSON_EXTRACT(metadata,'$%s') as query from %s where user_id = ? and guest_id = ? and module = 'profile' order by ctime DESC limit 1", pkey, tname)
err := m.db.WithContext(ctx).Raw(rawsql, userId, guestId).Take(&baseinfo).Error
if err != nil {
return nil, err
}
v, ok := baseinfo["query"].(string)
if !ok {
return nil, nil
}
var info map[string]any
err = json.Unmarshal([]byte(v), &info)
if err != nil {
return nil, err
}
return info, nil
}