|
@@ -269,11 +269,11 @@ pageSize 每页数据量
|
|
|
*/
|
|
|
func (this *Customer) GetDeptCustomerList(dept_id, ent_id int, name, alloc, staff_names string, area map[string]interface{}, startTme, endTime int64, pageIndex, pageSize int, sourceType []int, industry string) (count int64, customerList *[]map[string]interface{}) {
|
|
|
customerList = &[]map[string]interface{}{}
|
|
|
- searchSql := ` a.ent_id=? and a.state=1 `
|
|
|
+ searchSql := ` 1=1 `
|
|
|
searchValues := []interface{}{}
|
|
|
searchValues = append(searchValues, dept_id, dept_id, ent_id)
|
|
|
if name != "" { //名字模糊查询
|
|
|
- searchSql += ` and a.name like ? `
|
|
|
+ searchSql += ` and b.name like ? `
|
|
|
searchValues = append(searchValues, "%"+name+"%")
|
|
|
}
|
|
|
if len(area) > 0 {
|
|
@@ -292,33 +292,33 @@ func (this *Customer) GetDeptCustomerList(dept_id, ent_id int, name, alloc, staf
|
|
|
cityValue, citystr := util.GetInForComma(cityStr)
|
|
|
if len(areastr) > 0 {
|
|
|
if len(citystr) > 0 {
|
|
|
- searchSql += fmt.Sprintf(` and ( a.area in (%s) or a.city in (%s))`, areastr, citystr)
|
|
|
+ searchSql += fmt.Sprintf(` and ( b.area in (%s) or b.city in (%s))`, areastr, citystr)
|
|
|
searchValues = append(searchValues, areaValue...)
|
|
|
searchValues = append(searchValues, cityValue...)
|
|
|
} else {
|
|
|
- searchSql += fmt.Sprintf(` and ( a.area in (%s) )`, areastr)
|
|
|
+ searchSql += fmt.Sprintf(` and ( b.area in (%s) )`, areastr)
|
|
|
searchValues = append(searchValues, areaValue...)
|
|
|
}
|
|
|
} else {
|
|
|
if len(citystr) > 0 {
|
|
|
- searchSql += fmt.Sprintf(` and ( a.city in (%s))`, citystr)
|
|
|
+ searchSql += fmt.Sprintf(` and ( b.city in (%s))`, citystr)
|
|
|
searchValues = append(searchValues, cityValue...)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|
|
|
if startTme > 0 { //开始时间查询
|
|
|
- searchSql += ` and a.updatetime >= ? `
|
|
|
+ searchSql += ` and b.updatetime >= ? `
|
|
|
searchValues = append(searchValues, time.Unix(startTme, 0).Format(Date_Full_Layout))
|
|
|
}
|
|
|
if endTime > 0 { //开始时间查询
|
|
|
- searchSql += ` and a.updatetime <= ? `
|
|
|
+ searchSql += ` and b.updatetime <= ? `
|
|
|
searchValues = append(searchValues, time.Unix(endTime, 0).Format(Date_Full_Layout))
|
|
|
}
|
|
|
|
|
|
if industry != "" {
|
|
|
industryValue, industrystr := util.GetInForComma(industry)
|
|
|
- searchSql += fmt.Sprintf(` and ( a.industry in (%s))`, industrystr)
|
|
|
+ searchSql += fmt.Sprintf(` and ( b.industry in (%s))`, industrystr)
|
|
|
searchValues = append(searchValues, industryValue...)
|
|
|
}
|
|
|
allocSql := ``
|
|
@@ -335,109 +335,73 @@ func (this *Customer) GetDeptCustomerList(dept_id, ent_id int, name, alloc, staf
|
|
|
}
|
|
|
}
|
|
|
searchValues = append(searchValues, (pageIndex-1)*pageSize, pageSize)
|
|
|
- log.Println(`SELECT GROUP_CONCAT(c.name) as staff_names,a.industry,a.createtime,a.name as customer_name,a.id as customer_id,
|
|
|
- (SELECT b.time FROM entniche_project ep INNER JOIN entniche_project_track b ON ep.id = b.project_id WHERE ep.customer_id = a.id ORDER BY b.time desc LIMIT 0,1 ) AS updatetime from
|
|
|
- (select a.name,a.id,a.createtime,a.area,a.industry FROM entniche_customer a
|
|
|
- INNER JOIN (SELECT
|
|
|
- id
|
|
|
+ customersql = `SELECT
|
|
|
+ GROUP_CONCAT( c.NAME ) AS staff_names,
|
|
|
+ b.createtime,
|
|
|
+ b.area,
|
|
|
+ b.industry,
|
|
|
+ b.NAME AS customer_name,
|
|
|
+ b.id AS customer_id,
|
|
|
+ ( SELECT b.time FROM entniche_project_track b WHERE b.customer_id = a.customer_id ORDER BY b.time DESC LIMIT 0, 1 ) AS updatetime
|
|
|
FROM
|
|
|
- (
|
|
|
- SELECT
|
|
|
- t1.id,
|
|
|
- t1.NAME,
|
|
|
- IF( find_in_set( pid, @pids ) > 0, @pids := concat( @pids, ",", id ), 0 ) AS ischild
|
|
|
- FROM(
|
|
|
- SELECT id, pid, NAME
|
|
|
- FROM
|
|
|
- entniche_department t
|
|
|
- ORDER BY pid, id ) t1,
|
|
|
- (SELECT @pids := ?) t2 ) t3
|
|
|
- where ischild != 0
|
|
|
- or id=?
|
|
|
- ) b on (a.dept_id=b.id)
|
|
|
- WHERE `+searchSql+` order by updatetime desc limit 100000) as a
|
|
|
- LEFT JOIN entniche_user_customer b on (a.id=b.customer_id)
|
|
|
- LEFT JOIN entniche_user c on (b.user_id=c.id)
|
|
|
- GROUP BY a.id `+allocSql+` order by updatetime desc, a.createtime desc limit ?,?`, searchValues)
|
|
|
- customersql = `SELECT GROUP_CONCAT(c.name) as staff_names,a.industry,a.createtime,a.name as customer_name,a.id as customer_id,
|
|
|
- (SELECT b.time FROM entniche_project ep INNER JOIN entniche_project_track b ON ep.id = b.project_id WHERE ep.customer_id = a.id ORDER BY b.time desc LIMIT 0,1 ) AS updatetime from
|
|
|
- (select a.name,a.id,a.createtime,a.area,a.industry FROM entniche_customer a
|
|
|
- INNER JOIN (SELECT
|
|
|
- id
|
|
|
- FROM
|
|
|
- (
|
|
|
- SELECT
|
|
|
- t1.id,
|
|
|
- t1.NAME,
|
|
|
- IF( find_in_set( pid, @pids ) > 0, @pids := concat( @pids, ",", id ), 0 ) AS ischild
|
|
|
- FROM(
|
|
|
- SELECT id, pid, NAME
|
|
|
- FROM
|
|
|
- entniche_department t
|
|
|
- ORDER BY pid, id ) t1,
|
|
|
- (SELECT @pids := ?) t2 ) t3
|
|
|
- where ischild != 0
|
|
|
- or id=?
|
|
|
- ) b on (a.dept_id=b.id)
|
|
|
- WHERE ` + searchSql + ` order by updatetime desc limit 100000) as a
|
|
|
- LEFT JOIN entniche_user_customer b on (a.id=b.customer_id)
|
|
|
- LEFT JOIN entniche_user c on (b.user_id=c.id)
|
|
|
- GROUP BY a.id ` + allocSql + ` order by updatetime desc, a.createtime desc`
|
|
|
+ (
|
|
|
+ SELECT
|
|
|
+ a.customer_id,
|
|
|
+ a.user_id
|
|
|
+ FROM
|
|
|
+ entniche_user_customer a
|
|
|
+ INNER JOIN (
|
|
|
+ SELECT DISTINCT
|
|
|
+ c.id
|
|
|
+ FROM
|
|
|
+ entniche_department_parent a
|
|
|
+ INNER JOIN entniche_department_user b ON (
|
|
|
+ b.dept_id = ?
|
|
|
+ OR ( a.pid = ? AND a.id = b.dept_id ))
|
|
|
+ INNER JOIN entniche_user c ON ( c.ent_id = ? AND b.user_id = c.id )
|
|
|
+ ) b ON ( a.user_id = b.id )
|
|
|
+ limit 100000) as a
|
|
|
+ LEFT JOIN entniche_customer b ON ( a.customer_id = b.id )
|
|
|
+ AND b.ent_id = 14640
|
|
|
+ AND b.state = 1
|
|
|
+ LEFT JOIN entniche_user c ON ( a.user_id = c.id ) WHERE ` + searchSql + `
|
|
|
+ GROUP BY a.customer_id ` + allocSql + ` order by updatetime desc, b.createtime desc `
|
|
|
customerList = util.Mysql.SelectBySql(customersql+` limit ?,?`, searchValues...)
|
|
|
countValue = searchValues[:len(searchValues)-2]
|
|
|
} else {
|
|
|
searchValues = append(searchValues, (pageIndex-1)*pageSize, pageSize)
|
|
|
- log.Println(`SELECT GROUP_CONCAT(c.name) as staff_names,a.industry,a.createtime,a.name as customer_name,a.id as customer_id,
|
|
|
- (SELECT b.time FROM entniche_project_track b WHERE b.customer_id = a.id ORDER BY b.time desc LIMIT 0,1 ) AS updatetime
|
|
|
- from
|
|
|
- (select a.name,a.id,a.createtime,a.area,a.industry FROM entniche_customer a
|
|
|
- INNER JOIN (SELECT
|
|
|
- id
|
|
|
- FROM
|
|
|
- (
|
|
|
- SELECT
|
|
|
- t1.id,
|
|
|
- t1.NAME,
|
|
|
- IF( find_in_set( pid, @pids ) > 0, @pids := concat( @pids, ",", id ), 0 ) AS ischild
|
|
|
- FROM(
|
|
|
- SELECT id, pid, NAME
|
|
|
- FROM
|
|
|
- entniche_department t
|
|
|
- ORDER BY pid, id ) t1,
|
|
|
- (SELECT @pids := ?) t2 ) t3
|
|
|
- where ischild != 0
|
|
|
- or id=?
|
|
|
- ) b on (a.dept_id=b.id)
|
|
|
- WHERE `+searchSql+` order by updatetime desc limit ?,?) as a
|
|
|
- LEFT JOIN entniche_user_customer b on (a.id=b.customer_id)
|
|
|
- LEFT JOIN entniche_user c on (b.user_id=c.id)
|
|
|
- GROUP BY a.id order by updatetime desc, a.createtime desc`, searchValues)
|
|
|
- customersql = `SELECT GROUP_CONCAT(c.name) as staff_names,a.industry,a.createtime,a.name as customer_name,a.id as customer_id,
|
|
|
- (SELECT b.time FROM entniche_project_track b WHERE b.customer_id = a.id ORDER BY b.time desc LIMIT 0,1 ) AS updatetime
|
|
|
- from
|
|
|
- (select a.name,a.id,a.createtime,a.area,a.industry FROM entniche_customer a
|
|
|
- INNER JOIN (SELECT
|
|
|
- id
|
|
|
+ customersql = `SELECT
|
|
|
+ GROUP_CONCAT( c.NAME ) AS staff_names,
|
|
|
+ b.createtime,
|
|
|
+ b.area,
|
|
|
+ b.industry,
|
|
|
+ b.NAME AS customer_name,
|
|
|
+ b.id AS customer_id,
|
|
|
+ ( SELECT b.time FROM entniche_project_track b WHERE b.customer_id = a.customer_id ORDER BY b.time DESC LIMIT 0, 1 ) AS updatetime
|
|
|
FROM
|
|
|
- (
|
|
|
- SELECT
|
|
|
- t1.id,
|
|
|
- t1.NAME,
|
|
|
- IF( find_in_set( pid, @pids ) > 0, @pids := concat( @pids, ",", id ), 0 ) AS ischild
|
|
|
- FROM(
|
|
|
- SELECT id, pid, NAME
|
|
|
- FROM
|
|
|
- entniche_department t
|
|
|
- ORDER BY pid, id ) t1,
|
|
|
- (SELECT @pids := ?) t2 ) t3
|
|
|
- where ischild != 0
|
|
|
- or id=?
|
|
|
- ) b on (a.dept_id=b.id)
|
|
|
- WHERE ` + searchSql + ` order by updatetime desc limit ?,?) as a
|
|
|
- LEFT JOIN entniche_user_customer b on (a.id=b.customer_id)
|
|
|
- LEFT JOIN entniche_user c on (b.user_id=c.id)
|
|
|
- GROUP BY a.id order by updatetime desc, a.createtime desc`
|
|
|
- customerList = util.Mysql.SelectBySql(customersql, searchValues...)
|
|
|
+ (
|
|
|
+ SELECT
|
|
|
+ a.customer_id,
|
|
|
+ a.user_id
|
|
|
+ FROM
|
|
|
+ entniche_user_customer a
|
|
|
+ INNER JOIN (
|
|
|
+ SELECT DISTINCT
|
|
|
+ c.id
|
|
|
+ FROM
|
|
|
+ entniche_department_parent a
|
|
|
+ INNER JOIN entniche_department_user b ON (
|
|
|
+ b.dept_id = ?
|
|
|
+ OR ( a.pid = ? AND a.id = b.dept_id ))
|
|
|
+ INNER JOIN entniche_user c ON ( c.ent_id = ? AND b.user_id = c.id )
|
|
|
+ ) b ON ( a.user_id = b.id ) limit 100000
|
|
|
+ ) as a
|
|
|
+ LEFT JOIN entniche_customer b ON ( a.customer_id = b.id )
|
|
|
+ AND b.ent_id = 14640
|
|
|
+ AND b.state = 1
|
|
|
+ LEFT JOIN entniche_user c ON ( a.user_id = c.id ) WHERE ` + searchSql + `
|
|
|
+ GROUP BY a.customer_id ` + allocSql + ` order by updatetime desc, b.createtime desc `
|
|
|
+ customerList = util.Mysql.SelectBySql(customersql+` limit ?,?`, searchValues...)
|
|
|
countValue = searchValues
|
|
|
}
|
|
|
countSql := `select count(*) from (` + customersql + `) d`
|