作者 yangfu

用户中心-用户信息

@@ -11,6 +11,7 @@ @@ -11,6 +11,7 @@
11 |用户中心-修改手机号|完成|2019.11.20|/v1/user/changePhone| 11 |用户中心-修改手机号|完成|2019.11.20|/v1/user/changePhone|
12 |用户中心-修改密码|完成|2019.11.20|v1/user/changePassword| 12 |用户中心-修改密码|完成|2019.11.20|v1/user/changePassword|
13 |用户中心-忘记密码|完成|2019.11.20|v1/user/resetPassword| 13 |用户中心-忘记密码|完成|2019.11.20|v1/user/resetPassword|
  14 +|用户中心-用户信息|完成|2019.12.13|v1/user/userInfo|
14 |用户中心-切换企业| | |v1/user/switchCompany| 15 |用户中心-切换企业| | |v1/user/switchCompany|
15 |用户中心-用户公司列表| | |v1/user/companys| 16 |用户中心-用户公司列表| | |v1/user/companys|
16 |机会发布-机会类型| | |v1/chance/chanceType| 17 |机会发布-机会类型| | |v1/chance/chanceType|
@@ -137,3 +137,24 @@ func (this *UserController) SwitchCompany() { @@ -137,3 +137,24 @@ func (this *UserController) SwitchCompany() {
137 header := controllers.GetRequestHeader(this.Ctx) 137 header := controllers.GetRequestHeader(this.Ctx)
138 msg = protocol.NewReturnResponse(user.SwitchCompany(header, request)) 138 msg = protocol.NewReturnResponse(user.SwitchCompany(header, request))
139 } 139 }
  140 +
  141 +//UserInfo
  142 +//@router /userInfo [post]
  143 +func (this *UserController) UserInfo() {
  144 + var msg *protocol.ResponseMessage
  145 + defer func() {
  146 + this.Resp(msg)
  147 + }()
  148 + var request *protocol.UserInfoRequest
  149 + if err := json.Unmarshal(this.ByteBody, &request); err != nil {
  150 + log.Error(err)
  151 + msg = protocol.BadRequestParam(1)
  152 + return
  153 + }
  154 + if b, m := this.Valid(request); !b {
  155 + msg = m
  156 + return
  157 + }
  158 + header := controllers.GetRequestHeader(this.Ctx)
  159 + msg = protocol.NewReturnResponse(user.UserInfo(header, request))
  160 +}
@@ -80,9 +80,18 @@ func DeleteUserCompany(id int) (err error) { @@ -80,9 +80,18 @@ func DeleteUserCompany(id int) (err error) {
80 // Id doesn't exist 80 // Id doesn't exist
81 func GetUserCompanyByUserId(uid int64, companyId int64) (v *UserCompany, err error) { 81 func GetUserCompanyByUserId(uid int64, companyId int64) (v *UserCompany, err error) {
82 o := orm.NewOrm() 82 o := orm.NewOrm()
83 - sql := "select * from user_company where user_id=? and company_id=?" // 83 + sql := "select * from user_company where user_id=? and company_id=? and enable=1" //
84 if err = o.Raw(sql, uid, companyId).QueryRow(&v); err == nil { 84 if err = o.Raw(sql, uid, companyId).QueryRow(&v); err == nil {
85 return v, nil 85 return v, nil
86 } 86 }
87 return nil, err 87 return nil, err
88 } 88 }
  89 +
  90 +func GetUserCompanyFirst(uid int64) (v *UserCompany, err error) {
  91 + o := orm.NewOrm()
  92 + sql := "select * from user_company where user_id=? order by create_at desc limit 1" //
  93 + if err = o.Raw(sql, uid).QueryRow(&v); err == nil {
  94 + return v, nil
  95 + }
  96 + return nil, err
  97 +}
@@ -44,3 +44,62 @@ type SwitchCompanyRequest struct { @@ -44,3 +44,62 @@ type SwitchCompanyRequest struct {
44 } 44 }
45 type SwitchCompanyResponse struct { 45 type SwitchCompanyResponse struct {
46 } 46 }
  47 +
  48 +/*用户信息 UserInfo */
  49 +type UserInfoRequest struct {
  50 +}
  51 +type UserInfoResponse struct {
  52 + User User `json:"user"`
  53 +}
  54 +
  55 +/*
  56 +user object
  57 +必须
  58 +用户对象信息
  59 +备注: 用户对象信息
  60 +
  61 +必须
  62 +用户名称
  63 +phone string
  64 +必须
  65 +手机号码
  66 +image object
  67 +非必须
  68 +用户头像
  69 +备注: 用户头像
  70 +
  71 +did integer
  72 +必须
  73 +部门ID
  74 +department string
  75 +必须
  76 +部门名称
  77 +position string
  78 +必须
  79 +职位名称
  80 +level integer
  81 +必须
  82 +职位级别(员工0,老板1)
  83 +employeeAttr object
  84 +必须
  85 +员工属性
  86 +备注: 员工属性
  87 +
  88 +imToken string
  89 +必须
  90 +网易云信IM Token
  91 +filterModule
  92 +*/
  93 +type User struct {
  94 + UserId int64 `json:"uid"`
  95 + Name string `json:"uname"`
  96 + Phone string `json:"phone"`
  97 + Image Picture `json:"image"`
  98 + Department string `json:"department"`
  99 + Position string `json:"position"`
  100 + ImToken string `json:"imToken"`
  101 +
  102 + //companys
  103 + CompanyId int `json:"company_id"`
  104 + Company string `json:"company"` //公司名称
  105 +}
@@ -263,4 +263,12 @@ func init() { @@ -263,4 +263,12 @@ func init() {
263 MethodParams: param.Make(), 263 MethodParams: param.Make(),
264 Params: nil}) 264 Params: nil})
265 265
  266 + beego.GlobalControllerRouter["opp/controllers/v1:UserController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:UserController"],
  267 + beego.ControllerComments{
  268 + Method: "UserInfo",
  269 + Router: `/userInfo`,
  270 + AllowHTTPMethods: []string{"post"},
  271 + MethodParams: param.Make(),
  272 + Params: nil})
  273 +
266 } 274 }
@@ -71,6 +71,9 @@ func GetUserBaseInfo(uid int64, companyId int64) (v *protocol.BaseUserInfo, err @@ -71,6 +71,9 @@ func GetUserBaseInfo(uid int64, companyId int64) (v *protocol.BaseUserInfo, err
71 71
72 //获取最高层级部门 72 //获取最高层级部门
73 func GetTopDepartment(departments []*protocol.Department) *protocol.Department { 73 func GetTopDepartment(departments []*protocol.Department) *protocol.Department {
  74 + if len(departments) == 0 {
  75 + return &protocol.Department{}
  76 + }
74 var top *protocol.Department 77 var top *protocol.Department
75 var countTop, countTmp = 0, 0 78 var countTop, countTmp = 0, 0
76 for i := range departments { 79 for i := range departments {
@@ -100,6 +103,9 @@ func GetTopDepartment(departments []*protocol.Department) *protocol.Department { @@ -100,6 +103,9 @@ func GetTopDepartment(departments []*protocol.Department) *protocol.Department {
100 func GetTopPosition(positions []*protocol.Position) *protocol.Position { 103 func GetTopPosition(positions []*protocol.Position) *protocol.Position {
101 var top *protocol.Position 104 var top *protocol.Position
102 var countTop, countTmp = 0, 0 105 var countTop, countTmp = 0, 0
  106 + if len(positions) == 0 {
  107 + return &protocol.Position{}
  108 + }
103 for i := range positions { 109 for i := range positions {
104 tmp := positions[i] 110 tmp := positions[i]
105 if i == 0 { 111 if i == 0 {
@@ -253,6 +253,7 @@ func CheckToken(request *protocol.CheckTokenRequest) (rsp *protocol.CheckTokenRe @@ -253,6 +253,7 @@ func CheckToken(request *protocol.CheckTokenRequest) (rsp *protocol.CheckTokenRe
253 } 253 }
254 userAuth, err = repository.UserAuth.GetUserAuthByToken(request.Token) 254 userAuth, err = repository.UserAuth.GetUserAuthByToken(request.Token)
255 if err != nil { 255 if err != nil {
  256 + log.Error("查询失败: token:", request.Token, err)
256 err = protocol.NewErrWithMessage(4141, err) 257 err = protocol.NewErrWithMessage(4141, err)
257 return 258 return
258 } 259 }
@@ -205,3 +205,57 @@ func SwitchCompany(header *protocol.RequestHeader, request *protocol.SwitchCompa @@ -205,3 +205,57 @@ func SwitchCompany(header *protocol.RequestHeader, request *protocol.SwitchCompa
205 } 205 }
206 return 206 return
207 } 207 }
  208 +
  209 +//用户信息
  210 +func UserInfo(header *protocol.RequestHeader, request *protocol.UserInfoRequest) (rsp *protocol.UserInfoResponse, err error) {
  211 + var (
  212 + companyId = header.CompanyId
  213 + company *models.UserCompany
  214 + baseInfo *protocol.BaseUserInfo
  215 + userAuth *models.UserAuth
  216 + user *models.User
  217 + )
  218 +
  219 + if companyId == 0 {
  220 + if company, err = models.GetUserCompanyFirst(header.Uid); err != nil {
  221 + log.Error(err)
  222 + return
  223 + }
  224 + if userAuth, err = models.GetUserAuthByUserId(header.Uid, 1); err != nil {
  225 + log.Error(err)
  226 + return
  227 + }
  228 + if err = utils.UpdateTableByMap(&models.UserAuth{Id: userAuth.Id}, map[string]interface{}{"CurrentCompanyId": companyId}); err != nil {
  229 + log.Error(err)
  230 + return
  231 + }
  232 + companyId = int64(company.Id)
  233 + }
  234 + if user, err = models.GetUsersById(header.Uid); err != nil {
  235 + log.Error(err)
  236 + return
  237 + }
  238 + if baseInfo, err = agg.GetUserBaseInfo(header.Uid, companyId); err != nil {
  239 + log.Error(err)
  240 + return
  241 + }
  242 + rsp = &protocol.UserInfoResponse{
  243 + User: protocol.User{
  244 + UserId: baseInfo.UserId,
  245 + Name: baseInfo.NickName,
  246 + Phone: user.Phone,
  247 + Image: protocol.Picture{
  248 + Path: user.Icon,
  249 + //TODO:图片裁剪
  250 + H: 0,
  251 + W: 0,
  252 + },
  253 + Department: baseInfo.Department,
  254 + Position: baseInfo.Position,
  255 + ImToken: user.ImToken,
  256 + CompanyId: int(companyId),
  257 + Company: baseInfo.CompanyName,
  258 + },
  259 + }
  260 + return
  261 +}
@@ -119,34 +119,6 @@ data.module 有权限的模块 @@ -119,34 +119,6 @@ data.module 有权限的模块
119 } 119 }
120 ``` 120 ```
121 121
122 -### 获取token  
123 -  
124 -* URL: /v1/auth/accessToken  
125 -* 格式: JSON  
126 -* HTTP请求方式: POST  
127 -* 请求示例  
128 -```json  
129 -{  
130 - "clientId":"lks3Z8Ncn2j",  
131 - "clientSecret":"gtfhyjukiol3Qncbvmdwe67khh",  
132 - "authCode":"5251839614a611eaab01000c29ad8d6d"  
133 -}  
134 -```  
135 -  
136 -  
137 -* 应答示例  
138 -```json  
139 -{  
140 - "code": 0,  
141 - "msg": "成功",  
142 - "data": {  
143 - "refreshToken": "8debc5a314a611eaab01000c29ad8d6d",  
144 - "accessToken": "8debc59814a611eaab01000c29ad8d6d",  
145 - "expiresIn": 3600  
146 - }  
147 -}  
148 -```  
149 -  
150 ### 刷新token 122 ### 刷新token
151 123
152 * URL: /v1/auth/refreshToken 124 * URL: /v1/auth/refreshToken
@@ -306,4 +278,39 @@ data.module 有权限的模块 @@ -306,4 +278,39 @@ data.module 有权限的模块
306 "msg": "成功", 278 "msg": "成功",
307 "data":{} 279 "data":{}
308 } 280 }
  281 +```
  282 +
  283 +### 用户信息
  284 +* URL: /v1/user/userInfo
  285 +* 格式: JSON
  286 +* HTTP请求方式: POST
  287 +* 请求示例
  288 +```json
  289 +{
  290 +}
  291 +```
  292 +
  293 +* 应答示例
  294 +```json
  295 +{
  296 + "code": 0,
  297 + "msg": "成功",
  298 + "data": {
  299 + "user": {
  300 + "uid": 1,
  301 + "uname": "Jennifer Clark",
  302 + "phone": "18065048301",
  303 + "image": {
  304 + "path": "https://wx.qlogo.cn/mmopen/vi_32/AA24UDKOHgm9gy631bhPkjbrhQysEicjQLDibACO3DNksPpLuuwOYVhUPCDFud0W07wuICfkmhYng3ZtQo59Juzw/132",
  305 + "w": 0,
  306 + "h": 0
  307 + },
  308 + "department": "部门1",
  309 + "position": "董事长",
  310 + "imToken": "741df673c1671f8fad6d5d20adfa165e",
  311 + "company_id": 1,
  312 + "company": "test_company"
  313 + }
  314 + }
  315 +}
309 ``` 316 ```