Browse Source

产业更新时间排序

xingzai 3 years ago
parent
commit
392bf07d2c
5 changed files with 55 additions and 69 deletions
  1. 14 29
      controllers/article.go
  2. 2 2
      controllers/report.go
  3. 16 18
      controllers/tactics.go
  4. 19 19
      models/article.go
  5. 4 1
      models/industrial_management.go

+ 14 - 29
controllers/article.go

@@ -2,7 +2,6 @@ package controllers
 
 import (
 	"encoding/json"
-	"fmt"
 	"hongze/hongze_cygx/models"
 	"hongze/hongze_cygx/services"
 	"hongze/hongze_cygx/utils"
@@ -56,7 +55,6 @@ func (this *ArticleController) Detail() {
 		br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
 		return
 	}
-	fmt.Println(user.CompanyId)
 	//`description:"1:有该行业权限,正常展示,2:无该行业权限,不存在权益客户下,3:无该品类权限,4:潜在客户,未提交过申请,5:潜在客户,已提交过申请"`
 	if user.CompanyId > 1 {
 		companyPermission, err := models.GetCompanyPermission(user.CompanyId)
@@ -65,18 +63,14 @@ func (this *ArticleController) Detail() {
 			br.ErrMsg = "判断是否已申请访谈失败,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
 			return
 		}
-
 		detail, err = models.GetArticleDetailById(articleId)
 		if err != nil {
 			br.Msg = "获取信息失败"
 			br.ErrMsg = "获取信息失败,Err:" + err.Error()
 			return
 		}
-		fmt.Println(detail.Department)
-
 		detail.Body = html.UnescapeString(detail.Body)
 		detail.Abstract = html.UnescapeString(detail.Abstract)
-		fmt.Println(companyPermission)
 		if companyPermission == "" {
 			if applyCount > 0 {
 				hasPermission = 5
@@ -118,10 +112,7 @@ func (this *ArticleController) Detail() {
 			//		hasPermission = 3
 			//	}
 			//}
-
-			articlePermission, err := models.GetArticlePermission(detail.SubCategoryName)
-			fmt.Println(articlePermission)
-			fmt.Println(detail.SubCategoryName)
+			articlePermission, err := models.GetArticlePermission(detail.CategoryId)
 			if err != nil {
 				br.Msg = "获取信息失败"
 				br.ErrMsg = "获取报告权限失败,Err:" + err.Error() + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
@@ -132,22 +123,19 @@ func (this *ArticleController) Detail() {
 				br.ErrMsg = "报告权限不存在,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
 				return
 			}
-			for _, p := range articlePermission {
-				if strings.Contains(companyPermission, p.PermissionName) {
-					hasPermission = 1
-					historyRecord := new(models.CygxArticleHistoryRecord)
-					historyRecord.UserId = uid
-					historyRecord.ArticleId = articleId
-					historyRecord.CreateTime = time.Now()
-					historyRecord.Mobile = user.Mobile
-					historyRecord.Email = user.Email
-					historyRecord.CompanyId = user.CompanyId
-					historyRecord.CompanyName = user.CompanyName
-					go models.AddCygxArticleHistoryRecord(historyRecord)
-					break
-				} else { //无该行业权限
-					hasPermission = 3
-				}
+			if strings.Contains(companyPermission, articlePermission.PermissionName) {
+				hasPermission = 1
+				historyRecord := new(models.CygxArticleHistoryRecord)
+				historyRecord.UserId = uid
+				historyRecord.ArticleId = articleId
+				historyRecord.CreateTime = time.Now()
+				historyRecord.Mobile = user.Mobile
+				historyRecord.Email = user.Email
+				historyRecord.CompanyId = user.CompanyId
+				historyRecord.CompanyName = user.CompanyName
+				go models.AddCygxArticleHistoryRecord(historyRecord)
+			} else { //无该行业权限
+				hasPermission = 3
 			}
 			if hasPermission == 1 {
 				key := "CYGX_ARTICLE_" + strconv.Itoa(articleId) + "_" + strconv.Itoa(uid)
@@ -173,18 +161,15 @@ func (this *ArticleController) Detail() {
 			br.ErrMsg = "判断是否已收藏失败,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
 			return
 		}
-
 		if collectCount > 0 {
 			detail.IsCollect = true
 		}
-
 		interviewApplyItem, err := models.GetArticleInterviewApply(uid, articleId)
 		if err != nil && err.Error() != utils.ErrNoRow() {
 			br.Msg = "获取信息失败"
 			br.ErrMsg = "判断是否已申请访谈失败,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
 			return
 		}
-
 		if interviewApplyItem != nil && interviewApplyItem.InterviewApplyId > 0 {
 			detail.IsInterviewApply = true
 			detail.InterviewApplyStatus = interviewApplyItem.Status

+ 2 - 2
controllers/report.go

@@ -125,7 +125,7 @@ func (this *ReportController) IndustryList() {
 		return
 	}
 	if orderColumn == "NewTime" {
-		orderSrt = "art.publish_date DESC"
+		orderSrt = "update_time DESC"
 	} else {
 		orderSrt = "man.recommended_index DESC"
 	}
@@ -142,7 +142,7 @@ func (this *ReportController) IndustryList() {
 		}
 		list = listTop
 	} else if totalTop < (currentIndex-1)*pageSize { //全部都是不置顶
-		listNoTop, err := models.GetIndustrialManagementAll(ChartPermissionId, uid, orderSrt, startSize-totalTop+1, pageSize)
+		listNoTop, err := models.GetIndustrialManagementAll(ChartPermissionId, uid, orderSrt, startSize-totalTop, pageSize)
 		if err != nil {
 			br.Msg = "获取信息失败"
 			br.ErrMsg = "获取品种信息失败,Err:" + err.Error()

+ 16 - 18
controllers/tactics.go

@@ -184,7 +184,7 @@ func (this *TacticsController) Detail() {
 			goto Loop
 		} else {
 			hasFree = 1
-			articlePermission, err := models.GetReportPermission(detail.SubCategoryName)
+			articlePermission, err := models.GetArticlePermission(detail.CategoryId)
 			if err != nil {
 				br.Msg = "获取信息失败"
 				br.ErrMsg = "获取报告权限失败,Err:" + err.Error() + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
@@ -195,24 +195,22 @@ func (this *TacticsController) Detail() {
 				br.ErrMsg = "报告权限不存在,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
 				return
 			}
-			for _, p := range articlePermission {
-				fmt.Println(p)
-				if strings.Contains(companyPermission, p.PermissionName) {
-					hasPermission = 1
-					historyRecord := new(models.CygxArticleHistoryRecord)
-					historyRecord.UserId = uid
-					historyRecord.ArticleId = articleId
-					historyRecord.CreateTime = time.Now()
-					historyRecord.Mobile = user.Mobile
-					historyRecord.Email = user.Email
-					historyRecord.CompanyId = user.CompanyId
-					historyRecord.CompanyName = user.CompanyName
-					go models.AddCygxArticleHistoryRecord(historyRecord)
-					break
-				} else { //无该行业权限
-					hasPermission = 3
-				}
+			if strings.Contains(companyPermission, articlePermission.PermissionName) {
+				hasPermission = 1
+				historyRecord := new(models.CygxArticleHistoryRecord)
+				historyRecord.UserId = uid
+				historyRecord.ArticleId = articleId
+				historyRecord.CreateTime = time.Now()
+				historyRecord.Mobile = user.Mobile
+				historyRecord.Email = user.Email
+				historyRecord.CompanyId = user.CompanyId
+				historyRecord.CompanyName = user.CompanyName
+				go models.AddCygxArticleHistoryRecord(historyRecord)
+
+			} else { //无该行业权限
+				hasPermission = 3
 			}
+
 		}
 		collectCount, err := models.GetArticleCollectCount(uid, articleId)
 		if err != nil && err.Error() != utils.ErrNoRow() {

+ 19 - 19
models/article.go

@@ -74,6 +74,7 @@ type ArticleDetail struct {
 	SellerName           string `description:"销售名称"`
 	ArticleIdMd5         string `description:"纪要id"`
 	IsClass              int    `description:"是否归类,1是,0否"`
+	CategoryId           int    `description:"分类ID"`
 	SellerList           []*SellerRep
 }
 
@@ -117,30 +118,29 @@ func GetArticleDetailByIdStr(articleIdStr string) (items []*ArticleDetail, err e
 	return
 }
 
-func GetArticlePermission(categoryName string) (item []*ChartPermission, err error) {
-	o := orm.NewOrm()
-	sql := ` SELECT b.* FROM cygx_permission_mapping AS a
-			INNER JOIN chart_permission AS b ON a.chart_permission_id=b.chart_permission_id
-			WHERE a.sub_category_name=? `
-	_, err = o.Raw(sql, categoryName).QueryRows(&item)
-	return
-}
-
-//func GetArticlePermission(companyId int) (item []*ChartPermission, err error) {
+//func GetArticlePermission(categoryName string) (item []*ChartPermission, err error) {
 //	o := orm.NewOrm()
-//	sql := `SELECT b.chart_permission_name
-//			FROM company_report_permission AS a
+//	sql := ` SELECT b.* FROM cygx_permission_mapping AS a
 //			INNER JOIN chart_permission AS b ON a.chart_permission_id=b.chart_permission_id
-//			INNER JOIN company_product AS c ON a.company_id=c.company_id AND a.product_id=c.product_id
-//			WHERE  a.company_id= ?
-//			AND a.product_id=2
-//			AND c.is_suspend=0
-//            AND b.is_report=1
-//			AND c.status IN('正式','试用','永续')`
-//	_, err = o.Raw(sql, companyId).QueryRows(&item)
+//			WHERE a.sub_category_name=? `
+//	_, err = o.Raw(sql, categoryName).QueryRows(&item)
 //	return
 //}
 
+func GetArticlePermission(companyId int) (item *ChartPermission, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT
+			b.* 
+			FROM
+			cygx_report_mapping AS a
+			INNER JOIN chart_permission AS b ON a.chart_permission_id = b.chart_permission_id 
+			WHERE
+			a.category_id = ?`
+	err = o.Raw(sql, companyId).QueryRow(&item)
+	//_, err = o.Raw(sql, companyId).QueryRows(&item)
+	return
+}
+
 type ArticleDetailResp struct {
 	Detail        *ArticleDetail
 	HasPermission int `description:"1:有该行业权限,正常展示,2:无该行业权限,不存在权益客户下,3:无该品类权限,已提交过申请,4:无该行业权限,未提交过申请,5:潜在客户,未提交过申请,6:潜在客户,已提交过申请"`

+ 4 - 1
models/industrial_management.go

@@ -53,7 +53,7 @@ func GetIndustrialManagementAll(ChartPermissionId, uid int, orderSrt string, sta
 	o := orm.NewOrm()
 	sql := `SELECT
 			man.*,
-			art.publish_date AS update_time,(
+            MAX( art.publish_date ) AS update_time ,(
 			SELECT COUNT( 1 ) FROM cygx_article_history_record AS rec WHERE rec.user_id = ` + strconv.Itoa(uid) + ` AND rec.article_id = art.article_id ) AS readnum 
 			FROM
 			cygx_industrial_management AS man
@@ -69,6 +69,9 @@ func GetIndustrialManagementAll(ChartPermissionId, uid int, orderSrt string, sta
 			GROUP BY
 			man.industry_name 
 			ORDER BY ` + orderSrt + ` LIMIT ?,?`
+	//fmt.Println(sql)
+	//fmt.Println(startSize)
+	//fmt.Println(pageSize)
 	_, err = o.Raw(sql, ChartPermissionId, startSize, pageSize).QueryRows(&items)
 	return
 }