Pārlūkot izejas kodu

Merge branch 'cygx_v2' of hongze/hongze_cygx into master

hongze 4 gadi atpakaļ
vecāks
revīzija
5df0857863
5 mainītis faili ar 109 papildinājumiem un 33 dzēšanām
  1. 40 9
      controllers/article.go
  2. 21 14
      controllers/home.go
  3. 26 10
      controllers/tactics.go
  4. 1 0
      models/article.go
  5. 21 0
      models/article_history_record.go

+ 40 - 9
controllers/article.go

@@ -6,6 +6,7 @@ import (
 	"hongze/hongze_cygx/services"
 	"hongze/hongze_cygx/utils"
 	"html"
+	"regexp"
 	"strconv"
 	"strings"
 	"time"
@@ -133,18 +134,22 @@ 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
-				go models.AddCygxArticleHistoryRecord(historyRecord)
+				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
+					go models.AddCygxArticleHistoryRecord(historyRecord)
+				}
 			} else { //无该行业权限
 				hasPermission = 3
 			}
+
 			if hasPermission == 1 {
 				key := "CYGX_ARTICLE_" + strconv.Itoa(articleId) + "_" + strconv.Itoa(uid)
 				if !utils.Rc.IsExist(key) {
@@ -199,6 +204,19 @@ func (this *ArticleController) Detail() {
 			br.ErrMsg = "获取销售数据失败,Err:" + err.Error() + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
 			return
 		}
+		if detail.ArticleId > 1000000 {
+			var hrefRegexp = regexp.MustCompile("[0-9]\\d*")
+			match := hrefRegexp.FindAllString(detail.SellerAndMobile, -1)
+			if match != nil {
+				for _, v := range match {
+					sellerAndMobile := &models.SellerRep{
+						SellerMobile: v,
+						SellerName:   strings.Replace(detail.SellerAndMobile, v, "", -1),
+					}
+					sellerList = append(sellerList, sellerAndMobile)
+				}
+			}
+		}
 		detail.SellerList = sellerList
 	} else { //潜在客户
 		if applyCount > 0 {
@@ -430,6 +448,19 @@ func (this *ArticleCommonController) Detail() {
 		br.ErrMsg = "获取销售数据失败,Err:" + err.Error() + ";articleId" + strconv.Itoa(detail.ArticleId)
 		return
 	}
+	if detail.ArticleId > 1000000 {
+		var hrefRegexp = regexp.MustCompile("[0-9]\\d*")
+		match := hrefRegexp.FindAllString(detail.SellerAndMobile, -1)
+		if match != nil {
+			for _, v := range match {
+				sellerAndMobile := &models.SellerRep{
+					SellerMobile: v,
+					SellerName:   strings.Replace(detail.SellerAndMobile, v, "", -1),
+				}
+				sellerList = append(sellerList, sellerAndMobile)
+			}
+		}
+	}
 	detail.SellerList = sellerList
 	resp.Detail = detail
 	br.Ret = 200

+ 21 - 14
controllers/home.go

@@ -1,6 +1,7 @@
 package controllers
 
 import (
+	"fmt"
 	"hongze/hongze_cygx/models"
 	"hongze/hongze_cygx/services"
 	"hongze/hongze_cygx/utils"
@@ -42,7 +43,7 @@ func (this *HomeController) ListHome() {
 	var total int
 	resp := new(models.HomeListResp)
 	page := paging.GetPaging(currentIndex, pageSize, total)
-
+	condition += ` AND is_summary = 1  `
 	if chartPermissionId > 0 {
 		categoryId, err := models.GetCategoryId(chartPermissionId)
 		if err != nil && err.Error() != utils.ErrNoRow() {
@@ -57,22 +58,28 @@ func (this *HomeController) ListHome() {
 			return
 		}
 		page = paging.GetPaging(currentIndex, pageSize, total)
-		if categoryId == "" {
-			list := make([]*models.HomeArticle, 0)
-			resp.List = list
-			resp.Paging = page
-			br.Ret = 200
-			br.Success = true
-			br.Msg = "获取成功"
-			br.Data = resp
-			return
+		//if categoryId == "" {
+		//	list := make([]*models.HomeArticle, 0)
+		//	resp.List = list
+		//	resp.Paging = page
+		//	br.Ret = 200
+		//	br.Success = true
+		//	br.Msg = "获取成功"
+		//	br.Data = resp
+		//	return
+		//}
+
+		if categoryId != "" {
+			condition += ` AND category_id IN(` + categoryId + `)`
+			condition += ` OR ( category_name = '` + categoryinfo.PermissionName + `' AND publish_status = 1 AND is_summary = 1 )`
+		} else {
+			condition += ` AND  category_name = '` + categoryinfo.PermissionName + `'`
 		}
-		condition = ` AND category_id IN(` + categoryId + `)`
-		condition += ` OR ( category_name = '` + categoryinfo.PermissionName + `' AND publish_status = 1 )`
+
 	}
-	condition += ` AND is_summary = 1  `
-	//condition = ` AND a.category_id NOT IN (85,71) `
 
+	//condition = ` AND a.category_id NOT IN (85,71) `
+	fmt.Println(condition)
 	total, err := models.GetHomeCount(condition, pars)
 	if err != nil {
 		br.Msg = "获取信息失败"

+ 26 - 10
controllers/tactics.go

@@ -7,6 +7,7 @@ import (
 	"hongze/hongze_cygx/utils"
 	"html"
 	"rdluck_tools/paging"
+	"regexp"
 	"strconv"
 	"strings"
 	"time"
@@ -203,16 +204,18 @@ 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
-				go models.AddCygxArticleHistoryRecord(historyRecord)
-
+				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
+					go models.AddCygxArticleHistoryRecord(historyRecord)
+				}
 			} else { //无该行业权限
 				hasPermission = 3
 			}
@@ -257,6 +260,19 @@ func (this *TacticsController) Detail() {
 			br.ErrMsg = "获取销售数据失败,Err:" + err.Error() + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
 			return
 		}
+		if detail.ArticleId > 1000000 {
+			var hrefRegexp = regexp.MustCompile("[0-9]\\d*")
+			match := hrefRegexp.FindAllString(detail.SellerAndMobile, -1)
+			if match != nil {
+				for _, v := range match {
+					sellerAndMobile := &models.SellerRep{
+						SellerMobile: v,
+						SellerName:   strings.Replace(detail.SellerAndMobile, v, "", -1),
+					}
+					sellerList = append(sellerList, sellerAndMobile)
+				}
+			}
+		}
 		detail.SellerList = sellerList
 	} else { //潜在客户
 		if applyCount > 0 {

+ 1 - 0
models/article.go

@@ -78,6 +78,7 @@ type ArticleDetail struct {
 	IsClass              int    `description:"是否归类,1是,0否"`
 	CategoryId           int    `description:"分类ID"`
 	FileLink             string `description:"下载预览链接"`
+	SellerAndMobile      string `description:"销售和手机号"`
 	SellerList           []*SellerRep
 }
 

+ 21 - 0
models/article_history_record.go

@@ -73,8 +73,21 @@ type ArticleDetailAddStopTimeRep struct {
 
 func AddArticleStopTime(item *AddStopTimeNewRep) (err error) {
 	o := orm.NewOrm()
+	//o.Begin()
+	//defer func() {
+	//	if err == nil {
+	//		o.Commit()
+	//	} else {
+	//		o.Rollback()
+	//	}
+	//}()
 	sql := `UPDATE cygx_article_history_record SET stop_time = ? WHERE id =?`
 	_, err = o.Raw(sql, item.StopTime, item.Id).Exec()
+	if err != nil && err.Error() != utils.ErrNoRow() {
+		return
+	}
+	//sql = ` DELETE  FROM cygx_article_history_record  WHERE create_time > '2021-06-01 00:00:00' AND stop_time = 0`
+	//_, err = o.Raw(sql).Exec()
 	return
 }
 
@@ -85,3 +98,11 @@ func GetNewArticleHistoryRecord(uid, articleId int) (item *AddStopTimeNewRep, er
 	err = o.Raw(sql, uid, articleId).QueryRow(&item)
 	return
 }
+
+//获取用户阅读记录
+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 `
+	o := orm.NewOrm()
+	err = o.Raw(sqlCount, uid, articleId).QueryRow(&count)
+	return
+}