瀏覽代碼

no message

xingzai 10 月之前
父節點
當前提交
4261035f06
共有 4 個文件被更改,包括 130 次插入1 次删除
  1. 21 1
      controllers/yanxuan_special.go
  2. 14 0
      models/company/company_product.go
  3. 55 0
      services/cygx_yanxuan_special.go
  4. 40 0
      services/user_permission.go

+ 21 - 1
controllers/yanxuan_special.go

@@ -274,7 +274,27 @@ func (this *YanxuanSpecialNoLoginController) Detail() {
 			resp.IsFollowAuthor = true
 		}
 	}
-	//
+
+	//校验研选专栏权限,以及无权限的时候的对应状态码
+	havePower, err := services.GetYanxuanSpecialDetailUserPower(sysUser)
+	if err != nil {
+		br.Msg = "获取信息失败"
+		br.ErrMsg = "校验用户权限失败,Err:" + err.Error()
+		return
+	}
+	var hasPermission int
+	if havePower {
+		hasPermission = 1
+	} else {
+		hasPermission, err = services.GetUserDetailPermissionCode(sysUser.UserId, sysUser.CompanyId)
+		if err != nil {
+			br.Msg = "获取信息失败"
+			br.ErrMsg = "获取用户权限状态失败,Err:" + err.Error()
+			return
+		}
+	}
+	resp.HasPermission = hasPermission
+
 	//if resp.HasPermission != 1 || sysUser.UserId == 0 {
 	//	resp.Content = utils.InterceptHtmlLength(resp.Content, 240)
 	//}

+ 14 - 0
models/company/company_product.go

@@ -65,3 +65,17 @@ func GetCompanyProductByCompanyIdAndProductId(companyId, productId int) (item *C
 	err = o.Raw(sql, companyId, productId).QueryRow(&item)
 	return
 }
+
+func GetCompanyProductCount(companyId, productId int) (count int, err error) {
+	sql := ` SELECT COUNT(1) AS count FROM  company_product WHERE company_id = ? AND product_id = ? `
+	o := orm.NewOrmUsingDB("weekly_report")
+	err = o.Raw(sql, companyId, productId).QueryRow(&count)
+	return
+}
+
+func GetCompanyProductDetailByCompanyId(companyId, productId int) (item *CompanyProduct, err error) {
+	sql := ` SELECT * FROM company_product WHERE company_id = ? AND product_id = ?; `
+	o := orm.NewOrmUsingDB("weekly_report")
+	err = o.Raw(sql, companyId, productId).QueryRow(&item)
+	return
+}

+ 55 - 0
services/cygx_yanxuan_special.go

@@ -4,6 +4,7 @@ import (
 	"errors"
 	"fmt"
 	"hongze/hongze_clpt/models"
+	"hongze/hongze_clpt/models/company"
 	"hongze/hongze_clpt/utils"
 	"strconv"
 	"strings"
@@ -536,3 +537,57 @@ func GetYanxuanSpecialCollectMap(userId int) (mapResp map[int]bool, err error) {
 	}
 	return
 }
+
+// GetYanxuanSpecialDetailUserPower 处理用户查看研选专栏详情的权限
+func GetYanxuanSpecialDetailUserPower(user *models.WxUserItem) (havePower bool, err error) {
+	//研选专栏是否需要校验权限
+	detailChart, e := models.GetConfigByCode("yanxuan_special_power_check")
+	if e != nil {
+		err = errors.New("GetConfigByCode, Err: " + e.Error())
+		return
+	}
+	//如果没有开启校验,直接返回true
+	if detailChart.ConfigValue == "0" {
+		havePower = true
+		return
+	}
+	userId := user.UserId
+	companyId := user.CompanyId
+	//判断用户是否开通了个人研选权限
+	mfyxUserPermissionTotal := GetMfyxUserPermissionTotal(userId)
+
+	if mfyxUserPermissionTotal == 1 {
+		havePower = true
+		return
+	}
+
+	//是否是权益客户
+	raiCount, e := company.GetCompanyProductCount(companyId, utils.COMPANY_PRODUCT_RAI_ID)
+	if e != nil {
+		err = errors.New("GetCompanyProductCount, Err: " + e.Error())
+		return
+	}
+	if raiCount == 0 {
+		return
+	}
+
+	productDetail, e := company.GetCompanyProductDetailByCompanyId(companyId, 2)
+	if e != nil {
+		err = errors.New("GetCompanyProductDetailByCompanyId, Err: " + e.Error())
+		return
+	}
+	// 永续客户无法查看研选权限
+	if productDetail.Status == utils.COMPANY_STATUS_FOREVER {
+		return
+	}
+	permissionStr, e := models.GetCompanyPermission(companyId)
+	if e != nil {
+		err = errors.New("GetCompanyPermission, Err: " + e.Error())
+		return
+	}
+	if strings.Contains(permissionStr, utils.CHART_PERMISSION_NAME_MF_YANXUAN) {
+		havePower = true
+		return
+	}
+	return
+}

+ 40 - 0
services/user_permission.go

@@ -3,6 +3,7 @@ package services
 import (
 	"errors"
 	"hongze/hongze_clpt/models"
+	"hongze/hongze_clpt/models/company"
 	"hongze/hongze_clpt/utils"
 	"strings"
 )
@@ -198,3 +199,42 @@ func GetUserRaiPermissionYanXuanInfo(user *models.WxUserItem) (hasPermission int
 	}
 	return
 }
+
+// 用户详情页获取用户权限状态  https://hzstatic.hzinsights.com/static/images/202402/20240205/LpE6dspJCLzfQoCoE8SFMDiLuxXk.png(状态码说明)这一期先不改2024-05-24。
+func GetUserDetailPermissionCode(userId, companyId int) (permission int, err error) {
+	// 用户申请记录
+	applyCount, e := models.GetApplyRecordCount(userId)
+	if e != nil && e.Error() != utils.ErrNoRow() {
+		err = errors.New("获取用户申请信息失败, Err: " + e.Error())
+		return
+	}
+	if companyId == 1 {
+		// 潜在用户
+		if applyCount > 0 {
+			permission = 5
+		} else {
+			permission = 6
+		}
+	} else {
+		//权益客户
+		raiCount, e := company.GetCompanyProductCount(companyId, utils.COMPANY_PRODUCT_RAI_ID)
+		if e != nil {
+			err = errors.New("获取用户申请信息失败, Err: " + e.Error())
+			return
+		}
+		if raiCount == 1 {
+			if applyCount > 0 {
+				permission = 3
+			} else {
+				permission = 4
+			}
+		} else {
+			if applyCount > 0 {
+				permission = 2
+			} else {
+				permission = 6
+			}
+		}
+	}
+	return
+}