浏览代码

UserQuery

Xingyu Xian 4 月之前
父节点
当前提交
d926bbaf31
共有 5 个文件被更改,包括 128 次插入1 次删除
  1. 63 0
      handler/get_user_info.go
  2. 1 1
      model/gorm_model/user.go
  3. 21 0
      model/http_model/get_user_info.go
  4. 1 0
      route/init.go
  5. 42 0
      service/b_user_info.go

+ 63 - 0
handler/get_user_info.go

@@ -0,0 +1,63 @@
+package handler
+
+import (
+	"youngee_b_api/consts"
+	"youngee_b_api/model/http_model"
+	"youngee_b_api/service"
+	"youngee_b_api/util"
+
+	"github.com/gin-gonic/gin"
+	"github.com/sirupsen/logrus"
+	log "github.com/sirupsen/logrus"
+)
+
+func WrapGetUserInfoHandler(ctx *gin.Context) {
+	handler := newGetUserInfoHandler(ctx)
+	baseRun(handler)
+}
+
+func newGetUserInfoHandler(ctx *gin.Context) *GetUserInfoHandler {
+	return &GetUserInfoHandler{
+		req:  http_model.NewGetUserInfoRequest(),
+		resp: http_model.NewGetUserInfoResponse(),
+		ctx:  ctx,
+	}
+}
+
+type GetUserInfoHandler struct {
+	req  *http_model.GetUserInfoRequest
+	resp *http_model.CommonResponse
+	ctx  *gin.Context
+}
+
+func (h *GetUserInfoHandler) getRequest() interface{} {
+	return h.req
+}
+
+func (h *GetUserInfoHandler) getContext() *gin.Context {
+	return h.ctx
+}
+
+func (h *GetUserInfoHandler) getResponse() interface{} {
+	return h.resp
+}
+
+func (h *GetUserInfoHandler) run() {
+	userData, err := service.BUserInfo.FindBUserInfoByToken(h.ctx, h.req.Token)
+	if err != nil {
+		logrus.Errorf("[CodeLoginHandler] call AuthCode err:%+v\n", err)
+		util.HandlerPackErrorResp(h.resp, consts.ErrorInternal, err.Error())
+		log.Info("login fail,req:%+v", h.req)
+		return
+	}
+	var data *http_model.GetUserInfoData
+	data = userData
+	h.resp.Message = "成功查询用户信息"
+	h.resp.Data = data
+	h.resp.Status = 20000
+	return
+}
+
+func (h *GetUserInfoHandler) checkParam() error {
+	return nil
+}

+ 1 - 1
model/gorm_model/user.go

@@ -10,7 +10,7 @@ type YounggeeUser struct {
 	Username      string    `gorm:"column:username"`                      // 后台用户名
 	Password      string    `gorm:"column:password"`                      // 用户密码
 	RealName      string    `gorm:"column:real_name"`                     // 真实姓名
-	Role          string    `gorm:"column:role"`                          // 角色 1,超级管理员; 2,管理员;3,企业用户
+	Role          string    `gorm:"column:role"`                          // 角色 1,超级管理员; 2,管理员;3,企业用户; 4. 企业子账号;5. 管理后台子账号;6.服务商账号;7.服务商子账号
 	Phone         string    `gorm:"column:phone"`                         // 绑定手机
 	Email         string    `gorm:"column:email"`                         // 电子邮件
 	LastLoginTime time.Time `gorm:"column:last_login_time"`               // 最后一次登录时间

+ 21 - 0
model/http_model/get_user_info.go

@@ -0,0 +1,21 @@
+package http_model
+
+type GetUserInfoRequest struct {
+	Token string `json:"token"` // Token
+}
+
+type GetUserInfoData struct {
+	Role         string `json:"role"`           // 角色类型 1,超级管理员; 2,管理员;3,企业用户; 4. 企业子账号;5. 管理后台子账号
+	UserId       int64  `json:"user_id"`        // YG用户ID
+	EnterpriseId string `json:"enterprise_id"`  // 商家ID
+	SubAccountId int    `json:"sub_account_id"` // 子账号ID
+}
+
+func NewGetUserInfoRequest() *GetUserInfoRequest {
+	return new(GetUserInfoRequest)
+}
+func NewGetUserInfoResponse() *CommonResponse {
+	resp := new(CommonResponse)
+	resp.Data = new(GetUserInfoData)
+	return resp
+}

+ 1 - 0
route/init.go

@@ -22,6 +22,7 @@ func InitRoute(r *gin.Engine) {
 		business.POST("/deleteJob", handler.WrapdeleteJobHandler)               // 商家删除岗位
 		business.POST("/sendCode", handler.WrapSendCodeHandler)                 // 发送登录验证码
 		business.POST("/login", handler.WrapCodeLoginHandler)                   // 商家登录
+		business.POST("/getUserInfo", handler.WrapGetUserInfoHandler)           // 商家新增岗位
 		business.GET("/test/ping", func(c *gin.Context) {
 			resp := http_model.CommonResponse{
 				Status:  20000,

+ 42 - 0
service/b_user_info.go

@@ -0,0 +1,42 @@
+package service
+
+import (
+	"context"
+	"fmt"
+	log "github.com/sirupsen/logrus"
+	"youngee_b_api/db"
+	"youngee_b_api/model/http_model"
+)
+
+var BUserInfo *bUserInfo
+
+type bUserInfo struct {
+}
+
+// FindBUserInfoByToken 根据Token查询商家端用户信息
+func (*bUserInfo) FindBUserInfoByToken(ctx context.Context, token string) (*http_model.GetUserInfoData, error) {
+	if token != "" {
+		if auth, err := LoginAuth.AuthToken(ctx, token); err == nil {
+			var userInfo *http_model.GetUserInfoData
+			userInfo = &http_model.GetUserInfoData{
+				EnterpriseId: auth.EnterpriseID,
+				UserId:       auth.ID,
+				Role:         auth.Role,
+			}
+			if auth.Role == "3" {
+				fmt.Println("EnterpriseUser")
+			} else if auth.Role == "4" {
+				subaccountInfo, subaccountErr := db.FindSubAccountByPhone(ctx, auth.Phone)
+				if subaccountErr != nil {
+					return nil, subaccountErr
+				}
+				userInfo.SubAccountId = subaccountInfo.SubAccountId
+			}
+			return userInfo, nil
+		} else {
+			log.Infof("[LoginAuthMiddleware] auth fail,err:%+v", err)
+			return nil, err
+		}
+	}
+	return nil, nil
+}