作者 yangfu

修改登录

@@ -137,6 +137,10 @@ func (this *UserController) SwitchCompany() { @@ -137,6 +137,10 @@ func (this *UserController) SwitchCompany() {
137 return 137 return
138 } 138 }
139 header := controllers.GetRequestHeader(this.Ctx) 139 header := controllers.GetRequestHeader(this.Ctx)
  140 + if beego.BConfig.RunMode == "prod" || beego.BConfig.RunMode == "test" {
  141 + msg = protocol.NewReturnResponse(user.SwitchCompanyV3(header, request))
  142 + return
  143 + }
140 msg = protocol.NewReturnResponse(user.SwitchCompany(header, request)) 144 msg = protocol.NewReturnResponse(user.SwitchCompany(header, request))
141 } 145 }
142 146
@@ -87,7 +87,7 @@ func LoginV3(header *protocol.RequestHeader, request *protocol.LoginRequest) (rs @@ -87,7 +87,7 @@ func LoginV3(header *protocol.RequestHeader, request *protocol.LoginRequest) (rs
87 } 87 }
88 } 88 }
89 if !hasAuth { 89 if !hasAuth {
90 - err = protocol.NewErrWithMessage(2002, err) //账号不存在 90 + err = protocol.NewErrWithMessage(4140, err) //账号不存在
91 return 91 return
92 } 92 }
93 } 93 }
@@ -238,7 +238,7 @@ func UserCompanys(header *protocol.RequestHeader, request *protocol.UserCompanys @@ -238,7 +238,7 @@ func UserCompanys(header *protocol.RequestHeader, request *protocol.UserCompanys
238 } 238 }
239 239
240 //切换公司 240 //切换公司
241 -func SwitchCompany(header *protocol.RequestHeader, request *protocol.SwitchCompanyRequest) (rsp *protocol.SwitchCompanyResponse, err error) { 241 +func SwitchCompanyV3(header *protocol.RequestHeader, request *protocol.SwitchCompanyRequest) (rsp *protocol.SwitchCompanyResponse, err error) {
242 var ( 242 var (
243 userCompany *models.UserCompany 243 userCompany *models.UserCompany
244 auth *models.UserAuth 244 auth *models.UserAuth
@@ -276,6 +276,40 @@ func SwitchCompany(header *protocol.RequestHeader, request *protocol.SwitchCompa @@ -276,6 +276,40 @@ func SwitchCompany(header *protocol.RequestHeader, request *protocol.SwitchCompa
276 return 276 return
277 } 277 }
278 278
  279 +func SwitchCompany(header *protocol.RequestHeader, request *protocol.SwitchCompanyRequest) (rsp *protocol.SwitchCompanyResponse, err error) {
  280 + var (
  281 + userCompany *models.UserCompany
  282 + auth *models.UserAuth
  283 + )
  284 + if userCompany, err = models.GetUserCompanyByUserId(header.Uid, int64(request.CompanyId)); err != nil {
  285 + log.Error(err)
  286 + err = protocol.NewErrWithMessage(4201) //找不到这家公司
  287 + return
  288 + }
  289 + if auth, err = models.GetUserAuthByUserId(header.Uid, protocol.DeviceType); err != nil {
  290 + log.Error(err)
  291 + return
  292 + }
  293 + if auth.CurrentCompanyId == request.CompanyId {
  294 + log.Error(fmt.Sprintf("uid:%v 当前公司已经是:%v", header.Uid, request.CompanyId))
  295 + //return
  296 + } else {
  297 + auth.AuthCode = uid.NewV1().StringNoDash()
  298 + auth.AuthCodeExp = time.Now().Add(time.Second * protocol.TokenExpire)
  299 + if err = utils.UpdateTableByMap(&models.UserAuth{Id: auth.Id}, map[string]interface{}{
  300 + "CurrentCompanyId": userCompany.CompanyId, "CurrentUserCompanyId": userCompany.Id, "AuthCode": auth.AuthCode, "AuthCodeExp": auth.AuthCodeExp},
  301 + ); err != nil {
  302 + log.Error(err)
  303 + return
  304 + }
  305 + header.CompanyId = userCompany.CompanyId
  306 + header.UserId = userCompany.Id
  307 + }
  308 + rsp = &protocol.SwitchCompanyResponse{}
  309 + rsp.AuthCode = auth.AuthCode
  310 + return
  311 +}
  312 +
279 //用户信息 313 //用户信息
280 func UserInfo(header *protocol.RequestHeader, request *protocol.UserInfoRequest) (rsp *protocol.UserInfoResponse, err error) { 314 func UserInfo(header *protocol.RequestHeader, request *protocol.UserInfoRequest) (rsp *protocol.UserInfoResponse, err error) {
281 var ( 315 var (