Roc 3 years ago
parent
commit
eccedbc6b7
1 changed files with 44 additions and 48 deletions
  1. 44 48
      models/tables/company_user.go

+ 44 - 48
models/tables/company_user.go

@@ -7,10 +7,10 @@ import (
 )
 
 type ViewReportList struct {
-	CompanyName string `description:"公司名称" json:"company_name"`
-	RealName string `description:"用户名称" json:"user_name"`
-	Mobile string `description:"手机号" json:"mobile"`
-	Email string `description:"邮箱" json:"email"`
+	CompanyName        string `description:"公司名称" json:"company_name"`
+	RealName           string `description:"用户名称" json:"user_name"`
+	Mobile             string `description:"手机号" json:"mobile"`
+	Email              string `description:"邮箱" json:"email"`
 	ResearchReportName string `description:"报告标题" json:"report_name"`
 	CreatedTime        string `description:"报告阅读时间" json:"created_time"`
 	ReportType         string `description:"报告类型 'day 晨报'、'week 周报'、'twoweek 双周报'、'month 月报'、'rddp 日度点评'、'cygx 查研观向'、'advisory 每日商品聚焦'" json:"-"`
@@ -242,37 +242,37 @@ func GetViewReportListByEmail2(email string, txtType int) (items []*ViewReportLi
 }
 
 // GetViewReportCount 获取报告列表
-func GetViewReportList(mobile,email,startDate,endDate string, startSize, pageSize int) (total int,items []*ViewReportList, err error) {
+func GetViewReportList(mobile, email, startDate, endDate string, startSize, pageSize int) (total int, items []*ViewReportList, err error) {
 	dataName := ""
 	sql := ``
 
-	var sql1,sql2,sql3 string
+	var sql1, sql2, sql3 string
 	var pars []interface{}
-	if mobile != "" && email !=""{
-		sql1 = ` and ( uvh.mobile = ? or uvh.email = ? ) `
-		sql2 = ` and ( rvr.mobile = ? or rvr.email = ? `
-		sql3 = ` and ( auc.mobile = ? or auc.email = ? `
-		pars = append(pars,mobile,email,mobile,email,mobile,email)
-	}else if mobile != ""{
-		sql1 = ` and ( uvh.mobile = ? ) `
-		sql2 = ` and ( rvr.mobile = ? ) `
-		sql3 = ` and ( auc.mobile = ? ) `
-		pars = append(pars,mobile,mobile,mobile)
-	}else if email != ""{
-		sql1 = ` and ( uvh.email = ? ) `
-		sql2 = ` and ( rvr.email = ? ) `
-		sql3 = ` and ( auc.email = ? ) `
-		pars = append(pars,email,email,email)
+	if mobile != "" && email != "" {
+		sql1 += ` and ( uvh.mobile = ? or uvh.email = ? ) `
+		sql2 += ` and ( rvr.mobile = ? or rvr.email = ? `
+		sql3 += ` and ( auc.mobile = ? or auc.email = ? `
+		pars = append(pars, mobile, email, mobile, email, mobile, email)
+	} else if mobile != "" {
+		sql1 += ` and ( uvh.mobile = ? ) `
+		sql2 += ` and ( rvr.mobile = ? ) `
+		sql3 += ` and ( auc.mobile = ? ) `
+		pars = append(pars, mobile, mobile, mobile)
+	} else if email != "" {
+		sql1 += ` and ( uvh.email = ? ) `
+		sql2 += ` and ( rvr.email = ? ) `
+		sql3 += ` and ( auc.email = ? ) `
+		pars = append(pars, email, email, email)
 	}
 
 	//时间筛选
-	if startDate != ""&& endDate !=""{
-		sql1 = ` and uvh.created_time >= ? and uvh.created_time <= ?  `
-		pars = append(pars,startDate,endDate)
-		sql2 = ` and rvr.create_time >= ? and rvr.create_time <= ?  `
-		pars = append(pars,startDate,endDate)
-		sql3 = ` and auc.create_time >= ? and auc.create_time <= ?  `
-		pars = append(pars,startDate,endDate)
+	if startDate != "" && endDate != "" {
+		sql1 += ` and uvh.created_time >= ? and uvh.created_time <= ?  `
+		pars = append(pars, startDate, endDate)
+		sql2 += ` and rvr.create_time >= ? and rvr.create_time <= ?  `
+		pars = append(pars, startDate, endDate)
+		sql3 += ` and auc.create_time >= ? and auc.create_time <= ?  `
+		pars = append(pars, startDate, endDate)
 	}
 
 	if utils.RunMode == "debug" {
@@ -292,7 +292,7 @@ func GetViewReportList(mobile,email,startDate,endDate string, startSize, pageSiz
 	user_view_history uvh
 	LEFT JOIN research_report rr ON rr.research_report_id = uvh.research_report_id
 	WHERE 1=1 
-	`+ sql1 +`
+	` + sql1 + `
 	UNION ALL
 	SELECT
 	r.title AS research_report_name,
@@ -303,7 +303,7 @@ func GetViewReportList(mobile,email,startDate,endDate string, startSize, pageSiz
 		rvr.create_time AS created_time,rvr.mobile,rvr.email,rvr.real_name,rvr.company_name
 	FROM %s.report_view_record rvr
 	LEFT JOIN %s.report r ON r.id = rvr.report_id
-	WHERE 1=1 `+ sql2 +`
+	WHERE 1=1 ` + sql2 + `
 	UNION ALL
 	SELECT
 	cha.permission_name AS research_report_name,
@@ -315,49 +315,47 @@ func GetViewReportList(mobile,email,startDate,endDate string, startSize, pageSiz
 	FROM
 	advisory_user_chart_article_record auc
 	LEFT JOIN chart_permission cha ON cha.chart_permission_id = auc.chart_permission_id
-	WHERE 1=1 `+sql3
-
+	WHERE 1=1 ` + sql3
 
 	sql = ` SELECT * FROM ( ` + ficcSql + ` )AS t ORDER BY t.created_time DESC`
 
-
 	o := orm.NewOrm()
 
 	sql = fmt.Sprintf(sql, dataName, dataName)
 	totalSql := `SELECT count(*) total FROM ( ` + sql + ` )AS z `
 	err = o.Raw(totalSql, pars).QueryRow(&total)
-	if err != nil{
+	if err != nil {
 		return
 	}
 
 	sql += ` limit ?,?`
-	_, err = o.Raw(sql, pars,startSize,pageSize).QueryRows(&items)
+	_, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
 
 	return
 }
 
 // GetViewReportCount 获取报告列表总数
-func GetViewReportCount(mobile,email string) (total int, err error) {
+func GetViewReportCount(mobile, email string) (total int, err error) {
 	dataName := ""
 	sql := ``
 
-	var sql1,sql2,sql3 string
+	var sql1, sql2, sql3 string
 	var pars []interface{}
-	if mobile != "" && email !=""{
+	if mobile != "" && email != "" {
 		sql1 = `uvh.mobile = ? or uvh.email = ? `
 		sql2 = `rvr.mobile = ? or rvr.email = ? `
 		sql3 = `auc.mobile = ? or auc.email = ? `
-		pars = append(pars,mobile,email,mobile,email,mobile,email)
-	}else if mobile != ""{
+		pars = append(pars, mobile, email, mobile, email, mobile, email)
+	} else if mobile != "" {
 		sql1 = `uvh.mobile = ? `
 		sql2 = `rvr.mobile = ? `
 		sql3 = `auc.mobile = ? `
-		pars = append(pars,mobile,mobile,mobile)
-	}else if email != ""{
+		pars = append(pars, mobile, mobile, mobile)
+	} else if email != "" {
 		sql1 = `uvh.email = ? `
 		sql2 = `rvr.email = ? `
 		sql3 = `auc.email = ? `
-		pars = append(pars,email,email,email)
+		pars = append(pars, email, email, email)
 	}
 
 	if utils.RunMode == "debug" {
@@ -377,7 +375,7 @@ func GetViewReportCount(mobile,email string) (total int, err error) {
 	user_view_history uvh
 	LEFT JOIN research_report rr ON rr.research_report_id = uvh.research_report_id
 	WHERE
-	`+ sql1 +`
+	` + sql1 + `
 	UNION ALL
 	SELECT
 	r.title AS research_report_name,
@@ -388,7 +386,7 @@ func GetViewReportCount(mobile,email string) (total int, err error) {
 		rvr.create_time AS created_time
 	FROM %s.report_view_record rvr
 	LEFT JOIN %s.report r ON r.id = rvr.report_id
-	WHERE `+ sql2 +`
+	WHERE ` + sql2 + `
 	UNION ALL
 	SELECT
 	cha.permission_name AS research_report_name,
@@ -400,13 +398,11 @@ func GetViewReportCount(mobile,email string) (total int, err error) {
 	FROM
 	advisory_user_chart_article_record auc
 	LEFT JOIN chart_permission cha ON cha.chart_permission_id = auc.chart_permission_id
-	WHERE `+sql3
-
+	WHERE ` + sql3
 
 	sql = ` SELECT count(*) total FROM ( ` + ficcSql + `
 	      )AS t ORDER BY t.created_time DESC`
 
-
 	o := orm.NewOrm()
 
 	sql = fmt.Sprintf(sql, dataName, dataName)