|
@@ -3,7 +3,10 @@ package user
|
|
|
import (
|
|
|
"eta_mini_ht_api/common/component/cache"
|
|
|
logger "eta_mini_ht_api/common/component/log"
|
|
|
+ "eta_mini_ht_api/common/exception"
|
|
|
+ authUtils "eta_mini_ht_api/common/utils/auth"
|
|
|
"eta_mini_ht_api/controllers"
|
|
|
+ "eta_mini_ht_api/service/user"
|
|
|
"fmt"
|
|
|
)
|
|
|
|
|
@@ -31,3 +34,149 @@ func (u *UserController) Get() {
|
|
|
fmt.Print("查询用户列表")
|
|
|
u.ServeJSON()
|
|
|
}
|
|
|
+
|
|
|
+type FeedbackReq struct {
|
|
|
+ Mobile string `json:"mobile"`
|
|
|
+ Message string `json:"message"`
|
|
|
+}
|
|
|
+
|
|
|
+type FollowAnalystReq struct {
|
|
|
+ AnalystId int `json:"analystId"`
|
|
|
+ FollowType string `json:"followType"`
|
|
|
+ Mobile string `json:"mobile"`
|
|
|
+}
|
|
|
+
|
|
|
+// Feedback 用户意见反馈
|
|
|
+// @Summary 用户意见反馈
|
|
|
+// @Description 用户意见反馈
|
|
|
+// @Success 200 {object} controllers.BaseResponse
|
|
|
+// @router /feedback [post]
|
|
|
+func (u *UserController) Feedback() {
|
|
|
+ controllers.Wrap(&u.BaseController, func() (result *controllers.WrapData, err error) {
|
|
|
+ result = u.InitWrapData("提交反馈失败")
|
|
|
+ feedback := new(FeedbackReq)
|
|
|
+ u.GetPostParams(feedback)
|
|
|
+ if !authUtils.IsValidMobile(feedback.Mobile) {
|
|
|
+ u.FailedResult("手机号非法", result)
|
|
|
+ err = exception.New(exception.IllegalPhoneNumber)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ var userInfo user.User
|
|
|
+ userInfo = u.Data["user"].(user.User)
|
|
|
+ if userInfo.Mobile != feedback.Mobile {
|
|
|
+ u.FailedResult("非当前用户的手机号提交", result)
|
|
|
+ err = exception.New(exception.NotCurrentUserError)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if feedback.Message == "" {
|
|
|
+ u.FailedResult("反馈信息不能为空", result)
|
|
|
+ err = exception.New(exception.FeedBackMsgEmpty)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ err = user.FeedBack(userInfo.Id, feedback.Mobile, feedback.Message)
|
|
|
+ if err != nil {
|
|
|
+ err = exception.New(exception.FeedBackError)
|
|
|
+ u.FailedResult("提交反馈失败", result)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ u.SuccessResult("提交反馈成功", nil, result)
|
|
|
+ return
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+type FollowResp struct {
|
|
|
+ AnalystId int `json:"analystId"`
|
|
|
+ FollowedType string `json:"FollowedType"`
|
|
|
+}
|
|
|
+
|
|
|
+// FollowAnalyst 关注研究员
|
|
|
+// @Summary 关注研究员
|
|
|
+// @Description 关注研究员
|
|
|
+// @Success 200 {object} controllers.BaseResponse
|
|
|
+// @router /followAnalyst [post]
|
|
|
+func (u *UserController) FollowAnalyst() {
|
|
|
+ controllers.Wrap(&u.BaseController, func() (result *controllers.WrapData, err error) {
|
|
|
+ result = u.InitWrapData("")
|
|
|
+ followAnalyst := new(FollowAnalystReq)
|
|
|
+ u.GetPostParams(followAnalyst)
|
|
|
+ if !authUtils.IsValidMobile(followAnalyst.Mobile) {
|
|
|
+ u.FailedResult("手机号非法", result)
|
|
|
+ err = exception.New(exception.IllegalPhoneNumber)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ var userInfo user.User
|
|
|
+ userInfo = u.Data["user"].(user.User)
|
|
|
+ if userInfo.Mobile != followAnalyst.Mobile {
|
|
|
+ u.FailedResult("非当前用户的手机号提交", result)
|
|
|
+ err = exception.New(exception.NotCurrentUserError)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if !checkFollowType(followAnalyst.FollowType) {
|
|
|
+ u.FailedResult("关注状态非法", result)
|
|
|
+ err = exception.New(exception.IllegalFollowType)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ var msg string
|
|
|
+ switch followAnalyst.FollowType {
|
|
|
+ case "following":
|
|
|
+ msg = "关注研究员"
|
|
|
+ case "unfollowed":
|
|
|
+ msg = "取消关注研究员"
|
|
|
+ }
|
|
|
+ err = user.FollowAnalyst(userInfo.Id, followAnalyst.AnalystId, followAnalyst.FollowType)
|
|
|
+ if err != nil {
|
|
|
+ u.FailedResult(msg+"失败", result)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ resp := FollowResp{
|
|
|
+ AnalystId: followAnalyst.AnalystId,
|
|
|
+ FollowedType: followAnalyst.FollowType,
|
|
|
+ }
|
|
|
+ u.SuccessResult(msg+"成功", resp, result)
|
|
|
+ return
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+func checkFollowType(followType string) bool {
|
|
|
+ return followType == "following" || followType == "unfollowed"
|
|
|
+}
|
|
|
+
|
|
|
+// AnalystDetail 研究员详情
|
|
|
+// @Summary 研究员详情
|
|
|
+// @Description 研究员详情
|
|
|
+// @Success 200 {object} controllers.BaseResponse
|
|
|
+// @router /analystDetail [get]
|
|
|
+func (u *UserController) AnalystDetail(analystId int) {
|
|
|
+ controllers.Wrap(&u.BaseController, func() (result *controllers.WrapData, err error) {
|
|
|
+ result = u.InitWrapData("获取研究员详情失败")
|
|
|
+ fmt.Println(analystId)
|
|
|
+ userInfo := u.Data["user"].(user.User)
|
|
|
+ detail, err := user.GetAnalystDetail(userInfo.Id, analystId)
|
|
|
+ if err != nil {
|
|
|
+ u.FailedResult("获取研究员详情失败", result)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ u.SuccessResult("获取研究员详情成功", detail, result)
|
|
|
+ return
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+// FollowingAnalysts 关注研究员列表
|
|
|
+// @Summary 研究员详情
|
|
|
+// @Description 研究员详情
|
|
|
+// @Success 200 {object} controllers.BaseResponse
|
|
|
+// @router /followingAnalysts [get]
|
|
|
+func (u *UserController) FollowingAnalysts(analystId int) {
|
|
|
+ controllers.Wrap(&u.BaseController, func() (result *controllers.WrapData, err error) {
|
|
|
+ result = u.InitWrapData("获取研究员详情失败")
|
|
|
+ fmt.Println(analystId)
|
|
|
+ userInfo := u.Data["user"].(user.User)
|
|
|
+ detail, err := user.GetAnalystDetail(userInfo.Id, analystId)
|
|
|
+ if err != nil {
|
|
|
+ u.FailedResult("获取研究员详情失败", result)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ u.SuccessResult("获取研究员详情成功", detail, result)
|
|
|
+ return
|
|
|
+ })
|
|
|
+}
|