zqbao 9 hónapja
szülő
commit
a4cfc251fc
2 módosított fájl, 42 hozzáadás és 8 törlés
  1. 2 8
      controllers/user.go
  2. 40 0
      models/user.go

+ 2 - 8
controllers/user.go

@@ -772,7 +772,7 @@ func (this *UserController) PotentialList() {
 	}
 	startSize := utils.StartIndex(currentIndex, pageSize)
 
-	total, err := models.GetPotentialUserCountByConditon(condition, pars)
+	total, err := models.GetPotentialUserCountByConditonV2(condition, pars)
 	if err != nil {
 		br.Msg = "获取失败"
 		br.ErrMsg = "获取失败,Err:" + err.Error()
@@ -788,13 +788,7 @@ func (this *UserController) PotentialList() {
 		br.Data = resp
 		return
 	}
-	userIds, err := models.GetPotentialUserIdsByConditon(condition, pars)
-	if err != nil {
-		br.Msg = "查询用户失败"
-		br.Msg = "查询用户失败,系统错误,Err:" + err.Error()
-		return
-	}
-	userList, err := models.GetPotentialUserListByConditonSort(userIds, sortCondition, startSize, pageSize)
+	userList, err := models.GetPotentialUserIdsByConditonV2(condition, pars, sortCondition, startSize, pageSize)
 	if err != nil {
 		br.Msg = "查询用户失败"
 		br.Msg = "查询用户失败,系统错误,Err:" + err.Error()

+ 40 - 0
models/user.go

@@ -188,6 +188,46 @@ func GetPotentialUserCountByConditon(condition string, pars []interface{}) (coun
 	return
 }
 
+func GetPotentialUserCountByConditonV2(condition string, pars []interface{}) (count int, err error) {
+	sql := `SELECT COUNT(u.user_id) AS count
+	FROM user AS u
+	LEFT JOIN (
+		SELECT user_id, MAX(create_time) AS create_time
+		FROM user_read_record
+		GROUP BY user_id
+	) AS ur
+	ON u.user_id = ur.user_id
+	WHERE 1=1 AND (u.phone IS NOT NULL OR u.email IS NOT NULL) AND u.status=1`
+	if condition != "" {
+		sql += condition
+	}
+	o := orm.NewOrm()
+	err = o.Raw(sql, pars).QueryRow(&count)
+	return
+}
+
+func GetPotentialUserIdsByConditonV2(condition string, pars []interface{}, sortConditon string, startSize, pageSize int) (items []*UserView, err error) {
+	sql := `SELECT DISTINCT u.*, ur.read_cnt, ur.create_time AS last_update_time
+	FROM user AS u
+	LEFT JOIN (
+		SELECT user_id, MAX(create_time) AS create_time, COUNT(user_id) AS read_cnt
+		FROM user_read_record
+		GROUP BY user_id
+	) AS ur
+	ON u.user_id = ur.user_id
+	WHERE 1=1 AND (u.phone IS NOT NULL OR u.email IS NOT NULL) AND u.status=1`
+	if condition != "" {
+		sql += condition
+	}
+	if sortConditon != "" {
+		sql += sortConditon
+	}
+	sql += ` LIMIT ?,? `
+	o := orm.NewOrm()
+	_, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
+	return
+}
+
 func GetPotentialUserIdsByConditon(condition string, pars []interface{}) (userIds []string, err error) {
 	sql := `SELECT DISTINCT u.user_id AS user_id
 	FROM user AS u