rdluck 3 роки тому
батько
коміт
d56a64ad68
3 змінених файлів з 21 додано та 35 видалено
  1. 16 31
      controllers/article.go
  2. 3 3
      models/article.go
  3. 2 1
      utils/config.go

+ 16 - 31
controllers/article.go

@@ -97,37 +97,22 @@ func (this *ArticleController) Detail() {
 				br.ErrMsg = "报告权限不存在,Err:" + err.Error() + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
 				return
 			}
-			if strings.Contains(companyPermission, articlePermission.PermissionName) {
-				hasPermission = 1
-				//bm, err := cache.NewCache("file", `{"CachePath":"./temp/cache","FileSuffix":".cache","DirectoryLevel":2,"EmbedExpiry":120}`)
-				//if err != nil {
-				//	fmt.Println("false")
-				//}
-				//key := "ViewRecord:" + strconv.Itoa(uid) + "_" + strconv.Itoa(articleId)
-				//if !bm.IsExist(key) {
-				//	//新增浏览记录
-				//	record := new(models.CygxArticleViewRecord)
-				//	record.UserId = uid
-				//	record.ArticleId = articleId
-				//	record.CreateTime = time.Now()
-				//	record.Mobile = user.Mobile
-				//	record.Email = user.Email
-				//	record.CompanyId = user.CompanyId
-				//	record.CompanyName = user.CompanyName
-				//	go models.AddCygxArticleViewRecord(record)
-				//	bm.Put(key, 1, 30*time.Second)
-				//}
-				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
+			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
+				}
 			}
 		}
 		collectCount, err := models.GetArticleCollectCount(uid, articleId)

+ 3 - 3
models/article.go

@@ -92,12 +92,12 @@ func GetArticleDetailByIdStr(articleIdStr string) (items []*ArticleDetail, err e
 	return
 }
 
-func GetArticlePermission(categoryName string) (item *ChartPermission, err error) {
+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).QueryRow(&item)
+	_, err = o.Raw(sql, categoryName).QueryRows(&item)
 	return
 }
 
@@ -170,4 +170,4 @@ func GetArticleCountById(articleId int) (count int, err error) {
 	sql := `SELECT COUNT(1) AS count FROM cygx_article WHERE article_id = ? `
 	err = o.Raw(sql, articleId).QueryRow(&count)
 	return
-}
+}

+ 2 - 1
utils/config.go

@@ -57,7 +57,8 @@ func init() {
 		WxPublicAppId = "wx4a844c734d8c8e56"
 		WxPublicAppSecret = "26c586e7ccb3c575433f0f37797b3eeb"
 		WxPublicId = "gh_b67e0049fb8c"
-		IndexName="cygx_article_v1"
+		//IndexName="cygx_article_v1"
+		IndexName="cygx_article_v2"
 	} else {
 		WxAppId = "wxcc32b61f96720d2f"
 		WxAppSecret = "06894933fafb24dafead7eaae09c08e0"