...
|
...
|
@@ -227,7 +227,7 @@ func LoginAuthByUCenter(account, password string) (protocol.LoginAuthToken, erro |
|
|
err error
|
|
|
logintoken protocol.LoginAuthToken
|
|
|
uclientReturn ucenter.ResponseLogin
|
|
|
companyids []int64
|
|
|
companys []companybase
|
|
|
companyid int64
|
|
|
userdata *models.User
|
|
|
)
|
...
|
...
|
@@ -240,15 +240,15 @@ func LoginAuthByUCenter(account, password string) (protocol.LoginAuthToken, erro |
|
|
log.Debug("userdata.IsEnable()==false")
|
|
|
return logintoken, protocol.NewErrWithMessage("10021")
|
|
|
}
|
|
|
if companyids, err = getUserCompanyReal(userdata.Id); err != nil {
|
|
|
if companys, err = getUserCompanyReal(userdata.Id); err != nil {
|
|
|
log.Error("getUserCompanyReal err:%s", err)
|
|
|
return logintoken, protocol.NewErrWithMessage("10021")
|
|
|
}
|
|
|
if len(companyids) == 0 {
|
|
|
if len(companys) == 0 {
|
|
|
log.Debug("no company")
|
|
|
return logintoken, protocol.NewErrWithMessage("10021")
|
|
|
}
|
|
|
companyid = companyids[0]
|
|
|
companyid = companys[0].Id
|
|
|
param := ucenter.RequesLogin{
|
|
|
Phone: account,
|
|
|
Password: password,
|
...
|
...
|
@@ -272,23 +272,30 @@ func LoginAuthByUCenter(account, password string) (protocol.LoginAuthToken, erro |
|
|
return logintoken, err
|
|
|
}
|
|
|
|
|
|
type companybase struct {
|
|
|
Id int64 `orm:"column(id)"`
|
|
|
Name string `orm:"coumn(name)"`
|
|
|
Logo string `orm:"coumn(logo)"`
|
|
|
}
|
|
|
|
|
|
//getUserCompanyReal 获取用户有效的公司id
|
|
|
func getUserCompanyReal(userid int64) (companyids []int64, err error) {
|
|
|
func getUserCompanyReal(userid int64) (companyids []companybase, err error) {
|
|
|
const (
|
|
|
datasql0 string = `SELECT b.company_id FROM user_company AS b
|
|
|
WHERE b.delete_at=0 AND b.enable = 1 AND b.user_id=?`
|
|
|
datasql2 string = `SELECT b.id FROM company AS b
|
|
|
datasql2 string = `SELECT b.id,a.name,a.logo FROM company AS b
|
|
|
WHERE b.delete_at=0 AND b.enable = 1 AND b.id in (%s) `
|
|
|
)
|
|
|
var (
|
|
|
ids []string
|
|
|
companys []companybase
|
|
|
ids []string
|
|
|
)
|
|
|
err = utils.ExecuteQueryAll(&ids, datasql0, userid)
|
|
|
if err != nil {
|
|
|
log.Error("EXECUTE SQL err:%s", err)
|
|
|
return nil, err
|
|
|
}
|
|
|
if len(ids) == 0 {
|
|
|
if len(companys) == 0 {
|
|
|
return nil, nil
|
|
|
}
|
|
|
datasql3 := fmt.Sprintf(datasql2, strings.Join(ids, ","))
|
...
|
...
|
@@ -297,5 +304,45 @@ func getUserCompanyReal(userid int64) (companyids []int64, err error) { |
|
|
log.Error("EXECUTE SQL err:%s", err)
|
|
|
return nil, err
|
|
|
}
|
|
|
return companyids, nil
|
|
|
return companys, nil
|
|
|
}
|
|
|
|
|
|
func UserBaseInfo(userid, companyid int64) (protocol.ResponseMeInfo, error) {
|
|
|
var (
|
|
|
err error
|
|
|
userinfo *models.User
|
|
|
companylist []companybase
|
|
|
meInfo protocol.ResponseMeInfo
|
|
|
currentCompany *models.Company
|
|
|
)
|
|
|
userinfo, err = models.GetUserById(userid)
|
|
|
if err != nil {
|
|
|
log.Error("GetUserById(%d) err:%s", userid, err)
|
|
|
return meInfo, protocol.NewErrWithMessage("1", err)
|
|
|
}
|
|
|
currentCompany, err = models.GetCompanyById(companyid)
|
|
|
if err != nil {
|
|
|
log.Error("GetCompanyById(%d) err:%s", companyid, err)
|
|
|
return meInfo, protocol.NewErrWithMessage("1", err)
|
|
|
}
|
|
|
companylist, err = getUserCompanyReal(userid)
|
|
|
if err != nil {
|
|
|
log.Error("getUserCompanyReal(%d) err:%s", userid, err)
|
|
|
return meInfo, protocol.NewErrWithMessage("1", err)
|
|
|
}
|
|
|
meInfo = protocol.ResponseMeInfo{
|
|
|
NickName: userinfo.NickName,
|
|
|
Icon: userinfo.Icon,
|
|
|
Companyid: currentCompany.Id,
|
|
|
Companyname: currentCompany.Name,
|
|
|
Logo: currentCompany.Logo,
|
|
|
}
|
|
|
for _, v := range companylist {
|
|
|
t := protocol.MeCompany{
|
|
|
Id: v.Id,
|
|
|
Name: v.Name,
|
|
|
}
|
|
|
meInfo.Companys = append(meInfo.Companys, t)
|
|
|
}
|
|
|
return meInfo, nil
|
|
|
} |
...
|
...
|
|