Browse Source

no message

xingzai 9 months ago
parent
commit
e9a10d2e0f

+ 20 - 0
controllers/yanxuan_special.go

@@ -264,6 +264,26 @@ func (this *YanxuanSpecialController) Detail() {
 		}
 	}
 
+	//校验研选专栏权限,以及无权限的时候的对应状态码
+	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
+
 	br.Data = resp
 	br.Ret = 200
 	br.Success = true

+ 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

@@ -5,6 +5,7 @@ import (
 	"errors"
 	"fmt"
 	"hongze/hongze_cygx/models"
+	"hongze/hongze_cygx/models/company"
 	"hongze/hongze_cygx/utils"
 	"strconv"
 	"strings"
@@ -506,3 +507,57 @@ func UpdateYanxuanSpecialAuthoMomentsImg(cont context.Context) (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_cygx/models"
+	"hongze/hongze_cygx/models/company"
 	"hongze/hongze_cygx/utils"
 	"strings"
 )
@@ -115,3 +116,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 = 4
+		}
+	} 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 = 5
+			} else {
+				permission = 3
+			}
+		} else {
+			if applyCount > 0 {
+				permission = 5
+			} else {
+				permission = 2
+			}
+		}
+	}
+	return
+}