...
|
...
|
@@ -9,6 +9,7 @@ import ( |
|
|
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/domain"
|
|
|
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/log"
|
|
|
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/protocol"
|
|
|
protocolx "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/protocol/auth"
|
|
|
"strconv"
|
|
|
"strings"
|
|
|
)
|
...
|
...
|
@@ -20,8 +21,10 @@ func UserInfo(header *protocol.RequestHeader, request *protocol.UserInfoRequest) |
|
|
transactionContext, _ = factory.CreateTransactionContext(nil)
|
|
|
CompanyResponsitory, _ = factory.CreateCompanyRepository(transactionContext)
|
|
|
PartnerInfoService, _ = factory.CreatePartnerInfoRepositoryIn(transactionContext)
|
|
|
UsersRepository, _ = factory.CreateUsersRepository(transactionContext)
|
|
|
ImInfoRepository, _ = factory.CreateImInfoRepository(transactionContext)
|
|
|
company *domain.Company
|
|
|
user *domain.Users
|
|
|
)
|
|
|
if err = transactionContext.StartTransaction(); err != nil {
|
|
|
return nil, err
|
...
|
...
|
@@ -30,11 +33,13 @@ func UserInfo(header *protocol.RequestHeader, request *protocol.UserInfoRequest) |
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
rsp = &protocol.UserInfoResponse{}
|
|
|
|
|
|
funcPartnerInfo := func() {
|
|
|
if partnerInfo, err = PartnerInfoService.FindOne(map[string]interface{}{"id": header.UserId}); err != nil {
|
|
|
err = protocol.NewErrWithMessage(502, err) //账号不存在
|
|
|
return
|
|
|
}
|
|
|
if company, err = CompanyResponsitory.FindOne(map[string]interface{}{"id": 1}); err != nil {
|
|
|
if company, err = CompanyResponsitory.FindOne(map[string]interface{}{"id": header.CompanyId}); err != nil {
|
|
|
return
|
|
|
}
|
|
|
rsp.User = protocol.User{
|
...
|
...
|
@@ -56,7 +61,43 @@ func UserInfo(header *protocol.RequestHeader, request *protocol.UserInfoRequest) |
|
|
} else {
|
|
|
rsp.User.Salesman = map[string]interface{}{}
|
|
|
}
|
|
|
if imInfo, e := ImInfoRepository.FindOne(map[string]interface{}{"user_id": partnerInfo.Id}); e == nil && imInfo != nil {
|
|
|
}
|
|
|
funcManagerInfo := func() {
|
|
|
if user, err = UsersRepository.FindOne(map[string]interface{}{"id": header.UserId}); err != nil {
|
|
|
err = protocol.NewErrWithMessage(502, err) //账号不存在
|
|
|
return
|
|
|
}
|
|
|
if company, err = CompanyResponsitory.FindOne(map[string]interface{}{"id": header.CompanyId}); err != nil {
|
|
|
return
|
|
|
}
|
|
|
rsp.User = protocol.User{
|
|
|
Id: user.Id,
|
|
|
PartnerName: user.Name,
|
|
|
Phone: user.Phone,
|
|
|
CooperateCompany: protocol.Company{
|
|
|
Id: company.Id,
|
|
|
Name: company.Name,
|
|
|
Phone: company.Phone,
|
|
|
},
|
|
|
//JoinWay: partnerInfo.PartnerCategoryInfo(),
|
|
|
//District: map[string]interface{}{"id": partnerInfo.RegionInfo.RegionId, "name": partnerInfo.RegionInfo.RegionName},
|
|
|
//SerialNo: partnerInfo.Id,
|
|
|
//CooperateTime: partnerInfo.CooperateTime.Unix() * 1000,
|
|
|
}
|
|
|
}
|
|
|
switch header.AdminType {
|
|
|
case int(protocolx.AdminTypePartner):
|
|
|
funcPartnerInfo()
|
|
|
break
|
|
|
case int(protocolx.AdminTypeManager):
|
|
|
funcManagerInfo()
|
|
|
break
|
|
|
default:
|
|
|
funcPartnerInfo()
|
|
|
break
|
|
|
}
|
|
|
|
|
|
if imInfo, e := ImInfoRepository.FindOne(map[string]interface{}{"user_id": header.SimNum}); e == nil && imInfo != nil {
|
|
|
rsp.User.ImToken = imInfo.ImToken
|
|
|
rsp.User.AccountID, _ = strconv.ParseInt(imInfo.ImId, 10, 64)
|
|
|
rsp.User.CsAccountID = fmt.Sprintf("%v", imInfo.CustomerImId)
|
...
|
...
|
@@ -221,3 +262,109 @@ func ChangePassword(header *protocol.RequestHeader, request *protocol.ChangePass |
|
|
err = transactionContext.CommitTransaction()
|
|
|
return
|
|
|
}
|
|
|
|
|
|
func UserInfoV2(header *protocol.RequestHeader, request *protocol.UserInfoRequest) (rsp interface{}, err error) {
|
|
|
var (
|
|
|
partnerInfo *domain.PartnerInfo
|
|
|
transactionContext, _ = factory.CreateTransactionContext(nil)
|
|
|
CompanyResponsitory, _ = factory.CreateCompanyRepository(transactionContext)
|
|
|
PartnerInfoService, _ = factory.CreatePartnerInfoRepositoryIn(transactionContext)
|
|
|
UsersRepository, _ = factory.CreateUsersRepository(transactionContext)
|
|
|
company *domain.Company
|
|
|
user *domain.Users
|
|
|
)
|
|
|
if err = transactionContext.StartTransaction(); err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
defer func() {
|
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
rsp = &protocol.UserInfoResponse{}
|
|
|
|
|
|
type xcompany struct {
|
|
|
Id int64 `json:"id"`
|
|
|
Name string `json:"name"`
|
|
|
Phone string `json:"phone"`
|
|
|
//合作区域
|
|
|
District interface{} `json:"district"`
|
|
|
//合作编码
|
|
|
SerialNo int64 `json:"serialNo"`
|
|
|
//合作时间
|
|
|
CooperateTime int64 `json:"cooperationTime"`
|
|
|
Salesman interface{} `json:"salesman"`
|
|
|
}
|
|
|
type xuser struct {
|
|
|
Id int64 `json:"uid"`
|
|
|
//用户名称
|
|
|
PartnerName string `json:"uname"`
|
|
|
//手机号
|
|
|
Phone string `json:"phone"`
|
|
|
//合作公司
|
|
|
CooperateCompany xcompany `json:"company"`
|
|
|
}
|
|
|
rspMap := make(map[string]interface{})
|
|
|
funcPartnerInfo := func() {
|
|
|
if partnerInfo, err = PartnerInfoService.FindOne(map[string]interface{}{"id": header.UserId}); err != nil {
|
|
|
err = protocol.NewErrWithMessage(502, err) //账号不存在
|
|
|
return
|
|
|
}
|
|
|
if company, err = CompanyResponsitory.FindOne(map[string]interface{}{"id": header.CompanyId}); err != nil {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
u := xuser{
|
|
|
Id: partnerInfo.Id,
|
|
|
PartnerName: partnerInfo.PartnerName,
|
|
|
Phone: partnerInfo.Account,
|
|
|
CooperateCompany: xcompany{
|
|
|
Id: company.Id,
|
|
|
Name: company.Name,
|
|
|
Phone: company.Phone,
|
|
|
SerialNo: partnerInfo.Id,
|
|
|
CooperateTime: partnerInfo.CooperateTime.Unix() * 1000,
|
|
|
//JoinWay: partnerInfo.PartnerCategoryInfo(),
|
|
|
District: map[string]interface{}{"id": partnerInfo.RegionInfo.RegionId, "name": partnerInfo.RegionInfo.RegionName},
|
|
|
},
|
|
|
}
|
|
|
if len(partnerInfo.Salesman) > 0 {
|
|
|
u.CooperateCompany.Salesman = map[string]interface{}{"uname": partnerInfo.Salesman[0].Name, "phone": partnerInfo.Salesman[0].Telephone}
|
|
|
} else {
|
|
|
u.CooperateCompany.Salesman = map[string]interface{}{}
|
|
|
}
|
|
|
rspMap["User"] = u
|
|
|
rsp = rspMap
|
|
|
}
|
|
|
funcManagerInfo := func() {
|
|
|
if user, err = UsersRepository.FindOne(map[string]interface{}{"id": header.UserId}); err != nil {
|
|
|
err = protocol.NewErrWithMessage(502, err) //账号不存在
|
|
|
return
|
|
|
}
|
|
|
if company, err = CompanyResponsitory.FindOne(map[string]interface{}{"id": header.CompanyId}); err != nil {
|
|
|
return
|
|
|
}
|
|
|
rspMap["User"] = xuser{
|
|
|
Id: user.Id,
|
|
|
PartnerName: user.Name,
|
|
|
Phone: user.Phone,
|
|
|
CooperateCompany: xcompany{
|
|
|
Id: company.Id,
|
|
|
Name: company.Name,
|
|
|
Phone: company.Phone,
|
|
|
},
|
|
|
}
|
|
|
rsp = rspMap
|
|
|
}
|
|
|
switch header.AdminType {
|
|
|
case int(protocolx.AdminTypePartner):
|
|
|
funcPartnerInfo()
|
|
|
break
|
|
|
case int(protocolx.AdminTypeManager):
|
|
|
funcManagerInfo()
|
|
|
break
|
|
|
default:
|
|
|
funcPartnerInfo()
|
|
|
break
|
|
|
}
|
|
|
err = transactionContext.CommitTransaction()
|
|
|
return
|
|
|
} |
...
|
...
|
|