zwxi 1 year ago
parent
commit
2ca4a9495b
2 changed files with 10 additions and 6 deletions
  1. 4 4
      logic/sandbox/sandbox.go
  2. 6 2
      models/tables/sandbox/query.go

+ 4 - 4
logic/sandbox/sandbox.go

@@ -24,23 +24,23 @@ func GetList(chartPermissionId int, companyPermissionIdList []int, keyword strin
 	var condition string
 	var pars []interface{}
 
-	condition = ` is_delete = ? `
+	condition = ` s.is_delete = ? `
 	pars = append(pars, 0)
 
 	// 客户拥有的品种权限
 	if len(companyPermissionIdList) > 0 {
-		condition += " AND chart_permission_id in (?) "
+		condition += " AND c.chart_permission_id in (?) "
 		pars = append(pars, companyPermissionIdList)
 	}
 
 	if chartPermissionId > 0 {
-		condition += " AND chart_permission_id=? "
+		condition += " AND c.chart_permission_id=? "
 		pars = append(pars, chartPermissionId)
 	}
 
 	if keyword != "" {
 		//condition += ` AND  ( name LIKE '%` + keyword + `%'  OR  chart_permission_name LIKE '%` + keyword + `%' )`
-		condition += ` AND  ( name LIKE '%` + keyword + `%' )`
+		condition += ` AND  ( s.name LIKE '%` + keyword + `%' )`
 	}
 
 	//获取指标信息

+ 6 - 2
models/tables/sandbox/query.go

@@ -13,13 +13,17 @@ func GetBySandboxId(id uint32) (item *Sandbox, err error) {
 // GetPageListByWhere 分页获取活动列表
 func GetPageListByWhere(condition string, pars []interface{}, startSize, pageSize int) (total int64, list []*Sandbox, err error) {
 	// 获取查询总数量
-	err = global.MYSQL["data"].Model(Sandbox{}).Where(condition, pars...).Count(&total).Error
+	sql := "select count(1) from sandbox AS s JOIN sandbox_classify AS c ON c.sandbox_classify_id = s.sandbox_classify_id WHERE " + condition + " order by s.modify_time desc,s.sandbox_id desc"
+	err = global.MYSQL["data"].Raw(sql, pars...).Scan(&total).Error
 	if err != nil {
 		return
 	}
 
 	// 获取列表数据
-	err = global.MYSQL["data"].Model(Sandbox{}).Where(condition, pars...).Order("modify_time desc,sandbox_id desc").Offset(startSize).Limit(pageSize).Find(&list).Error
+	sql = "select s.* from sandbox AS s JOIN sandbox_classify AS c ON c.sandbox_classify_id = s.sandbox_classify_id WHERE " + condition + " order by s.modify_time desc,s.sandbox_id desc"
+	sql += " limit ?,? "
+	pars = append(pars, startSize, pageSize)
+	err = global.MYSQL["data"].Raw(sql, pars...).Find(&list).Error
 	return
 }