rdluck 4 anos atrás
pai
commit
dfd5edf5e9
4 arquivos alterados com 101 adições e 0 exclusões
  1. 52 0
      controllers/user.go
  2. 18 0
      models/company.go
  3. 26 0
      models/user.go
  4. 5 0
      routers/router.go

+ 52 - 0
controllers/user.go

@@ -0,0 +1,52 @@
+package controllers
+
+import (
+	"hongze/hongze_cygx/models"
+)
+
+//用户
+type UserController struct {
+	BaseAuthController
+}
+
+// @Title 获取用户详情
+// @Description 获取用户详情接口
+// @Success 200 {object} models.UserDetail
+// @router /detail [get]
+func (this *UserController) Detail() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	user := this.User
+	if user == nil {
+		br.Msg = "请登录"
+		br.ErrMsg = "请登录,用户信息为空"
+		br.Ret = 408
+		return
+	}
+	item, err := models.GetUserDetailByUserId(user.UserId)
+	if err != nil {
+		br.Msg = "获取信息失败"
+		br.ErrMsg = "获取信息失败,Err:" + err.Error()
+		return
+	}
+	companyItem, err := models.GetCompanyDetailById(user.UserId)
+	if err != nil {
+		br.Msg = "获取信息失败"
+		br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
+		return
+	}
+	item.CompanyName = companyItem.CompanyName
+	var hasPermission bool
+	if companyItem.Status == "试用" || companyItem.Status == "永续" || companyItem.Status == "正式" {
+		hasPermission = true
+
+	}
+	item.HasPermission = hasPermission
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "获取成功"
+	br.Data = item
+}

+ 18 - 0
models/company.go

@@ -0,0 +1,18 @@
+package models
+
+import "rdluck_tools/orm"
+
+type CompanyDetail struct {
+	CompanyId   int    `orm:"column(company_id);pk"`
+	CompanyName string `description:"客户名称"`
+	Status      string `description:"客户状态"`
+}
+
+func GetCompanyDetailById(companyId int) (item *CompanyDetail, err error) {
+	sql := ` SELECT a.company_id,a.company_name,b.status FROM company AS a
+			INNER JOIN company_product AS b ON a.company_id=b.company_id
+			WHERE a.company_id=? AND  b.product_id=2 `
+	o := orm.NewOrm()
+	err = o.Raw(sql, companyId).QueryRow(&item)
+	return
+}

+ 26 - 0
models/user.go

@@ -0,0 +1,26 @@
+package models
+
+import "rdluck_tools/orm"
+
+type UserDetail struct {
+	Headimgurl     string `description:"用户头像,最后一个数值代表正方形头像大小(有0、46、64、96、132数值可选,0代表640*640正方形头像),用户没有头像时该项为空"`
+	Mobile         string `description:"手机号码"`
+	Email          string `description:"邮箱"`
+	NickName       string `description:"用户昵称"`
+	RealName       string `description:"用户实际名称"`
+	CompanyName    string `description:"公司名称"`
+	PermissionName string `description:"拥有权限分类"`
+	HasPermission bool `description:"true:有权限,false:无权限"`
+}
+
+func GetUserDetailByUserId(userId int) (item *UserDetail, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT * FROM wx_user WHERE user_id = ? `
+	err = o.Raw(sql, userId).QueryRow(&item)
+	return
+}
+
+type UserPermission struct {
+	CompanyName         string `description:"公司名称"`
+	ChartPermissionName string `description:"权限"`
+}

+ 5 - 0
routers/router.go

@@ -33,6 +33,11 @@ func init() {
 				&controllers.WechatCommonController{},
 			),
 		),
+		beego.NSNamespace("/user",
+			beego.NSInclude(
+				&controllers.UserController{},
+			),
+		),
 	)
 	beego.AddNamespace(ns)
 }