|
@@ -269,7 +269,7 @@ 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 != "" { //名字模糊查询
|
|
@@ -335,45 +335,72 @@ func (this *Customer) GetDeptCustomerList(dept_id, ent_id int, name, alloc, staf
|
|
|
}
|
|
|
}
|
|
|
searchValues = append(searchValues, (pageIndex-1)*pageSize, pageSize)
|
|
|
- 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 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.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`
|
|
|
+ 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
|
|
|
+ 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 )
|
|
|
+ WHERE ` + searchSql + ` 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 )
|
|
|
+ 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)
|
|
|
- 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 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.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`
|
|
|
+ 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
|
|
|
+ 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 )
|
|
|
+ WHERE ` + searchSql + ` 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 )
|
|
|
+ GROUP BY a.customer_id ` + allocSql + ` order by updatetime desc, b.createtime desc`
|
|
|
customerList = util.Mysql.SelectBySql(customersql, searchValues...)
|
|
|
countValue = searchValues
|
|
|
}
|