sync: 对齐小程序 v1.0.2 生产代码并脱敏
This commit is contained in:
@@ -111,6 +111,16 @@ func (s *sAppUser) UpdateInfo(ctx context.Context, param *model.AppUpdateUserInf
|
||||
}
|
||||
|
||||
func (s *sAppUser) BindWechat(ctx context.Context, param *model.AppWechatBindParam) (res *model.AppWechatBindModel, err error) {
|
||||
if param == nil || strings.TrimSpace(param.WxCode) == "" {
|
||||
return nil, gerror.New("微信登录凭证不能为空")
|
||||
}
|
||||
config, err := appLoadWechatConfig(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if !config.Mini.Enabled {
|
||||
return nil, gerror.New("微信小程序绑定暂未启用")
|
||||
}
|
||||
user, err := appCurrentUser(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -122,6 +132,9 @@ func (s *sAppUser) BindWechat(ctx context.Context, param *model.AppWechatBindPar
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if !userInfo.WechatBound {
|
||||
return nil, gerror.New("微信绑定未完成,请检查小程序配置后重试")
|
||||
}
|
||||
return &model.AppWechatBindModel{
|
||||
Success: true,
|
||||
UserInfo: userInfo,
|
||||
@@ -291,6 +304,10 @@ func getAppUserInfoById(ctx context.Context, userId int64) (res *model.AppUserIn
|
||||
}
|
||||
}
|
||||
roleName, roleKey, roleNames := appLoadBoundRoleNames(ctx, user.UserId)
|
||||
isTopLevelEnterprise, err := appIsTopLevelEnterprise(ctx, user)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
wechatBound, wechatBindText, err := appUserWechatBindingStatus(ctx, user)
|
||||
if err != nil {
|
||||
@@ -298,6 +315,7 @@ func getAppUserInfoById(ctx context.Context, userId int64) (res *model.AppUserIn
|
||||
}
|
||||
|
||||
return &model.AppUserInfoModel{
|
||||
IsTopLevelEnterprise: isTopLevelEnterprise,
|
||||
UserId: user.UserId,
|
||||
TenantId: user.TenantId,
|
||||
DeptId: user.DeptId,
|
||||
@@ -321,6 +339,25 @@ func getAppUserInfoById(ctx context.Context, userId int64) (res *model.AppUserIn
|
||||
}, nil
|
||||
}
|
||||
|
||||
// 顶级企业按机构层级识别,不依赖运营、管理员等角色名称。
|
||||
func appIsTopLevelEnterprise(ctx context.Context, user *entity.SysUser) (bool, error) {
|
||||
if user == nil || user.UserId <= 0 || user.UserType == consts.SysUserTypeAPP || appIsTerminalUser(ctx, user) {
|
||||
return false, nil
|
||||
}
|
||||
if user.UserId == 1 {
|
||||
return true, nil
|
||||
}
|
||||
if user.DeptId <= 0 {
|
||||
return false, nil
|
||||
}
|
||||
var dept *entity.SysDept
|
||||
err := dao.SysDept.Ctx(ctx).Fields("dept_id", "parent_id", "status", "deleted_at").Where("tenant_id", user.TenantId).Where("dept_id", user.DeptId).Scan(&dept)
|
||||
if err != nil {
|
||||
return false, gerror.Wrap(err, "查询诊断企业层级失败")
|
||||
}
|
||||
return dept != nil && dept.ParentId == 0 && dept.Status == "0" && (dept.DeletedAt == nil || dept.DeletedAt.IsZero()), nil
|
||||
}
|
||||
|
||||
// appLoadBoundRoleNames 读取账户在 sys_user_role 中绑定的角色,并关联 sys_role 返回真实角色名称。
|
||||
// 这样既保留原有账号类型 role,又能让前端按真实的角色表名称展示账户身份标识。
|
||||
func appLoadBoundRoleNames(ctx context.Context, userId int64) (roleName string, roleKey string, roleNames []string) {
|
||||
|
||||
Reference in New Issue
Block a user