作者 陈志颖

fix:修复普通用户进入公司获取不到用户信息问题

1 -# 合伙人项目  
  1 +# 合伙人项目
  2 +
  3 +### 系统架构
  4 +
  5 +### 领域驱动设计
  6 +
  7 +### 核心登录流程
  8 +
@@ -396,22 +396,29 @@ func CompaniesLogin(header *protocol.RequestHeader, request *protocolx.CenterCom @@ -396,22 +396,29 @@ func CompaniesLogin(header *protocol.RequestHeader, request *protocolx.CenterCom
396 err = protocol.NewCustomMessage(1, "密码不能为空!") 396 err = protocol.NewCustomMessage(1, "密码不能为空!")
397 return 397 return
398 } 398 }
  399 +
399 // 判断是否高管 400 // 判断是否高管
400 ok, loginErr := loginSvr.CheckIsSenior(request.Phone, 0) 401 ok, loginErr := loginSvr.CheckIsSenior(request.Phone, 0)
401 if loginErr != nil { 402 if loginErr != nil {
402 err = protocol.NewErrWithMessage(10001) 403 err = protocol.NewErrWithMessage(10001)
403 return 404 return
404 } 405 }
  406 +
405 isSenior = ok 407 isSenior = ok
  408 +
406 if ok { // 高管 409 if ok { // 高管
407 if loginSvr.ManagerLogin(request.Phone, request.Password) != nil && loginSvr.PartnerLogin(request.Phone, request.Password) != nil { 410 if loginSvr.ManagerLogin(request.Phone, request.Password) != nil && loginSvr.PartnerLogin(request.Phone, request.Password) != nil {
408 err = protocol.NewCustomMessage(1, "密码输入有误!") 411 err = protocol.NewCustomMessage(1, "密码输入有误!")
409 return 412 return
410 } 413 }
411 - } else { // 普通用户登录,进入游客页面  
412 - guestErr := loginSvr.RegistryGuest(request.Phone)  
413 - if guestErr != nil {  
414 - err = protocol.NewCustomMessage(1, "普通用户登录错误") 414 + } else { // 普通用户登录
  415 + //guestErr := loginSvr.RegistryGuest(request.Phone)
  416 + //if guestErr != nil {
  417 + // err = protocol.NewCustomMessage(1, "普通用户登录错误")
  418 + // return
  419 + //}
  420 + if loginSvr.ManagerLogin(request.Phone, request.Password) != nil {
  421 + err = protocol.NewCustomMessage(1, "密码输入有误!")
415 return 422 return
416 } 423 }
417 } 424 }
@@ -196,25 +196,33 @@ func UserInfoV2(header *protocol.RequestHeader, request *protocol.UserInfoReques @@ -196,25 +196,33 @@ func UserInfoV2(header *protocol.RequestHeader, request *protocol.UserInfoReques
196 UsersRepository, _ = factory.CreateUsersRepository(transactionContext) 196 UsersRepository, _ = factory.CreateUsersRepository(transactionContext)
197 company *domain.Company 197 company *domain.Company
198 user *domain.Users 198 user *domain.Users
  199 + loginSvr = domain_service.NewPgLoginService(transactionContext)
199 ) 200 )
  201 +
200 if err = transactionContext.StartTransaction(); err != nil { 202 if err = transactionContext.StartTransaction(); err != nil {
201 return nil, err 203 return nil, err
202 } 204 }
  205 +
203 defer func() { 206 defer func() {
204 transactionContext.RollbackTransaction() 207 transactionContext.RollbackTransaction()
205 }() 208 }()
  209 +
206 rsp = &protocol.UserInfoResponse{} 210 rsp = &protocol.UserInfoResponse{}
207 rspMap := make(map[string]interface{}) 211 rspMap := make(map[string]interface{})
208 212
  213 + // 获取合伙人信息
209 funcPartnerInfo := func() { 214 funcPartnerInfo := func() {
210 if partnerInfo, err = PartnerInfoService.FindOne(map[string]interface{}{"id": header.UserId}); err != nil { 215 if partnerInfo, err = PartnerInfoService.FindOne(map[string]interface{}{"id": header.UserId}); err != nil {
211 err = protocol.NewErrWithMessage(502, err) //账号不存在 216 err = protocol.NewErrWithMessage(502, err) //账号不存在
212 return 217 return
213 } 218 }
  219 +
214 if company, err = CompanyRepository.FindOne(map[string]interface{}{"id": header.CompanyId}); err != nil { 220 if company, err = CompanyRepository.FindOne(map[string]interface{}{"id": header.CompanyId}); err != nil {
215 return 221 return
216 } 222 }
  223 +
217 var miniProgram map[string]interface{} 224 var miniProgram map[string]interface{}
  225 +
218 if len(company.Applets) > 0 { 226 if len(company.Applets) > 0 {
219 if company.Applets[0].Valid() { 227 if company.Applets[0].Valid() {
220 miniProgram = make(map[string]interface{}) 228 miniProgram = make(map[string]interface{})
@@ -228,6 +236,7 @@ func UserInfoV2(header *protocol.RequestHeader, request *protocol.UserInfoReques @@ -228,6 +236,7 @@ func UserInfoV2(header *protocol.RequestHeader, request *protocol.UserInfoReques
228 miniProgram["title"] = company.Applets[0].Name 236 miniProgram["title"] = company.Applets[0].Name
229 } 237 }
230 } 238 }
  239 +
231 u := userx.User{ 240 u := userx.User{
232 Id: partnerInfo.Id, 241 Id: partnerInfo.Id,
233 PartnerName: partnerInfo.PartnerName, 242 PartnerName: partnerInfo.PartnerName,
@@ -265,18 +274,22 @@ func UserInfoV2(header *protocol.RequestHeader, request *protocol.UserInfoReques @@ -265,18 +274,22 @@ func UserInfoV2(header *protocol.RequestHeader, request *protocol.UserInfoReques
265 } else { 274 } else {
266 u.CooperateCompany.Salesman = map[string]interface{}{} 275 u.CooperateCompany.Salesman = map[string]interface{}{}
267 } 276 }
  277 +
268 rspMap["user"] = u 278 rspMap["user"] = u
269 rsp = rspMap 279 rsp = rspMap
270 } 280 }
271 281
  282 + // 获取管理员信息
272 funcManagerInfo := func() { 283 funcManagerInfo := func() {
273 if user, err = UsersRepository.FindOne(map[string]interface{}{"id": header.UserId}); err != nil { 284 if user, err = UsersRepository.FindOne(map[string]interface{}{"id": header.UserId}); err != nil {
274 err = protocol.NewErrWithMessage(502, err) //账号不存在 285 err = protocol.NewErrWithMessage(502, err) //账号不存在
275 return 286 return
276 } 287 }
  288 +
277 if company, err = CompanyRepository.FindOne(map[string]interface{}{"id": header.CompanyId}); err != nil { 289 if company, err = CompanyRepository.FindOne(map[string]interface{}{"id": header.CompanyId}); err != nil {
278 return 290 return
279 } 291 }
  292 +
280 rspMap["user"] = userx.User{ 293 rspMap["user"] = userx.User{
281 Id: user.Id, 294 Id: user.Id,
282 PartnerName: user.Name, 295 PartnerName: user.Name,
@@ -288,12 +301,26 @@ func UserInfoV2(header *protocol.RequestHeader, request *protocol.UserInfoReques @@ -288,12 +301,26 @@ func UserInfoV2(header *protocol.RequestHeader, request *protocol.UserInfoReques
288 MiniProgram: nil, 301 MiniProgram: nil,
289 }, 302 },
290 } 303 }
  304 +
291 rsp = rspMap 305 rsp = rspMap
292 } 306 }
293 307
  308 + phone := strconv.Itoa(header.SimNum)
  309 +
  310 + // 判断是否高管
  311 + ok, loginErr := loginSvr.CheckIsSenior(phone, 0)
  312 + if loginErr != nil {
  313 + err = protocol.NewErrWithMessage(10001)
  314 + return
  315 + }
  316 +
294 switch header.AdminType { 317 switch header.AdminType {
295 case int(protocolx.AdminTypePartner): 318 case int(protocolx.AdminTypePartner):
296 - funcPartnerInfo() 319 + if ok { // 身份为高管,则默认登录合伙人
  320 + funcPartnerInfo()
  321 + } else { // 身份非高管
  322 + funcManagerInfo()
  323 + }
297 break 324 break
298 case int(protocolx.AdminTypeManager): 325 case int(protocolx.AdminTypeManager):
299 funcManagerInfo() 326 funcManagerInfo()
@@ -302,6 +329,7 @@ func UserInfoV2(header *protocol.RequestHeader, request *protocol.UserInfoReques @@ -302,6 +329,7 @@ func UserInfoV2(header *protocol.RequestHeader, request *protocol.UserInfoReques
302 funcPartnerInfo() 329 funcPartnerInfo()
303 break 330 break
304 } 331 }
  332 +
305 err = transactionContext.CommitTransaction() 333 err = transactionContext.CommitTransaction()
306 return 334 return
307 } 335 }
@@ -50,7 +50,7 @@ func (svr *PgLoginService) CheckIsSenior(phone string, companyId int64) (ok bool @@ -50,7 +50,7 @@ func (svr *PgLoginService) CheckIsSenior(phone string, companyId int64) (ok bool
50 UsersRepository, _ = repository.NewUsersRepository(svr.transactionContext) 50 UsersRepository, _ = repository.NewUsersRepository(svr.transactionContext)
51 ) 51 )
52 svr.Phone = phone 52 svr.Phone = phone
53 - user, err := UsersRepository.FindOne(map[string]interface{}{"phone": phone, "status": 1, "deleteAtIsNull": 1}) 53 + user, err := UsersRepository.FindOne(map[string]interface{}{"phone": phone, "status": 1, "deleteAtIsNull": true})
54 if err != nil { 54 if err != nil {
55 return false, err 55 return false, err
56 } else { 56 } else {