浏览代码

Merge branch 'index_tab' of hongze/hongze_yb into master

hsun 2 年之前
父节点
当前提交
501ef1c82e
共有 5 个文件被更改,包括 166 次插入15 次删除
  1. 25 0
      controller/user/user.go
  2. 74 15
      logic/user/user.go
  3. 45 0
      models/tables/yb_index_tab/entity.go
  4. 21 0
      models/tables/yb_index_tab/model.go
  5. 1 0
      routers/user.go

+ 25 - 0
controller/user/user.go

@@ -292,4 +292,29 @@ func SetUserInfo(c *gin.Context) {
 		return
 	}
 	response.Ok("更新成功", c)
+}
+
+// GetTopTab 获取首页顶部Tab
+// @Tags 用户模块
+// @Summary  获取首页顶部Tab
+// @Description 获取首页顶部Tab
+// @Security ApiKeyAuth
+// @securityDefinitions.basic BasicAuth
+// @Param Authorization	header string true "微信登录后获取到的token"
+// @Accept  json
+// @Product json
+// @Success 200 {object} []string "获取成功"
+// @failure 400 {string} string "获取失败"
+// @Router /user/get_top_tab [get]
+func GetTopTab(c *gin.Context) {
+	userInfo := userService.GetInfoByClaims(c)
+	version := c.Request.Header.Get("version")
+	tabBarList, err := userLogic.GetTopTab(userInfo, version)
+
+	if err != nil {
+		response.Fail("获取失败", c)
+		return
+	}
+
+	response.OkData("获取成功", tabBarList, c)
 }

+ 74 - 15
logic/user/user.go

@@ -11,6 +11,7 @@ import (
 	"hongze/hongze_yb/models/tables/research_group_relation"
 	"hongze/hongze_yb/models/tables/wx_user"
 	"hongze/hongze_yb/models/tables/yb_apply_record"
+	"hongze/hongze_yb/models/tables/yb_index_tab"
 	"hongze/hongze_yb/models/tables/yb_message"
 	"hongze/hongze_yb/services"
 	companyService "hongze/hongze_yb/services/company"
@@ -399,24 +400,34 @@ func Apply(userId int, companyId int64, mobile, email string, applyInfo userReq.
 
 // GetUserTabBar 获取用户小程序TabBar
 func GetUserTabBar(userInfo user.UserInfo, version string) (list []string, err error) {
-	// user-我的; activity-活动; chart-图表; report-研报; buy-已购; question-问答;
-	list = []string{"activity", "user", "chart"}
-	if version == "yb3.0" {
-		list = []string{"activity", "user", "chart", "report"}
+	where := make(map[string]interface{})
+	where["version"] = version
+	where["position"] = 2
+	where["is_show"] = 1
+	tabs, e := yb_index_tab.GetListByCondition(where)
+	if e != nil {
+		err = errors.New("获取TabBar失败, Err: " + e.Error())
+		return
 	}
-	if version == "yb5.0" {
-		list = []string{"activity", "question", "chart", "report"}
+	if len(tabs) == 0 {
+		return
 	}
-	companyProduct, tmpErr := company_product.GetByCompany2ProductId(userInfo.CompanyID, 1)
-	if tmpErr != nil {
-		if tmpErr == utils.ErrNoRow {
-			err = nil
-		}
+	authOk := false
+	companyProduct, e := company_product.GetByCompany2ProductId(userInfo.CompanyID, 1)
+	if e != nil && e != utils.ErrNoRow {
+		err = errors.New("获取客户信息失败, Err: " + e.Error())
 		return
 	}
-	// 已购仅付费用户可见
-	if strings.Contains("永续,正式", companyProduct.Status) {
-		list = append(list, "buy")
+	if companyProduct != nil {
+		if strings.Contains("永续,正式", companyProduct.Status) {
+			authOk = true
+		}
+	}
+	for _, v := range tabs {
+		if v.AuthCheck == 1 && !authOk {
+			continue
+		}
+		list = append(list, v.Mark)
 	}
 	return
 }
@@ -480,8 +491,56 @@ func PcSendEmailCode(email string) (err error, errMsg string) {
 		}
 		err = item.Create()
 	} else {
-		err = errors.New("发送失败,Err:" + err.Error())
+		err = errors.New("发送失败")
 	}
 
 	return
 }
+
+// TopTab
+type TopTab struct {
+	Tab  string `json:"tab" description:"选项卡名称"`
+	Mark string `json:"mark" description:"选项卡标识"`
+	Icon string `json:"icon" description:"icon图标"`
+	Sort int    `json:"sort" description:"排序"`
+}
+
+// GetTopTab 获取小程序首页顶部选项卡
+func GetTopTab(userInfo user.UserInfo, version string) (list []*TopTab, err error) {
+	where := make(map[string]interface{})
+	where["version"] = version
+	where["position"] = 1
+	where["is_show"] = 1
+	tabs, e := yb_index_tab.GetListByCondition(where)
+	if e != nil {
+		err = errors.New("获取TabBar失败, Err: " + e.Error())
+		return
+	}
+	if len(tabs) == 0 {
+		return
+	}
+	authOk := false
+	companyProduct, e := company_product.GetByCompany2ProductId(userInfo.CompanyID, 1)
+	if e != nil && e != utils.ErrNoRow {
+		err = errors.New("获取客户信息失败, Err: " + e.Error())
+		return
+	}
+	if companyProduct != nil {
+		if strings.Contains("永续,正式", companyProduct.Status) {
+			authOk = true
+		}
+	}
+	list = make([]*TopTab, 0)
+	for _, v := range tabs {
+		if v.AuthCheck == 1 && !authOk {
+			continue
+		}
+		list = append(list, &TopTab{
+			Tab: v.Tab,
+			Mark: v.Mark,
+			Icon: v.DefaultIcon,
+			Sort: v.Sort,
+		})
+	}
+	return
+}

+ 45 - 0
models/tables/yb_index_tab/entity.go

@@ -0,0 +1,45 @@
+package yb_index_tab
+
+// YbIndexTab 研报-首页选项卡
+type YbIndexTab struct {
+	ID           int    `gorm:"primaryKey;column:id;type:int(10) unsigned;not null" json:"-"`
+	Tab          string `gorm:"column:tab;type:varchar(30);not null;default:''" json:"tab"`                     // 选项卡名
+	Mark         string `gorm:"column:mark;type:varchar(30);not null;default:''" json:"mark"`                   // 枚举值
+	DefaultIcon  string `gorm:"column:default_icon;type:varchar(255);not null;default:''" json:"defaultIcon"`   // 默认icon
+	SelectedIcon string `gorm:"column:selected_icon;type:varchar(255);not null;default:''" json:"selectedIcon"` // 选中icon
+	Sort         int    `gorm:"column:sort;type:int(10) unsigned;not null;default:0" json:"sort"`               // 排序
+	IsShow       int    `gorm:"column:is_show;type:tinyint(4) unsigned;not null;default:0" json:"isShow"`       // 是否显示:0-隐藏 1-显示
+	AuthCheck    int    `gorm:"column:auth_check;type:tinyint(4) unsigned;not null;default:0" json:"authCheck"` // 是否需要检验权限:0-否 1-是
+	Position     int    `gorm:"column:position;type:tinyint(4) unsigned;not null;default:0" json:"position"`    // 位置:1-顶部 2-底部
+	Version      string `gorm:"column:version;type:varchar(30);not null;default:''" json:"version"`             // 版本号
+}
+
+// TableName get sql table name.获取数据库表名
+func (m *YbIndexTab) TableName() string {
+	return "yb_index_tab"
+}
+
+// YbIndexTabColumns get sql column name.获取数据库列名
+var YbIndexTabColumns = struct {
+	ID           string
+	Tab          string
+	Mark         string
+	DefaultIcon  string
+	SelectedIcon string
+	Sort         string
+	IsShow       string
+	AuthCheck    string
+	Position     string
+	Version      string
+}{
+	ID:           "id",
+	Tab:          "tab",
+	Mark:         "mark",
+	DefaultIcon:  "default_icon",
+	SelectedIcon: "selected_icon",
+	Sort:         "sort",
+	IsShow:       "is_show",
+	AuthCheck:    "auth_check",
+	Position:     "position",
+	Version:      "version",
+}

+ 21 - 0
models/tables/yb_index_tab/model.go

@@ -0,0 +1,21 @@
+package yb_index_tab
+
+import (
+	"errors"
+	"hongze/hongze_yb/global"
+	"hongze/hongze_yb/utils"
+)
+
+// GetListByCondition 条件获取列表
+func GetListByCondition(where map[string]interface{}) (list []*YbIndexTab, err error) {
+	cond, vals, e := utils.WhereBuild(where)
+	if e != nil {
+		err = errors.New("系统异常,生成查询语句失败")
+		return
+	}
+	err = global.DEFAULT_MYSQL.Model(YbIndexTab{}).
+		Where(cond, vals...).
+		Order("sort ASC").
+		Scan(&list).Error
+	return
+}

+ 1 - 0
routers/user.go

@@ -41,6 +41,7 @@ func initUser(r *gin.Engine) {
 		rGroup2.GET("/get_last_apply_record", user.GetLastApplyRecord)
 		rGroup2.POST("/apply", user.Apply)
 		rGroup2.GET("/get_tab_bar", user.GetTabBar)
+		rGroup2.GET("/get_top_tab", user.GetTopTab)
 		rGroup2.POST("/set", user.SetUserInfo)
 	}