浏览代码

晨报章节详情底部添加菜单

xiexiaoyuan 3 年之前
父节点
当前提交
8526c69f49

+ 1 - 1
models/response/report.go

@@ -67,7 +67,7 @@ type ReportChapterItem struct {
 }
 
 type ReportChapterDetail struct {
-	ReportChapterItem  * ReportChapterItem
+	ReportChapterItem  * ReportChapterItem  `json:"report_chapter_item"`
 	PermissionCheck     *company.PermissionCheckInfo    `json:"permission_check"`
 	ReportChapterMenuList        []*ReportChapterMenu `json:"report_chapter_menu_list""`
 	AuthOk              bool `json:"auth_ok"`

+ 20 - 6
models/tables/rddp/report_chapter/query.go

@@ -28,20 +28,34 @@ ORDER BY
 }
 
 // GetListByReportId 根据报告ID获取章节列表
-func GetListByReportId(reportId int) (list []*ReportChapter, err error)  {
+func GetListByReportId(reportId int, classifyNameFirst string) (list []*ReportChapter, err error)  {
+	var where string
+	if  classifyNameFirst == "周报"{
+		where = "report_id = ? AND is_edit = 1 AND publish_state = 2"
+	}else{
+		where = "report_id = ? AND publish_state = 2"
+	}
+
 	err = global.MYSQL["rddp"].Model(ReportChapter{}).
 		Select("report_chapter_id, report_id, type_id, type_name, abstract, title, author, publish_time").
-		Where("report_id = ? AND is_edit = 1 AND publish_state = 2 ", reportId).
+		Where(where, reportId).
 		Order("sort asc, report_chapter_id asc").
 		Scan(&list).Error
 	return
 }
 
 // GetListByReportIdTypeIds 根据报告ID、章节类型ID获取章节列表
-func GetListByReportIdTypeIds(reportId int, typeIds []int) (list []*ReportChapter, err error)  {
+func GetListByReportIdTypeIds(reportId int, typeIds []int, classifyNameFirst string) (list []*ReportChapter, err error)  {
+	var where string
+	if  classifyNameFirst == "周报"{
+		where = "report_id = ? AND type_id in (?) AND is_edit = 1 AND publish_state = 2 "
+	}else{
+		where = "report_id = ? AND type_id in (?) AND publish_state = 2 "
+	}
+
 	err = global.MYSQL["rddp"].Model(ReportChapter{}).
 		Select("report_chapter_id, report_id, type_id, type_name, abstract, title, author, publish_time").
-		Where("report_id = ? AND type_id in (?) AND is_edit = 1 AND publish_state = 2 ", reportId, typeIds).
+		Where(where, reportId, typeIds).
 		Order("sort asc, report_chapter_id asc").
 		Scan(&list).Error
 	return
@@ -49,8 +63,8 @@ func GetListByReportIdTypeIds(reportId int, typeIds []int) (list []*ReportChapte
 
 // GetContentById 根据ID获取章节详情
 func GetContentById(id int, typeIds []int) (info *ReportChapter, err error)  {
-	err = global.MYSQL["rddp"].Select("report_chapter_id, report_id,  content, trend, type_id, type_name, abstract, title, author, publish_time, content, content_sub, video_url, video_name, video_play_seconds, video_size").
-		Where("report_chapter_id = ? and type_id in (?) and is_edit = 1 AND publish_state = 2 ", id, typeIds).
+	err = global.MYSQL["rddp"].Select("report_chapter_id, report_id,  is_edit, content, trend, type_id, type_name, abstract, title, author, publish_time, content, content_sub, video_url, video_name, video_play_seconds, video_size").
+		Where("report_chapter_id = ? and type_id in (?) AND publish_state = 2 ", id, typeIds).
 		First(&info).Error
 	if err == utils.ErrNoRow {
 		err = nil

+ 122 - 0
services/company/permission.go

@@ -258,6 +258,128 @@ func CheckPermissionByPermissionIdList2Ficc(companyId int64, userId int, permiss
 	return
 }
 
+func GetCheckPermission(companyId int64, userId int, permissionIdList []int) (ok bool, permissionCheckInfo PermissionCheckInfo, err error) {
+	defer func() {
+		// 如果无权限,那么就去查询是否申请过
+		if ok == false {
+			ok, _ = checkPermissionByPermissionIdList2Rai(companyId, permissionIdList)
+		}
+		if ok == false && permissionCheckInfo.Type == "apply" {
+			_, err = yb_apply_record.GetLastNotOpRecordByUserId(userId)	// 从来源我的/活动申请的记录
+			if err != nil {
+				if err == utils.ErrNoRow {
+					err = nil
+				}
+				return
+			}
+			//查询是否有申请过,如果有申请过的话,那么err是nil
+			if err == nil {
+				permissionCheckInfo.CustomerInfo.HasApply = true
+			}
+		}
+	}()
+	//非潜在客户
+	permissionMap := make(map[int]bool)
+	if len(permissionIdList) > 0 {
+		for _, permissionId := range permissionIdList {
+			permissionMap[permissionId] = true
+		}
+	}
+
+	var productId int64
+	productId = 1
+	if companyId > 1 {
+		//查询是否 开通ficc的客户
+		companyProductInfo, tmpErr := company_product.GetByCompany2ProductId(companyId, productId)
+		if tmpErr != nil {
+			// 没有开通ficc的客户
+			if tmpErr == utils.ErrNoRow {
+				permissionCheckInfo.Type = "apply"
+				return
+			}
+			err = tmpErr
+			return
+		}
+
+		wxUser, tmpErr := wx_user.GetByUserId(userId)
+		if tmpErr != nil {
+			permissionCheckInfo.Type = "apply"
+			err = tmpErr
+			return
+		}
+
+		//客户信息
+		companyInfo, tmpErr := company.GetByCompanyId(companyId)
+		if tmpErr != nil {
+			// 没有开通ficc的客户
+			if tmpErr == utils.ErrNoRow {
+				permissionCheckInfo.Type = "apply"
+				return
+			}
+			err = tmpErr
+			return
+		}
+		customerInfo := CustomerInfo{
+			CompanyName: companyInfo.CompanyName,
+			Status:      companyProductInfo.Status,
+			Name:        wxUser.RealName,
+			IsSuspend:   companyProductInfo.IsSuspend,
+			Mobile:      wxUser.Mobile,
+		}
+		permissionCheckInfo.CustomerInfo = customerInfo
+
+		// 如果客户ficc产品的状态是流失,那么也是让去申请
+		if companyProductInfo.Status == "流失" {
+			permissionCheckInfo.Type = "apply"
+			return
+		}
+
+		//查找对应客户的销售信息
+		adminInfo, tmpErr := admin.GetByAdminId(companyProductInfo.SellerID)
+		if tmpErr != nil {
+			//if tmpErr ==
+			err = tmpErr
+			return
+		}
+
+		permissionCheckInfo.Name = adminInfo.RealName
+		permissionCheckInfo.Mobile = adminInfo.Mobile
+		if companyProductInfo.Status == "冻结" {
+			permissionCheckInfo.Type = "contact"
+			return
+		}
+
+		//客户状态是:试用暂停状态(联系销售)
+		if companyProductInfo.Status == "试用" && companyProductInfo.IsSuspend == 1 {
+			permissionCheckInfo.Type = "contact"
+			return
+		}
+
+		// 获取有效的权限id列表
+		validPermissionIdList, tmpErr := GetValidPermissionIdListByCompany2ProductId(companyId, productId)
+		if tmpErr != nil {
+			err = tmpErr
+			return
+		}
+		// 校验在有效的权限id列表中是否存在该权限
+		if len(permissionIdList) > 0 {
+			for _, validPermissionId := range validPermissionIdList {
+				//如果有该权限id,那么直接返回校验通过
+				if _, validOk := permissionMap[validPermissionId]; validOk {
+					ok = true
+					return
+				}
+			}
+		}
+
+		permissionCheckInfo.Type = "contact"
+	} else {
+		permissionCheckInfo.Type = "apply"
+	}
+
+	return
+}
+
 // checkPermissionByPermissionIdList2Rai 根据权限id集合权限校验(权益)
 func checkPermissionByPermissionIdList2Rai(companyId int64, permissionIdList []int) (ok bool, err error) {
 	//非潜在客户

+ 10 - 9
services/report/report.go

@@ -199,14 +199,15 @@ func GetReportDetail(userinfo user.UserInfo, reportId int) (reportDetail respons
 	//判断权限
 	var authOk bool
 	var permissionCheckInfo company.PermissionCheckInfo
-	if reportInfo.ClassifyNameFirst == "晨报" || reportInfo.ClassifyNameFirst == "周报" {
-		authOk = true
-		permissionCheckInfo = company.PermissionCheckInfo{}
+	if reportInfo.ClassifyNameFirst == "晨报"{
+		authOk, permissionCheckInfo, err = CheckDayReportPermission(userinfo)
+	}else if reportInfo.ClassifyNameFirst == "周报"{
+		authOk, permissionCheckInfo, err = CheckWeekReportPermission(userinfo, reportId)
 	}else{
 		authOk, permissionCheckInfo, err = CheckReportPermission(userinfo, reportId)
-		if err != nil {
-			return
-		}
+	}
+	if err != nil {
+		return
 	}
 
 	reportItem := new(response.ReportItem)
@@ -224,7 +225,7 @@ func GetReportDetail(userinfo user.UserInfo, reportId int) (reportDetail respons
 	reportItem.Author = reportInfo.Author
 
 	var reportTypeList []*response.ReportChapterListItem
-	if reportInfo.ClassifyNameFirst == "晨报" || reportInfo.ClassifyNameFirst == "周报" {
+	if (reportInfo.ClassifyNameFirst == "晨报" || reportInfo.ClassifyNameFirst == "周报") && authOk {
 		reportTypeList, err = GetChapterListByReport(reportInfo.ClassifyNameFirst, reportInfo.Id, userinfo.CompanyID)
 		if err != nil {
 			return
@@ -246,9 +247,9 @@ func GetReportDetail(userinfo user.UserInfo, reportId int) (reportDetail respons
 // CheckReportPermission 验证用户查看报告的权限
 func CheckReportPermission(userInfo user.UserInfo, reportId int) (authOk bool, permissionCheckInfo company.PermissionCheckInfo, err error) {
 	permissionIds, err := chart_permission_chapter_mapping.GetPermissionIdsByReportId(reportId, "rddp")
-	if err != nil {
+	if err != nil && err != utils.ErrNoRow {
 		return
 	}
-	authOk, permissionCheckInfo, err = company.CheckPermissionByPermissionIdList2Ficc(userInfo.CompanyID, int(userInfo.UserID), permissionIds)
+	authOk, permissionCheckInfo, err = company.GetCheckPermission(userInfo.CompanyID, int(userInfo.UserID), permissionIds)
 	return
 }

+ 34 - 6
services/report/report_chapter.go

@@ -99,7 +99,7 @@ func GetChapterListByReport(classifyNameFirst string, reportId int, companyId in
 		}
 	}
 	//获取所有当前研报的章节
-	chapterList, tErr := report_chapter.GetListByReportId(reportId)
+	chapterList, tErr := report_chapter.GetListByReportId(reportId, classifyNameFirst)
 	if tErr != nil && tErr != utils.ErrNoRow{
 		errMsg = err.Error()
 		err = errors.New("章节查询出错")
@@ -183,6 +183,10 @@ func GetChapterDetail(user user.UserInfo, reportChapterId int) (reportChapterDet
 		err = errors.New("报告不存在")
 		return
 	}
+	if reportInfo.ClassifyNameFirst == "周报" && reportChapter.IsEdit != 1 {
+		err = errors.New("章节未编辑")
+		return
+	}
 	//判断权限
 	permissionIds, tErr := company.GetValidPermissionIdListByCompany2ProductId(user.CompanyID, 1)
 	if tErr != nil && tErr != utils.ErrNoRow {
@@ -192,7 +196,7 @@ func GetChapterDetail(user user.UserInfo, reportChapterId int) (reportChapterDet
 	}
 
 	//TODO 修改权限校验接口,如果用户没有权限也要允许用户查看部分内容
-	authOk, permissionCheckInfo, tErr = company.CheckPermissionByPermissionIdList2Ficc(user.CompanyID, int(user.UserID), permissionIds)
+	authOk, permissionCheckInfo, tErr = company.GetCheckPermission(user.CompanyID, int(user.UserID), permissionIds)
 	if tErr != nil && tErr != utils.ErrNoRow{
 		errMsg = tErr.Error()
 		err = errors.New("权限查询出错")
@@ -230,9 +234,9 @@ func GetChapterDetail(user user.UserInfo, reportChapterId int) (reportChapterDet
 		reportChapterItem.VideoUrl = reportChapter.VideoUrl
 		//底部菜单切换
 		if reportInfo.ClassifyNameFirst == "周报" {
-			chapterMenu, err = GetMenuChapter(reportInfo.Id, newTypeIds)
+			chapterMenu, err = GetMenuChapter(reportInfo.Id, newTypeIds, reportInfo.ClassifyNameFirst)
 		}else{
-			chapterMenu, err = GetMenuChapter(reportInfo.Id, typeIds)
+			chapterMenu, err = GetMenuChapter(reportInfo.Id, typeIds, reportInfo.ClassifyNameFirst)
 		}
 	}else{
 		reportChapterItem.ContentSub = reportChapter.ContentSub
@@ -245,7 +249,7 @@ func GetChapterDetail(user user.UserInfo, reportChapterId int) (reportChapterDet
 	return
 }
 
-func GetMenuChapter(reportId int, typeIds []int) (reportTypeList []*response.ReportChapterMenu, err error)  {
+func GetMenuChapter(reportId int, typeIds []int, classifyNameFirst string) (reportTypeList []*response.ReportChapterMenu, err error)  {
 	//查询有效的章节
 	typeList, tErr := report_chapter_type.GetEffectTypes()
 	if tErr != nil {
@@ -262,7 +266,7 @@ func GetMenuChapter(reportId int, typeIds []int) (reportTypeList []*response.Rep
 	}
 
 	//获取所有当前研报的章节
-	chapterList, tErr := report_chapter.GetListByReportIdTypeIds(reportId, typeIds)
+	chapterList, tErr := report_chapter.GetListByReportIdTypeIds(reportId, typeIds, classifyNameFirst)
 	if tErr != nil && tErr != utils.ErrNoRow{
 		return
 	}
@@ -279,4 +283,28 @@ func GetMenuChapter(reportId int, typeIds []int) (reportTypeList []*response.Rep
 		}
 	}
 	return
+}
+
+// CheckWeekReportPermission 验证周报的权限
+func CheckWeekReportPermission(userInfo user.UserInfo, reportId int) (authOk bool, permissionCheckInfo company.PermissionCheckInfo, err error) {
+	permissionIds, err := chart_permission_chapter_mapping.GetPermissionIdsByReportId(reportId, "week")
+	if err != nil && err != utils.ErrNoRow {
+		return
+	}
+	authOk, permissionCheckInfo, err = company.GetCheckPermission(userInfo.CompanyID, int(userInfo.UserID), permissionIds)
+	return
+}
+
+// CheckDayReportPermission 验证晨报的权限
+func CheckDayReportPermission(userInfo user.UserInfo) (authOk bool, permissionCheckInfo company.PermissionCheckInfo, err error) {
+	permissions, err := company.GetValidPermissionByCompany2ProductId(userInfo.CompanyID, 1)
+	if err != nil && err != utils.ErrNoRow {
+		return
+	}
+	var permissionIds []int
+	for _, item := range permissions {
+		permissionIds = append(permissionIds, item.ChartPermissionID)
+	}
+	authOk, permissionCheckInfo, err = company.GetCheckPermission(userInfo.CompanyID, int(userInfo.UserID), permissionIds)
+	return
 }