正在显示
3 个修改的文件
包含
72 行增加
和
10 行删除
| @@ -88,7 +88,13 @@ func (e ErrWithMessage) Unwrap() error { | @@ -88,7 +88,13 @@ func (e ErrWithMessage) Unwrap() error { | ||
| 88 | 88 | ||
| 89 | //ParseToMessage 实现CustomErrParse的接口 | 89 | //ParseToMessage 实现CustomErrParse的接口 |
| 90 | func (e ErrWithMessage) ParseToMessage() *ResponseMessage { | 90 | func (e ErrWithMessage) ParseToMessage() *ResponseMessage { |
| 91 | - return NewMessage(e.Errno) | 91 | + rsp := &ResponseMessage{ |
| 92 | + Errno: transformCode(e.Errno), | ||
| 93 | + Errmsg: e.Errmsg, | ||
| 94 | + Data: NullData, | ||
| 95 | + OriginErrno: e.Errno, | ||
| 96 | + } | ||
| 97 | + return rsp | ||
| 92 | } | 98 | } |
| 93 | 99 | ||
| 94 | func SearchErr(code string) ErrorCode { | 100 | func SearchErr(code string) ErrorCode { |
| @@ -294,16 +294,19 @@ func UserBaseInfo(userid, companyid int64) (protocol.ResponseMeInfo, error) { | @@ -294,16 +294,19 @@ func UserBaseInfo(userid, companyid int64) (protocol.ResponseMeInfo, error) { | ||
| 294 | 294 | ||
| 295 | func UserHasCompanys(userid int64) ([]protocol.MeCompany, error) { | 295 | func UserHasCompanys(userid int64) ([]protocol.MeCompany, error) { |
| 296 | var ( | 296 | var ( |
| 297 | - companylist []companybase | ||
| 298 | - err error | ||
| 299 | - mecompanys []protocol.MeCompany | 297 | + userData *models.User |
| 298 | + err error | ||
| 299 | + mecompanys []protocol.MeCompany | ||
| 300 | ) | 300 | ) |
| 301 | - companylist, err = getUserCompanyReal(userid) | 301 | + userData, err = models.GetUserById(userid) |
| 302 | if err != nil { | 302 | if err != nil { |
| 303 | - log.Error("getUserCompanyReal(%d) err:%s", userid, err) | ||
| 304 | - return nil, protocol.NewErrWithMessage("1", err) | 303 | + return mecompanys, fmt.Errorf("获取用户数据失败") |
| 305 | } | 304 | } |
| 306 | - for _, v := range companylist { | 305 | + resp, err := serverplatform.GetUserCompanyDo(userData.Phone) |
| 306 | + if err != nil { | ||
| 307 | + return mecompanys, fmt.Errorf("获取数据失败:%s", err) | ||
| 308 | + } | ||
| 309 | + for _, v := range resp.Data.Company { | ||
| 307 | t := protocol.MeCompany{ | 310 | t := protocol.MeCompany{ |
| 308 | Id: v.Id, | 311 | Id: v.Id, |
| 309 | Name: v.Name, | 312 | Name: v.Name, |
| @@ -623,7 +626,7 @@ func LoginAuthBySecretKey(secretKey string) (protocol.LoginAuthToken, error) { | @@ -623,7 +626,7 @@ func LoginAuthBySecretKey(secretKey string) (protocol.LoginAuthToken, error) { | ||
| 623 | if ok := businessAdminResp.IsOK(); !ok { | 626 | if ok := businessAdminResp.IsOK(); !ok { |
| 624 | return logintoken, protocol.ErrWithMessage{ | 627 | return logintoken, protocol.ErrWithMessage{ |
| 625 | ErrorCode: protocol.ErrorCode{ | 628 | ErrorCode: protocol.ErrorCode{ |
| 626 | - Errno: fmt.Sprint(businessAdminResp.Code), | 629 | + Errno: "-1", |
| 627 | Errmsg: businessAdminResp.Msg, | 630 | Errmsg: businessAdminResp.Msg, |
| 628 | }, | 631 | }, |
| 629 | } | 632 | } |
| @@ -12,6 +12,10 @@ import ( | @@ -12,6 +12,10 @@ import ( | ||
| 12 | "time" | 12 | "time" |
| 13 | ) | 13 | ) |
| 14 | 14 | ||
| 15 | +const ( | ||
| 16 | + ResponseOk int = 0 | ||
| 17 | +) | ||
| 18 | + | ||
| 15 | //请求企业平台的接口 | 19 | //请求企业平台的接口 |
| 16 | type IBusinessAdminParam interface { | 20 | type IBusinessAdminParam interface { |
| 17 | Format() []byte | 21 | Format() []byte |
| @@ -72,7 +76,9 @@ type CommResponse struct { | @@ -72,7 +76,9 @@ type CommResponse struct { | ||
| 72 | } | 76 | } |
| 73 | 77 | ||
| 74 | func (resp CommResponse) IsOK() bool { | 78 | func (resp CommResponse) IsOK() bool { |
| 75 | - | 79 | + if resp.Code != ResponseOk { |
| 80 | + return false | ||
| 81 | + } | ||
| 76 | return true | 82 | return true |
| 77 | } | 83 | } |
| 78 | 84 | ||
| @@ -120,3 +126,50 @@ func GetuserAuthDo(userid int64) (ResponseGetUserAuth, error) { | @@ -120,3 +126,50 @@ func GetuserAuthDo(userid int64) (ResponseGetUserAuth, error) { | ||
| 120 | } | 126 | } |
| 121 | return resp, nil | 127 | return resp, nil |
| 122 | } | 128 | } |
| 129 | + | ||
| 130 | +//RequestGetUserCompany 从企业平台获取用户的公司 | ||
| 131 | +type RequestGetUserCompany struct { | ||
| 132 | + Phone string `json:"phone"` | ||
| 133 | + platformId string `json:"platformId"` | ||
| 134 | +} | ||
| 135 | + | ||
| 136 | +type ResponseGetUserCompany struct { | ||
| 137 | + CommResponse | ||
| 138 | + Data struct { | ||
| 139 | + Company []struct { | ||
| 140 | + Id int64 `json:"id"` | ||
| 141 | + Name string `json:"name"` | ||
| 142 | + Logo string `json:"logo"` | ||
| 143 | + } `json:"company"` | ||
| 144 | + } `json:"data"` | ||
| 145 | +} | ||
| 146 | + | ||
| 147 | +func (r RequestGetUserCompany) Format() []byte { | ||
| 148 | + r.platformId = "18" | ||
| 149 | + var bt []byte | ||
| 150 | + bt, _ = json.Marshal(r) | ||
| 151 | + return bt | ||
| 152 | +} | ||
| 153 | + | ||
| 154 | +func (r RequestGetUserCompany) GetPath() (string, string) { | ||
| 155 | + return "/companies/user-company", "POST" | ||
| 156 | +} | ||
| 157 | + | ||
| 158 | +func GetUserCompanyDo(phone string) (ResponseGetUserCompany, error) { | ||
| 159 | + param := RequestGetUserCompany{ | ||
| 160 | + Phone: phone, | ||
| 161 | + } | ||
| 162 | + var resp ResponseGetUserCompany | ||
| 163 | + uclient := NewBusinessAdminClient() | ||
| 164 | + btBody, err := uclient.Call(param) | ||
| 165 | + if err != nil { | ||
| 166 | + log.Error("向企业平台发送请求失败 err:%s", err) | ||
| 167 | + return resp, errors.New("向企业平台发送请求失败") | ||
| 168 | + } | ||
| 169 | + err = json.Unmarshal(btBody, &resp) | ||
| 170 | + if err != nil { | ||
| 171 | + log.Error("解析企业平台响应失败 err:%s", err) | ||
| 172 | + return resp, errors.New("解析企业平台响应失败") | ||
| 173 | + } | ||
| 174 | + return resp, nil | ||
| 175 | +} |
-
请 注册 或 登录 后发表评论