浏览代码

商家列表查询新增分类权限字段

xyxie 1 月之前
父节点
当前提交
20570793e3
共有 2 个文件被更改,包括 32 次插入13 次删除
  1. 21 9
      controllers/eta_business/eta_business.go
  2. 11 4
      models/eta_business/eta_business.go

+ 21 - 9
controllers/eta_business/eta_business.go

@@ -33,6 +33,7 @@ type EtaBusinessController struct {
 // @Param   IndustryId		query	int	false	"行业ID"
 // @Param   SortParam		query	int	false	"排序字段: 1-签约时间; 2-到期时间; 3-创建时间; 4-用户上限"
 // @Param   SortType		query	int	false	"排序类型: 1-正序; 2-倒序"
+// @Param   chartClassifyIds		query	string	false	"分类id,用逗号分隔"
 // @Success 200 Ret=200 获取成功
 // @router /page_list [get]
 func (this *EtaBusinessController) PageList() {
@@ -90,7 +91,7 @@ func (this *EtaBusinessController) PageList() {
 		keyword = strings.TrimSpace(keyword)
 		if keyword != "" {
 			kw := fmt.Sprint("%", keyword, "%")
-			cond += fmt.Sprintf(` AND (%s LIKE ? OR %s LIKE ? OR %s LIKE ?)`, eta_business.EtaBusinessColumns.BusinessName, eta_business.EtaBusinessColumns.BusinessCode, eta_business.EtaBusinessColumns.CreditCode)
+			cond += fmt.Sprintf(` AND (e.%s LIKE ? OR e.%s LIKE ? OR e.%s LIKE ?)`, eta_business.EtaBusinessColumns.BusinessName, eta_business.EtaBusinessColumns.BusinessCode, eta_business.EtaBusinessColumns.CreditCode)
 			pars = append(pars, kw, kw, kw)
 		}
 
@@ -115,14 +116,14 @@ func (this *EtaBusinessController) PageList() {
 				br.Msg = "获取成功"
 				return
 			}
-			cond += fmt.Sprintf(` AND %s IN (%s)`, eta_business.EtaBusinessColumns.SellerId, utils.GetOrmInReplace(len(ids)))
+			cond += fmt.Sprintf(` AND e.%s IN (%s)`, eta_business.EtaBusinessColumns.SellerId, utils.GetOrmInReplace(len(ids)))
 			pars = append(pars, ids)
 		}
 
 		// 签约状态
 		signingStatus, _ := this.GetInt("SigningStatus", 0)
 		if signingStatus > 0 {
-			cond += fmt.Sprintf(` AND %s = ?`, eta_business.EtaBusinessColumns.SigningStatus)
+			cond += fmt.Sprintf(` AND e.%s = ?`, eta_business.EtaBusinessColumns.SigningStatus)
 			pars = append(pars, signingStatus)
 		}
 
@@ -139,7 +140,7 @@ func (this *EtaBusinessController) PageList() {
 				br.Msg = "获取成功"
 				return
 			}
-			cond += fmt.Sprintf(` AND %s IN (%s)`, eta_business.EtaBusinessColumns.Province, utils.GetOrmInReplace(len(provinceArr)))
+			cond += fmt.Sprintf(` AND e.%s IN (%s)`, eta_business.EtaBusinessColumns.Province, utils.GetOrmInReplace(len(provinceArr)))
 			pars = append(pars, provinceArr)
 		}
 		city := this.GetString("City", "")
@@ -154,14 +155,14 @@ func (this *EtaBusinessController) PageList() {
 				br.Msg = "获取成功"
 				return
 			}
-			cond += fmt.Sprintf(` AND %s IN (%s)`, eta_business.EtaBusinessColumns.City, utils.GetOrmInReplace(len(cityArr)))
+			cond += fmt.Sprintf(` AND e.%s IN (%s)`, eta_business.EtaBusinessColumns.City, utils.GetOrmInReplace(len(cityArr)))
 			pars = append(pars, cityArr)
 		}
 
 		// 行业
 		industryId, _ := this.GetInt("IndustryId", 0)
 		if industryId > 0 {
-			cond += fmt.Sprintf(` AND %s = ?`, eta_business.EtaBusinessColumns.IndustryId)
+			cond += fmt.Sprintf(` AND e.%s = ?`, eta_business.EtaBusinessColumns.IndustryId)
 			pars = append(pars, industryId)
 		}
 
@@ -169,9 +170,20 @@ func (this *EtaBusinessController) PageList() {
 		nation := this.GetString("Nation", "")
 		nation = strings.TrimSpace(nation)
 		if nation != "" {
-			cond += ` AND nation = ? `
+			cond += ` AND e.nation = ? `
 			pars = append(pars, nation)
 		}
+
+		// 分类id
+		chartClassifyIds := this.GetString("ChartClassifyIds", "")
+		chartClassifyIds = strings.TrimSpace(chartClassifyIds)
+		if chartClassifyIds != "" {
+			chartClassifyIdsArr := strings.Split(chartClassifyIds, ",")
+			if len(chartClassifyIdsArr) > 0 {
+				cond += fmt.Sprintf(` AND p.chart_classify_id IN (%s)`, utils.GetOrmInReplace(len(chartClassifyIdsArr)))
+				pars = append(pars, chartClassifyIdsArr)
+			}
+		}
 	}
 
 	order := ``
@@ -200,13 +212,13 @@ func (this *EtaBusinessController) PageList() {
 
 	// 获取列表
 	businessOb := new(eta_business.EtaBusiness)
-	total, e := businessOb.GetCountByCondition(cond, pars)
+	total, e := businessOb.GetWithChartClassifyCountByCondition(cond, pars)
 	if e != nil {
 		br.Msg = "获取失败"
 		br.ErrMsg = "获取商家总数失败, Err: " + e.Error()
 		return
 	}
-	list, e := businessOb.GetPageItemsByCondition(cond, pars, []string{}, order, startSize, pageSize)
+	list, e := businessOb.GetPageItemsWithChartClassifyByCondition(cond, pars, []string{}, order, startSize, pageSize)
 	if e != nil {
 		br.Msg = "获取失败"
 		br.ErrMsg = "获取商家列表失败, Err: " + e.Error()

+ 11 - 4
models/eta_business/eta_business.go

@@ -191,17 +191,24 @@ func (m *EtaBusiness) GetItemsByCondition(condition string, pars []interface{},
 	return
 }
 
-func (m *EtaBusiness) GetPageItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string, startSize, pageSize int) (items []*EtaBusiness, err error) {
+func (m *EtaBusiness) GetWithChartClassifyCountByCondition(condition string, pars []interface{}) (count int, err error) {
+	o := orm.NewOrm()
+	sql := fmt.Sprintf(`SELECT COUNT(1) FROM %s as e left join business_chart_classify_permission as p on e.eta_business_id = p.eta_business_id WHERE 1=1 %s`, m.TableName(), condition)
+	err = o.Raw(sql, pars).QueryRow(&count)
+	return
+}
+
+func (m *EtaBusiness) GetPageItemsWithChartClassifyByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string, startSize, pageSize int) (items []*EtaBusiness, err error) {
 	o := orm.NewOrm()
 	fields := strings.Join(fieldArr, ",")
 	if len(fieldArr) == 0 {
-		fields = `*`
+		fields = `e.*`
 	}
-	order := `ORDER BY create_time DESC`
+	order := `ORDER BY e.create_time DESC`
 	if orderRule != "" {
 		order = ` ORDER BY ` + orderRule
 	}
-	sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s LIMIT ?,?`, fields, m.TableName(), condition, order)
+	sql := fmt.Sprintf(`SELECT %s FROM %s as e left join business_chart_classify_permission as p on e.eta_business_id = p.eta_business_id WHERE 1=1 %s %s LIMIT ?,?`, fields, m.TableName(), condition, order)
 	_, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
 	return
 }