Browse Source

获取总数

xyxie 3 tháng trước cách đây
mục cha
commit
46e958d9e6
1 tập tin đã thay đổi với 3 bổ sung2 xóa
  1. 3 2
      models/chart_collect/chart.go

+ 3 - 2
models/chart_collect/chart.go

@@ -123,14 +123,15 @@ func GetChartCollectDetailByCondition(condition string, pars []interface{}) (ite
 
 func GetChartCollectCountByCondition(condition string, pars []interface{}) (total int64, err error) {
 	o := orm.NewOrm()
-	sql := `SELECT 	count(*) AS num FROM chart_collect AS a INNER JOIN chart_info AS b ON a.chart_info_id=b.chart_info_id
+	sql := `SELECT 	a.chart_info_id FROM chart_collect AS a INNER JOIN chart_info AS b ON a.chart_info_id=b.chart_info_id
 			WHERE 1=1 
 			`
 	if condition != "" {
 		sql += condition
 	}
 	sql += ` GROUP BY a.chart_info_id`
-	err = o.Raw(sql, pars).QueryRow(&total)
+	totalSql := `select count(1) as total from (` + sql + `) as t`
+	err = o.Raw(totalSql, pars).QueryRow(&total)
 	return
 }