作者 yangfu

切换公司修改

@@ -44,6 +44,7 @@ type SwitchCompanyRequest struct { @@ -44,6 +44,7 @@ type SwitchCompanyRequest struct {
44 CompanyId int64 `json:"companyId" valid:"Required"` 44 CompanyId int64 `json:"companyId" valid:"Required"`
45 } 45 }
46 type SwitchCompanyResponse struct { 46 type SwitchCompanyResponse struct {
  47 + AuthCode string `json:"authCode"`
47 } 48 }
48 49
49 /*用户信息 UserInfo */ 50 /*用户信息 UserInfo */
@@ -3,6 +3,7 @@ package user @@ -3,6 +3,7 @@ package user
3 import ( 3 import (
4 "fmt" 4 "fmt"
5 "github.com/astaxie/beego/orm" 5 "github.com/astaxie/beego/orm"
  6 + "gitlab.fjmaimaimai.com/mmm-go/gocomm/identity/uid"
6 "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log" 7 "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log"
7 "opp/internal/utils" 8 "opp/internal/utils"
8 "opp/models" 9 "opp/models"
@@ -10,6 +11,7 @@ import ( @@ -10,6 +11,7 @@ import (
10 "opp/services/agg" 11 "opp/services/agg"
11 "opp/services/auth" 12 "opp/services/auth"
12 "strings" 13 "strings"
  14 + "time"
13 ) 15 )
14 16
15 //验证smscode 17 //验证smscode
@@ -226,7 +228,7 @@ func UserCompanys(header *protocol.RequestHeader, request *protocol.UserCompanys @@ -226,7 +228,7 @@ func UserCompanys(header *protocol.RequestHeader, request *protocol.UserCompanys
226 } 228 }
227 229
228 //切换公司 230 //切换公司
229 -func SwitchCompany(header *protocol.RequestHeader, request *protocol.SwitchCompanyRequest) (rsp *protocol.UserInfoResponse, err error) { 231 +func SwitchCompany(header *protocol.RequestHeader, request *protocol.SwitchCompanyRequest) (rsp *protocol.SwitchCompanyResponse, err error) {
230 var ( 232 var (
231 userCompany *models.UserCompany 233 userCompany *models.UserCompany
232 auth *models.UserAuth 234 auth *models.UserAuth
@@ -244,17 +246,19 @@ func SwitchCompany(header *protocol.RequestHeader, request *protocol.SwitchCompa @@ -244,17 +246,19 @@ func SwitchCompany(header *protocol.RequestHeader, request *protocol.SwitchCompa
244 log.Error(fmt.Sprintf("uid:%v 当前公司已经是:%v", header.Uid, request.CompanyId)) 246 log.Error(fmt.Sprintf("uid:%v 当前公司已经是:%v", header.Uid, request.CompanyId))
245 //return 247 //return
246 } else { 248 } else {
247 - if err = utils.UpdateTableByMap(&models.UserAuth{Id: auth.Id}, map[string]interface{}{"CurrentCompanyId": userCompany.CompanyId, "CurrentUserCompanyId": userCompany.Id}); err != nil { 249 + auth.AuthCode = uid.NewV1().StringNoDash()
  250 + auth.AuthCodeExp = time.Now().Add(time.Second * protocol.TokenExpire)
  251 + if err = utils.UpdateTableByMap(&models.UserAuth{Id: auth.Id}, map[string]interface{}{
  252 + "CurrentCompanyId": userCompany.CompanyId, "CurrentUserCompanyId": userCompany.Id, "AuthCode": auth.AuthCode, "AuthCodeExp": auth.AuthCodeExp},
  253 + ); err != nil {
248 log.Error(err) 254 log.Error(err)
249 return 255 return
250 } 256 }
251 header.CompanyId = userCompany.CompanyId 257 header.CompanyId = userCompany.CompanyId
252 header.UserId = userCompany.Id 258 header.UserId = userCompany.Id
253 } 259 }
254 - if rsp, err = UserInfo(header, &protocol.UserInfoRequest{}); err != nil {  
255 - log.Error(err)  
256 - return  
257 - } 260 + rsp = &protocol.SwitchCompanyResponse{}
  261 + rsp.AuthCode = auth.AuthCode
258 return 262 return
259 } 263 }
260 264