作者 yangfu

用户中心-用户信息

... ... @@ -11,6 +11,7 @@
|用户中心-修改手机号|完成|2019.11.20|/v1/user/changePhone|
|用户中心-修改密码|完成|2019.11.20|v1/user/changePassword|
|用户中心-忘记密码|完成|2019.11.20|v1/user/resetPassword|
|用户中心-用户信息|完成|2019.12.13|v1/user/userInfo|
|用户中心-切换企业| | |v1/user/switchCompany|
|用户中心-用户公司列表| | |v1/user/companys|
|机会发布-机会类型| | |v1/chance/chanceType|
... ...
... ... @@ -137,3 +137,24 @@ func (this *UserController) SwitchCompany() {
header := controllers.GetRequestHeader(this.Ctx)
msg = protocol.NewReturnResponse(user.SwitchCompany(header, request))
}
//UserInfo
//@router /userInfo [post]
func (this *UserController) UserInfo() {
var msg *protocol.ResponseMessage
defer func() {
this.Resp(msg)
}()
var request *protocol.UserInfoRequest
if err := json.Unmarshal(this.ByteBody, &request); err != nil {
log.Error(err)
msg = protocol.BadRequestParam(1)
return
}
if b, m := this.Valid(request); !b {
msg = m
return
}
header := controllers.GetRequestHeader(this.Ctx)
msg = protocol.NewReturnResponse(user.UserInfo(header, request))
}
... ...
... ... @@ -80,9 +80,18 @@ func DeleteUserCompany(id int) (err error) {
// Id doesn't exist
func GetUserCompanyByUserId(uid int64, companyId int64) (v *UserCompany, err error) {
o := orm.NewOrm()
sql := "select * from user_company where user_id=? and company_id=?" //
sql := "select * from user_company where user_id=? and company_id=? and enable=1" //
if err = o.Raw(sql, uid, companyId).QueryRow(&v); err == nil {
return v, nil
}
return nil, err
}
func GetUserCompanyFirst(uid int64) (v *UserCompany, err error) {
o := orm.NewOrm()
sql := "select * from user_company where user_id=? order by create_at desc limit 1" //
if err = o.Raw(sql, uid).QueryRow(&v); err == nil {
return v, nil
}
return nil, err
}
... ...
... ... @@ -44,3 +44,62 @@ type SwitchCompanyRequest struct {
}
type SwitchCompanyResponse struct {
}
/*用户信息 UserInfo */
type UserInfoRequest struct {
}
type UserInfoResponse struct {
User User `json:"user"`
}
/*
user object
必须
用户对象信息
备注: 用户对象信息
必须
用户名称
phone string
必须
手机号码
image object
非必须
用户头像
备注: 用户头像
did integer
必须
部门ID
department string
必须
部门名称
position string
必须
职位名称
level integer
必须
职位级别(员工0,老板1)
employeeAttr object
必须
员工属性
备注: 员工属性
imToken string
必须
网易云信IM Token
filterModule
*/
type User struct {
UserId int64 `json:"uid"`
Name string `json:"uname"`
Phone string `json:"phone"`
Image Picture `json:"image"`
Department string `json:"department"`
Position string `json:"position"`
ImToken string `json:"imToken"`
//companys
CompanyId int `json:"company_id"`
Company string `json:"company"` //公司名称
}
... ...
... ... @@ -263,4 +263,12 @@ func init() {
MethodParams: param.Make(),
Params: nil})
beego.GlobalControllerRouter["opp/controllers/v1:UserController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:UserController"],
beego.ControllerComments{
Method: "UserInfo",
Router: `/userInfo`,
AllowHTTPMethods: []string{"post"},
MethodParams: param.Make(),
Params: nil})
}
... ...
... ... @@ -71,6 +71,9 @@ func GetUserBaseInfo(uid int64, companyId int64) (v *protocol.BaseUserInfo, err
//获取最高层级部门
func GetTopDepartment(departments []*protocol.Department) *protocol.Department {
if len(departments) == 0 {
return &protocol.Department{}
}
var top *protocol.Department
var countTop, countTmp = 0, 0
for i := range departments {
... ... @@ -100,6 +103,9 @@ func GetTopDepartment(departments []*protocol.Department) *protocol.Department {
func GetTopPosition(positions []*protocol.Position) *protocol.Position {
var top *protocol.Position
var countTop, countTmp = 0, 0
if len(positions) == 0 {
return &protocol.Position{}
}
for i := range positions {
tmp := positions[i]
if i == 0 {
... ...
... ... @@ -253,6 +253,7 @@ func CheckToken(request *protocol.CheckTokenRequest) (rsp *protocol.CheckTokenRe
}
userAuth, err = repository.UserAuth.GetUserAuthByToken(request.Token)
if err != nil {
log.Error("查询失败: token:", request.Token, err)
err = protocol.NewErrWithMessage(4141, err)
return
}
... ...
... ... @@ -205,3 +205,57 @@ func SwitchCompany(header *protocol.RequestHeader, request *protocol.SwitchCompa
}
return
}
//用户信息
func UserInfo(header *protocol.RequestHeader, request *protocol.UserInfoRequest) (rsp *protocol.UserInfoResponse, err error) {
var (
companyId = header.CompanyId
company *models.UserCompany
baseInfo *protocol.BaseUserInfo
userAuth *models.UserAuth
user *models.User
)
if companyId == 0 {
if company, err = models.GetUserCompanyFirst(header.Uid); err != nil {
log.Error(err)
return
}
if userAuth, err = models.GetUserAuthByUserId(header.Uid, 1); err != nil {
log.Error(err)
return
}
if err = utils.UpdateTableByMap(&models.UserAuth{Id: userAuth.Id}, map[string]interface{}{"CurrentCompanyId": companyId}); err != nil {
log.Error(err)
return
}
companyId = int64(company.Id)
}
if user, err = models.GetUsersById(header.Uid); err != nil {
log.Error(err)
return
}
if baseInfo, err = agg.GetUserBaseInfo(header.Uid, companyId); err != nil {
log.Error(err)
return
}
rsp = &protocol.UserInfoResponse{
User: protocol.User{
UserId: baseInfo.UserId,
Name: baseInfo.NickName,
Phone: user.Phone,
Image: protocol.Picture{
Path: user.Icon,
//TODO:图片裁剪
H: 0,
W: 0,
},
Department: baseInfo.Department,
Position: baseInfo.Position,
ImToken: user.ImToken,
CompanyId: int(companyId),
Company: baseInfo.CompanyName,
},
}
return
}
... ...
... ... @@ -119,34 +119,6 @@ data.module 有权限的模块
}
```
### 获取token
* URL: /v1/auth/accessToken
* 格式: JSON
* HTTP请求方式: POST
* 请求示例
```json
{
"clientId":"lks3Z8Ncn2j",
"clientSecret":"gtfhyjukiol3Qncbvmdwe67khh",
"authCode":"5251839614a611eaab01000c29ad8d6d"
}
```
* 应答示例
```json
{
"code": 0,
"msg": "成功",
"data": {
"refreshToken": "8debc5a314a611eaab01000c29ad8d6d",
"accessToken": "8debc59814a611eaab01000c29ad8d6d",
"expiresIn": 3600
}
}
```
### 刷新token
* URL: /v1/auth/refreshToken
... ... @@ -306,4 +278,39 @@ data.module 有权限的模块
"msg": "成功",
"data":{}
}
```
### 用户信息
* URL: /v1/user/userInfo
* 格式: JSON
* HTTP请求方式: POST
* 请求示例
```json
{
}
```
* 应答示例
```json
{
"code": 0,
"msg": "成功",
"data": {
"user": {
"uid": 1,
"uname": "Jennifer Clark",
"phone": "18065048301",
"image": {
"path": "https://wx.qlogo.cn/mmopen/vi_32/AA24UDKOHgm9gy631bhPkjbrhQysEicjQLDibACO3DNksPpLuuwOYVhUPCDFud0W07wuICfkmhYng3ZtQo59Juzw/132",
"w": 0,
"h": 0
},
"department": "部门1",
"position": "董事长",
"imToken": "741df673c1671f8fad6d5d20adfa165e",
"company_id": 1,
"company": "test_company"
}
}
}
```
\ No newline at end of file
... ...