Browse Source

Merge branch 'cygx_v2' of hongze/hongze_cygx into master

hongze 3 years ago
parent
commit
5fad6dec29
3 changed files with 47 additions and 24 deletions
  1. 19 9
      controllers/article.go
  2. 27 15
      controllers/tactics.go
  3. 1 0
      models/article_history_record.go

+ 19 - 9
controllers/article.go

@@ -134,17 +134,27 @@ func (this *ArticleController) Detail() {
 
 			if strings.Contains(companyPermission, articlePermissionPermissionName) {
 				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
 				recordCount, _ := models.GetNoAddStoptimeArticleCount(uid, articleId)
-				if recordCount < 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
+				if recordCount == 0 {
 					go models.AddCygxArticleHistoryRecord(historyRecord)
+				} else {
+					detailNew, err := models.GetNewArticleHistoryRecord(uid, articleId)
+					if err != nil {
+						br.Msg = "获取信息失败"
+						br.ErrMsg = "获取信息失败,Err:" + err.Error()
+						return
+					}
+					if detailNew.StopTime > 0 {
+						go models.AddCygxArticleHistoryRecord(historyRecord)
+					}
 				}
 			} else { //无该行业权限
 				hasPermission = 3

+ 27 - 15
controllers/tactics.go

@@ -104,13 +104,15 @@ func (this *TacticsController) List() {
 			list[k].IsRed = true
 		}
 	}
-	detail, errCategory := models.GetdetailByCategoryId(categoryId)
-	if errCategory != nil && errCategory.Error() != utils.ErrNoRow() {
-		br.Msg = "获取信息失败"
-		br.ErrMsg = "获取信息失败,Err:" + errCategory.Error()
-		return
+	if categoryId > 0 {
+		detail, errCategory := models.GetdetailByCategoryId(categoryId)
+		if errCategory != nil {
+			br.Msg = "获取信息失败"
+			br.ErrMsg = "获取信息失败,Err:" + errCategory.Error() + "categoryID 不存在:" + strconv.Itoa(categoryId)
+			return
+		}
+		resp.MatchTypeName = detail.MatchTypeName
 	}
-	resp.MatchTypeName = detail.MatchTypeName
 	resp.List = list
 	resp.Paging = page
 	br.Ret = 200
@@ -204,17 +206,27 @@ func (this *TacticsController) Detail() {
 			}
 			if strings.Contains(companyPermission, articlePermissionPermissionName) {
 				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
 				recordCount, _ := models.GetNoAddStoptimeArticleCount(uid, articleId)
-				if recordCount < 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
+				if recordCount == 0 {
 					go models.AddCygxArticleHistoryRecord(historyRecord)
+				} else {
+					detailNew, err := models.GetNewArticleHistoryRecord(uid, articleId)
+					if err != nil {
+						br.Msg = "获取信息失败"
+						br.ErrMsg = "获取信息失败,Err:" + err.Error()
+						return
+					}
+					if detailNew.StopTime > 0 {
+						go models.AddCygxArticleHistoryRecord(historyRecord)
+					}
 				}
 			} else { //无该行业权限
 				hasPermission = 3

+ 1 - 0
models/article_history_record.go

@@ -102,6 +102,7 @@ func GetNewArticleHistoryRecord(uid, articleId int) (item *AddStopTimeNewRep, er
 //获取用户阅读记录
 func GetNoAddStoptimeArticleCount(uid, articleId int) (count int, err error) {
 	sqlCount := `SELECT COUNT(1) AS count FROM cygx_article_history_record WHERE user_id=? AND article_id=? AND create_time > '` + utils.OnlineTime + `' AND stop_time = 0 `
+	//sqlCount := `SELECT COUNT(1) AS count FROM cygx_article_history_record WHERE id = ? AND stop_time = 0 `
 	o := orm.NewOrm()
 	err = o.Raw(sqlCount, uid, articleId).QueryRow(&count)
 	return