作者 tangxvhui

更新

... ... @@ -88,7 +88,13 @@ func (e ErrWithMessage) Unwrap() error {
//ParseToMessage 实现CustomErrParse的接口
func (e ErrWithMessage) ParseToMessage() *ResponseMessage {
return NewMessage(e.Errno)
rsp := &ResponseMessage{
Errno: transformCode(e.Errno),
Errmsg: e.Errmsg,
Data: NullData,
OriginErrno: e.Errno,
}
return rsp
}
func SearchErr(code string) ErrorCode {
... ...
... ... @@ -294,16 +294,19 @@ func UserBaseInfo(userid, companyid int64) (protocol.ResponseMeInfo, error) {
func UserHasCompanys(userid int64) ([]protocol.MeCompany, error) {
var (
companylist []companybase
err error
mecompanys []protocol.MeCompany
userData *models.User
err error
mecompanys []protocol.MeCompany
)
companylist, err = getUserCompanyReal(userid)
userData, err = models.GetUserById(userid)
if err != nil {
log.Error("getUserCompanyReal(%d) err:%s", userid, err)
return nil, protocol.NewErrWithMessage("1", err)
return mecompanys, fmt.Errorf("获取用户数据失败")
}
for _, v := range companylist {
resp, err := serverplatform.GetUserCompanyDo(userData.Phone)
if err != nil {
return mecompanys, fmt.Errorf("获取数据失败:%s", err)
}
for _, v := range resp.Data.Company {
t := protocol.MeCompany{
Id: v.Id,
Name: v.Name,
... ... @@ -623,7 +626,7 @@ func LoginAuthBySecretKey(secretKey string) (protocol.LoginAuthToken, error) {
if ok := businessAdminResp.IsOK(); !ok {
return logintoken, protocol.ErrWithMessage{
ErrorCode: protocol.ErrorCode{
Errno: fmt.Sprint(businessAdminResp.Code),
Errno: "-1",
Errmsg: businessAdminResp.Msg,
},
}
... ...
... ... @@ -12,6 +12,10 @@ import (
"time"
)
const (
ResponseOk int = 0
)
//请求企业平台的接口
type IBusinessAdminParam interface {
Format() []byte
... ... @@ -72,7 +76,9 @@ type CommResponse struct {
}
func (resp CommResponse) IsOK() bool {
if resp.Code != ResponseOk {
return false
}
return true
}
... ... @@ -120,3 +126,50 @@ func GetuserAuthDo(userid int64) (ResponseGetUserAuth, error) {
}
return resp, nil
}
//RequestGetUserCompany 从企业平台获取用户的公司
type RequestGetUserCompany struct {
Phone string `json:"phone"`
platformId string `json:"platformId"`
}
type ResponseGetUserCompany struct {
CommResponse
Data struct {
Company []struct {
Id int64 `json:"id"`
Name string `json:"name"`
Logo string `json:"logo"`
} `json:"company"`
} `json:"data"`
}
func (r RequestGetUserCompany) Format() []byte {
r.platformId = "18"
var bt []byte
bt, _ = json.Marshal(r)
return bt
}
func (r RequestGetUserCompany) GetPath() (string, string) {
return "/companies/user-company", "POST"
}
func GetUserCompanyDo(phone string) (ResponseGetUserCompany, error) {
param := RequestGetUserCompany{
Phone: phone,
}
var resp ResponseGetUserCompany
uclient := NewBusinessAdminClient()
btBody, err := uclient.Call(param)
if err != nil {
log.Error("向企业平台发送请求失败 err:%s", err)
return resp, errors.New("向企业平台发送请求失败")
}
err = json.Unmarshal(btBody, &resp)
if err != nil {
log.Error("解析企业平台响应失败 err:%s", err)
return resp, errors.New("解析企业平台响应失败")
}
return resp, nil
}
... ...