Browse Source

Merge remote-tracking branch 'origin/fix/split_db'

Roc 1 year ago
parent
commit
b9f854dbb1
2 changed files with 157 additions and 151 deletions
  1. 155 151
      controllers/company_user.go
  2. 2 0
      models/company/company_user.go

+ 155 - 151
controllers/company_user.go

@@ -967,64 +967,64 @@ func (this *CompanyUserController) List() {
 		//}
 
 		//报告统计删除晨报部分统计加入每日资讯 2021-4-9
-		//手机号
-		userViewMobileTotalMap := make(map[string]*models.UserViewMobileTotalSlice)
-		userReportViewMobileTotalMap := make(map[string]*models.ReportViewMobileRecord)
-		userAdvisoryViewMobileTotalMap := make(map[string]*advisory.UserViewMobileTotalSlice)
-		userCygxArticleHistoryRecordViewMobileTotalMap := make(map[string]*models.UserViewMobileTotalSlice)
-		if len(mobilesSlice) > 0 {
-			//用户浏览数据
-			userViewMobileTotalList, _ := models.GetCountUserViewHistoryByMobiles(mobileStr)
-			for _, userViewMobile := range userViewMobileTotalList {
-				userViewMobileTotalMap[userViewMobile.Mobile] = userViewMobile
-			}
-
-			//每日点评手机号数据
-			userReportViewMobileTotalList, _ := models.GetReportViewMaxTimeByMobiles(mobileStr)
-			for _, userReportViewMobile := range userReportViewMobileTotalList {
-				userReportViewMobileTotalMap[userReportViewMobile.Mobile] = userReportViewMobile
-			}
-
-			//每日资讯
-			userAdvisoryViewMobileTotalList, _ := advisory.GetCountUserViewHistoryByMobiles(mobileStr)
-			//fmt.Println(userAdvisoryViewMobileTotalList)
-			for _, userAdvisoryViewMobile := range userAdvisoryViewMobileTotalList {
-				userAdvisoryViewMobileTotalMap[userAdvisoryViewMobile.Mobile] = userAdvisoryViewMobile
-			}
-			//查研观向
-			userCygxArticleHistoryRecordViewMobileTotalList, _ := models.GetCountCygxArticleHistoryRecordByMobiles(mobileStr)
-			for _, userCygxArticleHistoryRecordViewMobile := range userCygxArticleHistoryRecordViewMobileTotalList {
-				userCygxArticleHistoryRecordViewMobileTotalMap[userCygxArticleHistoryRecordViewMobile.Mobile] = userCygxArticleHistoryRecordViewMobile
-			}
-		}
+		////手机号
+		//userViewMobileTotalMap := make(map[string]*models.UserViewMobileTotalSlice)
+		//userReportViewMobileTotalMap := make(map[string]*models.ReportViewMobileRecord)
+		//userAdvisoryViewMobileTotalMap := make(map[string]*advisory.UserViewMobileTotalSlice)
+		//userCygxArticleHistoryRecordViewMobileTotalMap := make(map[string]*models.UserViewMobileTotalSlice)
+		//if len(mobilesSlice) > 0 {
+		//	//用户浏览数据
+		//	userViewMobileTotalList, _ := models.GetCountUserViewHistoryByMobiles(mobileStr)
+		//	for _, userViewMobile := range userViewMobileTotalList {
+		//		userViewMobileTotalMap[userViewMobile.Mobile] = userViewMobile
+		//	}
+		//
+		//	//每日点评手机号数据
+		//	userReportViewMobileTotalList, _ := models.GetReportViewMaxTimeByMobiles(mobileStr)
+		//	for _, userReportViewMobile := range userReportViewMobileTotalList {
+		//		userReportViewMobileTotalMap[userReportViewMobile.Mobile] = userReportViewMobile
+		//	}
+		//
+		//	//每日资讯
+		//	userAdvisoryViewMobileTotalList, _ := advisory.GetCountUserViewHistoryByMobiles(mobileStr)
+		//	//fmt.Println(userAdvisoryViewMobileTotalList)
+		//	for _, userAdvisoryViewMobile := range userAdvisoryViewMobileTotalList {
+		//		userAdvisoryViewMobileTotalMap[userAdvisoryViewMobile.Mobile] = userAdvisoryViewMobile
+		//	}
+		//	//查研观向
+		//	userCygxArticleHistoryRecordViewMobileTotalList, _ := models.GetCountCygxArticleHistoryRecordByMobiles(mobileStr)
+		//	for _, userCygxArticleHistoryRecordViewMobile := range userCygxArticleHistoryRecordViewMobileTotalList {
+		//		userCygxArticleHistoryRecordViewMobileTotalMap[userCygxArticleHistoryRecordViewMobile.Mobile] = userCygxArticleHistoryRecordViewMobile
+		//	}
+		//}
 
-		//邮箱
-		userViewEmailTotalMap := make(map[string]*models.UserViewEmailTotalSlice)
-		userReportViewEmailTotalMap := make(map[string]*models.ReportViewEmailRecord)
-		userAdvisoryViewEmailTotalMap := make(map[string]*advisory.UserViewEmailTotalSlice)
-		userCygxViewEmailTotalMap := make(map[string]*models.UserViewEmailTotalSlice)
-		if len(emailsSlice) > 0 {
-			//用户浏览数据
-			userViewEmailTotalList, _ := models.GetCountUserViewHistoryByEmails(emailStr)
-			for _, userViewEmail := range userViewEmailTotalList {
-				userViewEmailTotalMap[userViewEmail.Email] = userViewEmail
-			}
-			//每日点评手机号数据
-			userReportViewEmailTotalList, _ := models.GetReportViewMaxTimeByEmails(emailStr)
-			for _, userReportViewEmail := range userReportViewEmailTotalList {
-				userReportViewEmailTotalMap[userReportViewEmail.Email] = userReportViewEmail
-			}
-			//每日资讯
-			userAdvisoryViewEmailTotalList, _ := advisory.GetCountUserViewHistoryByEmails(emailStr)
-			for _, userAdvisoryViewEmail := range userAdvisoryViewEmailTotalList {
-				userAdvisoryViewEmailTotalMap[userAdvisoryViewEmail.Email] = userAdvisoryViewEmail
-			}
-			//查研观向
-			userCygxViewEmailTotalList, _ := models.GetCountCygxArticleHistoryRecordByEmails(emailStr)
-			for _, userCygxReportViewEmail := range userCygxViewEmailTotalList {
-				userCygxViewEmailTotalMap[userCygxReportViewEmail.Email] = userCygxReportViewEmail
-			}
-		}
+		////邮箱
+		//userViewEmailTotalMap := make(map[string]*models.UserViewEmailTotalSlice)
+		//userReportViewEmailTotalMap := make(map[string]*models.ReportViewEmailRecord)
+		//userAdvisoryViewEmailTotalMap := make(map[string]*advisory.UserViewEmailTotalSlice)
+		//userCygxViewEmailTotalMap := make(map[string]*models.UserViewEmailTotalSlice)
+		//if len(emailsSlice) > 0 {
+		//	//用户浏览数据
+		//	userViewEmailTotalList, _ := models.GetCountUserViewHistoryByEmails(emailStr)
+		//	for _, userViewEmail := range userViewEmailTotalList {
+		//		userViewEmailTotalMap[userViewEmail.Email] = userViewEmail
+		//	}
+		//	//每日点评手机号数据
+		//	userReportViewEmailTotalList, _ := models.GetReportViewMaxTimeByEmails(emailStr)
+		//	for _, userReportViewEmail := range userReportViewEmailTotalList {
+		//		userReportViewEmailTotalMap[userReportViewEmail.Email] = userReportViewEmail
+		//	}
+		//	//每日资讯
+		//	userAdvisoryViewEmailTotalList, _ := advisory.GetCountUserViewHistoryByEmails(emailStr)
+		//	for _, userAdvisoryViewEmail := range userAdvisoryViewEmailTotalList {
+		//		userAdvisoryViewEmailTotalMap[userAdvisoryViewEmail.Email] = userAdvisoryViewEmail
+		//	}
+		//	//查研观向
+		//	userCygxViewEmailTotalList, _ := models.GetCountCygxArticleHistoryRecordByEmails(emailStr)
+		//	for _, userCygxReportViewEmail := range userCygxViewEmailTotalList {
+		//		userCygxViewEmailTotalMap[userCygxReportViewEmail.Email] = userCygxReportViewEmail
+		//	}
+		//}
 
 		//获取联系人关联产品的条数
 		userSellerRelationTotalSlice, err := models.GetUserSellerRelationCountByUserIds(userIdStr)
@@ -1090,23 +1090,6 @@ func (this *CompanyUserController) List() {
 			item := list[i]
 			//企业名称
 			list[i].CompanyName = companyInfo.CompanyName
-			//手机号用户累计浏览次数
-			if userView, ok := userViewMobileTotalMap[item.Mobile]; ok {
-				list[i].ViewTotal += userView.Total
-				if userView.CreatedTime.After(list[i].LastViewTime) {
-					list[i].LastViewTime = userView.CreatedTime
-					list[i].LastViewTimeStr = userView.CreatedTime.Format(utils.FormatDateTime)
-				}
-			}
-			//邮箱用户累计浏览次数
-			if userView, ok := userViewEmailTotalMap[item.Email]; ok {
-				//总共浏览的报表数据需要调整为(手机号用户浏览晨报数+邮箱号用户浏览晨报数)
-				list[i].ViewTotal += userView.Total
-				if userView.CreatedTime.After(list[i].LastViewTime) {
-					list[i].LastViewTime = userView.CreatedTime
-					list[i].LastViewTimeStr = userView.CreatedTime.Format(utils.FormatDateTime)
-				}
-			}
 
 			if item.OpenId != "" {
 				list[i].IsRegister = true
@@ -1121,78 +1104,98 @@ func (this *CompanyUserController) List() {
 					list[i].IsRegister = false
 				}
 			}
-			//如果存在手机号用户日评数据,那么需要做处理
-			if reportView, ok := userReportViewMobileTotalMap[item.Mobile]; ok {
-				//对日评数据做校验,日评时间晚于晨报时间,那么将最近一次浏览时间替换
-				if reportView.LastViewTime.After(list[i].LastViewTime) {
-					list[i].LastViewTime = reportView.LastViewTime
-					list[i].LastViewTimeStr = reportView.LastViewTime.Format(utils.FormatDateTime)
-				}
-				//总共浏览的报表数据需要调整为(浏览晨报数+浏览日评数)
-				list[i].ViewTotal += reportView.ViewTotal
-			}
-			//如果存在手机号用户日评数据,那么需要做处理
-			if reportView, ok := userReportViewEmailTotalMap[item.Email]; ok {
-				//对日评数据做校验,日评时间晚于晨报时间,那么将最近一次浏览时间替换
-				if reportView.LastViewTime.After(list[i].LastViewTime) {
-					list[i].LastViewTime = reportView.LastViewTime
-					list[i].LastViewTimeStr = reportView.LastViewTime.Format(utils.FormatDateTime)
-				}
-				//总共浏览的报表数据需要调整为(浏览晨报数+浏览日评数)
-				list[i].ViewTotal += reportView.ViewTotal
-			}
 
-			//如果存在手机号用户每日资讯,那么需要做处理
-			if advisoryView, ok := userAdvisoryViewMobileTotalMap[item.Mobile]; ok {
-				//fmt.Println("蝴蝶眨几次眼睛")
-				//对每日资讯数据做校验,每日资讯时间晚日评报时间,那么将最近一次浏览时间替换
-				if advisoryView.CreatedTime.After(list[i].LastViewTime) {
-					list[i].LastViewTime = advisoryView.CreatedTime
-					list[i].LastViewTimeStr = advisoryView.CreatedTime.Format(utils.FormatDateTime)
-				}
-				//总共浏览的报表数据需要调整为(浏览晨报数+浏览日评数+每日资讯数)
-				list[i].ViewTotal += advisoryView.Total
-			}
-			//如果存在邮箱号用户每日资讯,那么需要做处理
-			if advisoryView, ok := userAdvisoryViewEmailTotalMap[item.Email]; ok {
-				//对每日资讯数据做校验,每日资讯时间晚日评报时间,那么将最近一次浏览时间替换
-				if advisoryView.CreatedTime.After(list[i].LastViewTime) {
-					list[i].LastViewTime = advisoryView.CreatedTime
-					list[i].LastViewTimeStr = advisoryView.CreatedTime.Format(utils.FormatDateTime)
-				}
-				//总共浏览的报表数据需要调整为(浏览晨报数+浏览日评数+每日资讯数)
-				list[i].ViewTotal += advisoryView.Total
-			}
+			////手机号用户累计浏览次数
+			//if userView, ok := userViewMobileTotalMap[item.Mobile]; ok {
+			//	list[i].ViewTotal += userView.Total
+			//	if userView.CreatedTime.After(list[i].LastViewTime) {
+			//		list[i].LastViewTime = userView.CreatedTime
+			//		list[i].LastViewTimeStr = userView.CreatedTime.Format(utils.FormatDateTime)
+			//	}
+			//}
+			////邮箱用户累计浏览次数
+			//if userView, ok := userViewEmailTotalMap[item.Email]; ok {
+			//	//总共浏览的报表数据需要调整为(手机号用户浏览晨报数+邮箱号用户浏览晨报数)
+			//	list[i].ViewTotal += userView.Total
+			//	if userView.CreatedTime.After(list[i].LastViewTime) {
+			//		list[i].LastViewTime = userView.CreatedTime
+			//		list[i].LastViewTimeStr = userView.CreatedTime.Format(utils.FormatDateTime)
+			//	}
+			//}
+			////如果存在手机号用户日评数据,那么需要做处理
+			//if reportView, ok := userReportViewMobileTotalMap[item.Mobile]; ok {
+			//	//对日评数据做校验,日评时间晚于晨报时间,那么将最近一次浏览时间替换
+			//	if reportView.LastViewTime.After(list[i].LastViewTime) {
+			//		list[i].LastViewTime = reportView.LastViewTime
+			//		list[i].LastViewTimeStr = reportView.LastViewTime.Format(utils.FormatDateTime)
+			//	}
+			//	//总共浏览的报表数据需要调整为(浏览晨报数+浏览日评数)
+			//	list[i].ViewTotal += reportView.ViewTotal
+			//}
+			////如果存在手机号用户日评数据,那么需要做处理
+			//if reportView, ok := userReportViewEmailTotalMap[item.Email]; ok {
+			//	//对日评数据做校验,日评时间晚于晨报时间,那么将最近一次浏览时间替换
+			//	if reportView.LastViewTime.After(list[i].LastViewTime) {
+			//		list[i].LastViewTime = reportView.LastViewTime
+			//		list[i].LastViewTimeStr = reportView.LastViewTime.Format(utils.FormatDateTime)
+			//	}
+			//	//总共浏览的报表数据需要调整为(浏览晨报数+浏览日评数)
+			//	list[i].ViewTotal += reportView.ViewTotal
+			//}
+			//
+			////如果存在手机号用户每日资讯,那么需要做处理
+			//if advisoryView, ok := userAdvisoryViewMobileTotalMap[item.Mobile]; ok {
+			//	//fmt.Println("蝴蝶眨几次眼睛")
+			//	//对每日资讯数据做校验,每日资讯时间晚日评报时间,那么将最近一次浏览时间替换
+			//	if advisoryView.CreatedTime.After(list[i].LastViewTime) {
+			//		list[i].LastViewTime = advisoryView.CreatedTime
+			//		list[i].LastViewTimeStr = advisoryView.CreatedTime.Format(utils.FormatDateTime)
+			//	}
+			//	//总共浏览的报表数据需要调整为(浏览晨报数+浏览日评数+每日资讯数)
+			//	list[i].ViewTotal += advisoryView.Total
+			//}
+			////如果存在邮箱号用户每日资讯,那么需要做处理
+			//if advisoryView, ok := userAdvisoryViewEmailTotalMap[item.Email]; ok {
+			//	//对每日资讯数据做校验,每日资讯时间晚日评报时间,那么将最近一次浏览时间替换
+			//	if advisoryView.CreatedTime.After(list[i].LastViewTime) {
+			//		list[i].LastViewTime = advisoryView.CreatedTime
+			//		list[i].LastViewTimeStr = advisoryView.CreatedTime.Format(utils.FormatDateTime)
+			//	}
+			//	//总共浏览的报表数据需要调整为(浏览晨报数+浏览日评数+每日资讯数)
+			//	list[i].ViewTotal += advisoryView.Total
+			//}
+			//
+			////如果存在手机号用户查研观向,那么需要做处理
+			//if cygxView, ok := userCygxArticleHistoryRecordViewMobileTotalMap[item.Mobile]; ok {
+			//	//对每日资讯数据做校验,每日资讯时间晚日评报时间,那么将最近一次浏览时间替换
+			//	if cygxView.CreatedTime.After(list[i].LastViewTime) {
+			//		list[i].LastViewTime = cygxView.CreatedTime
+			//		list[i].LastViewTimeStr = cygxView.CreatedTime.Format(utils.FormatDateTime)
+			//	}
+			//	//总共浏览的报表数据需要调整为(浏览晨报数+浏览日评数+每日资讯数+查研观向)
+			//	list[i].ViewTotal += cygxView.Total
+			//}
+			////如果存在邮箱号用户查研观向,那么需要做处理
+			//if cygxView, ok := userCygxViewEmailTotalMap[item.Email]; ok {
+			//	//对每日资讯数据做校验,每日资讯时间晚日评报时间,那么将最近一次浏览时间替换
+			//	if cygxView.CreatedTime.After(list[i].LastViewTime) {
+			//		list[i].LastViewTime = cygxView.CreatedTime
+			//		list[i].LastViewTimeStr = cygxView.CreatedTime.Format(utils.FormatDateTime)
+			//	}
+			//	//总共浏览的报表数据需要调整为(浏览晨报数+浏览日评数+每日资讯数+查研观向)
+			//	list[i].ViewTotal += cygxView.Total
+			//}
+			///*if reportView, ok := userReportViewTotalMap[int(item.UserId)]; ok {
+			//	//对日评数据做校验,日评时间晚于晨报时间,那么将最近一次浏览时间替换
+			//	if reportView.LastViewTime.After(list[i].LastViewTime) {
+			//		list[i].LastViewTime = reportView.LastViewTime
+			//		list[i].LastViewTimeStr = reportView.LastViewTime.Format(utils.FormatDateTime)
+			//	}
+			//	//总共浏览的报表数据需要调整为(浏览晨报数+浏览日评数)
+			//	list[i].ViewTotal += reportView.ViewTotal
+			//}*/
 
-			//如果存在手机号用户查研观向,那么需要做处理
-			if cygxView, ok := userCygxArticleHistoryRecordViewMobileTotalMap[item.Mobile]; ok {
-				//对每日资讯数据做校验,每日资讯时间晚日评报时间,那么将最近一次浏览时间替换
-				if cygxView.CreatedTime.After(list[i].LastViewTime) {
-					list[i].LastViewTime = cygxView.CreatedTime
-					list[i].LastViewTimeStr = cygxView.CreatedTime.Format(utils.FormatDateTime)
-				}
-				//总共浏览的报表数据需要调整为(浏览晨报数+浏览日评数+每日资讯数+查研观向)
-				list[i].ViewTotal += cygxView.Total
-			}
-			//如果存在邮箱号用户查研观向,那么需要做处理
-			if cygxView, ok := userCygxViewEmailTotalMap[item.Email]; ok {
-				//对每日资讯数据做校验,每日资讯时间晚日评报时间,那么将最近一次浏览时间替换
-				if cygxView.CreatedTime.After(list[i].LastViewTime) {
-					list[i].LastViewTime = cygxView.CreatedTime
-					list[i].LastViewTimeStr = cygxView.CreatedTime.Format(utils.FormatDateTime)
-				}
-				//总共浏览的报表数据需要调整为(浏览晨报数+浏览日评数+每日资讯数+查研观向)
-				list[i].ViewTotal += cygxView.Total
-			}
-			/*if reportView, ok := userReportViewTotalMap[int(item.UserId)]; ok {
-				//对日评数据做校验,日评时间晚于晨报时间,那么将最近一次浏览时间替换
-				if reportView.LastViewTime.After(list[i].LastViewTime) {
-					list[i].LastViewTime = reportView.LastViewTime
-					list[i].LastViewTimeStr = reportView.LastViewTime.Format(utils.FormatDateTime)
-				}
-				//总共浏览的报表数据需要调整为(浏览晨报数+浏览日评数)
-				list[i].ViewTotal += reportView.ViewTotal
-			}*/
+			list[i].ViewTotal = list[i].FiccViewTotal + list[i].RaiViewTotal
 
 			//如果有绑定数据,那么将数据返回对应的注册绑定数据
 			if _, ok := userRecordRegisterMap[int(item.UserId)]; ok {
@@ -2985,11 +2988,11 @@ func (this *CompanyUserController) ViewReportList() {
 	case 1:
 		baseCondition += ` AND source = ? `
 		basePars = append(basePars, 4)
-		total = item.FiccViewTotal
-
+		
+		total = item.RaiViewTotal
 		if lastViewTimeT.IsZero() {
-			if item.FiccLastViewTime != `` && item.FiccLastViewTime != `0000-00-00 00:00:00` {
-				lastViewTimeT, _ = time.ParseInLocation(utils.FormatDateTime, item.FiccLastViewTime, time.Local)
+			if item.RaiLastViewTime != `` && item.RaiLastViewTime != `0000-00-00 00:00:00` {
+				lastViewTimeT, _ = time.ParseInLocation(utils.FormatDateTime, item.RaiLastViewTime, time.Local)
 			} else {
 				lastViewTimeT = time.Now()
 			}
@@ -2999,10 +3002,11 @@ func (this *CompanyUserController) ViewReportList() {
 	case 2: // ficc
 		baseCondition += ` AND source in (?,?,?) `
 		basePars = append(basePars, 1, 2, 3)
-		total = item.RaiViewTotal
+		total = item.FiccViewTotal
+
 		if lastViewTimeT.IsZero() {
-			if item.RaiLastViewTime != `` && item.RaiLastViewTime != `0000-00-00 00:00:00` {
-				lastViewTimeT, _ = time.ParseInLocation(utils.FormatDateTime, item.RaiLastViewTime, time.Local)
+			if item.FiccLastViewTime != `` && item.FiccLastViewTime != `0000-00-00 00:00:00` {
+				lastViewTimeT, _ = time.ParseInLocation(utils.FormatDateTime, item.FiccLastViewTime, time.Local)
 			} else {
 				lastViewTimeT = time.Now()
 			}

+ 2 - 0
models/company/company_user.go

@@ -63,6 +63,8 @@ type CompanyUser struct {
 	IsSubscribe              int       `description:"是否关注了微信公众号: 0-未关注; 1-已关注"`
 	IsSubscribeHzyj          int       `description:"是否关注了弘则研究微信公众号: 0-未关注; 1-已关注"`
 	IsSubscribeCygx          int       `description:"是否关注了查研观向微信公众号: 0-未关注; 1-已关注"`
+	FiccViewTotal            int       `description:"ficc报告的阅读次数" json:"-"`
+	RaiViewTotal             int       `description:"权益报告的阅读次数" json:"-"`
 }
 
 type CompanyUserListResp struct {