|
@@ -6,6 +6,7 @@ import (
|
|
|
"hongze/hongze_api/models"
|
|
|
"hongze/hongze_api/utils"
|
|
|
"strconv"
|
|
|
+ "strings"
|
|
|
)
|
|
|
|
|
|
func CheckUserPermission(userId int) (status int, err error) {
|
|
@@ -62,3 +63,150 @@ func CheckUserPermission(userId int) (status int, err error) {
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
+
|
|
|
+// CheckUserReportPermission 判断用户查看当前报告时是需要发起申请还是联系销售
|
|
|
+func CheckUserReportPermission(user *models.WxUserItem, productId int, report *models.ReportDetail, maxPermissionCount int) (status int, checkInfo models.PermissionCheckInfoResp, company *models.CompanyProduct, msg, brMsg, brErrMsg string) {
|
|
|
+ reportId := report.Id
|
|
|
+ company, err := models.GetCompanyProductById(user.CompanyId, productId)
|
|
|
+ if err != nil {
|
|
|
+ if err.Error() != utils.ErrNoRow() {
|
|
|
+ brMsg = "获取报告详情失败"
|
|
|
+ brErrMsg = "获取用户管理企业信息失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+ sellerName := ""
|
|
|
+ if company == nil {
|
|
|
+ status = 2
|
|
|
+ msg = "您还未开通权限,立即申请免费试用"
|
|
|
+ checkInfo.Type = "apply"
|
|
|
+ }else if company.CompanyId == 1 {
|
|
|
+ status = 2
|
|
|
+ msg = "您还未开通权限,立即申请免费试用"
|
|
|
+ checkInfo.Type = "apply"
|
|
|
+ }else {
|
|
|
+ checkInfo.Type = "contact"
|
|
|
+ customerInfo := models.CustomerInfoResp{
|
|
|
+ CompanyName: company.CompanyName,
|
|
|
+ Status: company.Status,
|
|
|
+ Name: user.RealName,
|
|
|
+ IsSuspend: int8(company.IsSuspend),
|
|
|
+ Mobile: user.Mobile,
|
|
|
+ }
|
|
|
+ checkInfo.CustomerInfo = customerInfo
|
|
|
+ // 判断用户状态
|
|
|
+ if company.Status == utils.COMPANY_STATUS_LOSE {
|
|
|
+ status = 2
|
|
|
+ msg = "您还未开通权限,立即申请免费试用"
|
|
|
+ checkInfo.Type = "apply"
|
|
|
+ }else if company.Status == utils.COMPANY_STATUS_FREEZE {
|
|
|
+ status = 2
|
|
|
+ msg = "您还未开通权限,如有需要请联系对口销售"
|
|
|
+ }else if company.IsSuspend > 0 && company.Status == "试用" { //如果客户产品被禁用了,只有在试用状态下,才不允许查看报告,那么没有权限
|
|
|
+ status = 2
|
|
|
+ msg = "您还未开通权限,如有需要请联系对口销售"
|
|
|
+ }
|
|
|
+ //查找对应客户的销售信息
|
|
|
+ if company.SellerId > 0 {
|
|
|
+ adminInfo, tmpErr := models.GetAdminByAdminId(company.SellerId)
|
|
|
+ if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
|
|
|
+ brMsg = "获取销售信息失败"
|
|
|
+ brErrMsg = "获取销售信息失败,Err:" + tmpErr.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if adminInfo != nil {
|
|
|
+ sellerName = adminInfo.RealName
|
|
|
+ checkInfo.Name = adminInfo.RealName
|
|
|
+ checkInfo.Mobile = adminInfo.Mobile
|
|
|
+ if status == 2 && checkInfo.Type == "contact" {
|
|
|
+ msg = "您还未开通权限,如有需要请联系对口销售"+sellerName
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if productId == 1 {
|
|
|
+ reportType := "rddp"
|
|
|
+ reportPermissionList, err := models.GetReportVarietyListByUserIdExt(user.UserId, reportType) //获取客户拥有权限的报告id
|
|
|
+ if err != nil {
|
|
|
+ if err.Error() != utils.ErrNoRow() {
|
|
|
+ brMsg = "获取报告详情失败"
|
|
|
+ brErrMsg = "获取客户信息失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if len(reportPermissionList) >= 0 {
|
|
|
+ permissionMap := make(map[int]int)
|
|
|
+ for _, v := range reportPermissionList {
|
|
|
+ if _, ok := permissionMap[v.ReportChapterTypeId]; !ok {
|
|
|
+ permissionMap[v.ReportChapterTypeId] = v.ReportChapterTypeId
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if _, ok := permissionMap[reportId]; !ok {
|
|
|
+ tips := ""
|
|
|
+ status = 2
|
|
|
+ classifyNameSecond := report.ClassifyNameSecond
|
|
|
+ if strings.Contains(classifyNameSecond, "宏观商品复盘") ||
|
|
|
+ strings.Contains(classifyNameSecond, "股债日评") ||
|
|
|
+ strings.Contains(classifyNameSecond, "每日经济数据备忘录") {
|
|
|
+ tips = "宏观"
|
|
|
+ } else if strings.Contains(classifyNameSecond, "知白守黑日评") ||
|
|
|
+ strings.Contains(classifyNameSecond, "动力煤数据点评") {
|
|
|
+ tips = "黑色"
|
|
|
+ } else if strings.Contains(classifyNameSecond, "化里化外日评") ||
|
|
|
+ strings.Contains(classifyNameSecond, "EIA原油库存点评") ||
|
|
|
+ strings.Contains(classifyNameSecond, "苯乙烯数据点评") ||
|
|
|
+ strings.Contains(classifyNameSecond, "聚酯数据点评") {
|
|
|
+ tips = "化工"
|
|
|
+ } else if strings.Contains(classifyNameSecond, "有声有色日度闲篇") {
|
|
|
+ tips = "有色"
|
|
|
+ }
|
|
|
+ if checkInfo.Type == "contact" {
|
|
|
+ msg = "您还未开通" + tips + "权限,如有需要请联系对口销售 "+sellerName
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ status = 2
|
|
|
+ if checkInfo.Type == "contact" {
|
|
|
+ msg = "您还未开通权限,如有需要请联系对口销售 " + sellerName
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ //判断大小权限
|
|
|
+ {
|
|
|
+ if status == 2 {
|
|
|
+ if company != nil {
|
|
|
+ permissionCount, err := models.GetCompanyProductPermissionCount(company.CompanyId, productId)
|
|
|
+ if err != nil {
|
|
|
+ brMsg = "获取信息失败"
|
|
|
+ brErrMsg = "获取权限信息失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if permissionCount >= maxPermissionCount {
|
|
|
+ status = 0
|
|
|
+ msg = ""
|
|
|
+ checkInfo.Type = ""
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if status == 2 {
|
|
|
+ //查询是否有过申请记录
|
|
|
+ record, err := models.GetLastApplyRecordNotOpRecordByUserId(user.UserId) // 从来源我的/活动申请的记录
|
|
|
+ if err != nil && err.Error() != utils.ErrNoRow() {
|
|
|
+ brMsg = "获取申请记录失败"
|
|
|
+ brErrMsg = "获取申请记录失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ //查询是否有申请过,如果有申请过的话,那么err是nil
|
|
|
+ if record != nil {
|
|
|
+ checkInfo.CustomerInfo.HasApply = true
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return
|
|
|
+}
|