|
@@ -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 (
|