123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567 |
- package entity
- import (
- "database/sql"
- "errors"
- "fmt"
- "log"
- "strings"
- "time"
- "app.yhyue.com/moapp/jybase/api"
- qutil "app.yhyue.com/moapp/jybase/common"
- . "app.yhyue.com/moapp/jybase/date"
- "app.yhyue.com/moapp/jybase/encrypt"
- util "app.yhyue.com/moapp/jypkg/ent/util"
- )
- var VarCustomer = &Customer{}
- type Customer struct {
- Id int
- Name string //客户名字
- Industry string //行业
- Area string //地区
- Address string //详细地址
- Remarks int //备注
- }
- /*
- *获取企业已分配人员
- */
- func (this *Customer) GetDistributeUser(entId int, customerId string) []int {
- res := util.Mysql.Find(util.Entniche_user_customer, api.M{"customer_id": customerId}, "user_id", "", -1, -1)
- userids := []int{}
- if res != nil {
- for _, user := range *res {
- userids = append(userids, qutil.IntAll(user["user_id"]))
- }
- }
- return userids
- }
- /*
- 清除客户的分配人员
- customerId:客户id
- users:管辖下的客户列表
- excludeUserId:不清除的用户列表
- */
- func (this *Customer) ClearDistributeUser(tx *sql.Tx, customerId string, users []*User, excludeUserId []string) bool {
- uIds := []string{}
- for _, v := range users {
- has := false //排除本次分配的中仍分配的
- for _, vv := range excludeUserId {
- if fmt.Sprint(v.Id) == vv {
- has = true
- break
- }
- }
- if !has {
- uIds = append(uIds, fmt.Sprintf("%d", v.Id))
- }
- }
- if len(uIds) == 0 {
- return true
- }
- value, str := util.GetInForComma(strings.Join(uIds, ","))
- log.Println(`delete from entniche_user_customer where customer_id = ? and user_id in (` + str + `)`)
- if util.Mysql.UpdateOrDeleteBySqlByTx(tx, `delete from entniche_user_customer where customer_id = ? and user_id in (`+str+`)`, append([]interface{}{customerId}, value...)...) > -1 {
- return true
- }
- return false
- }
- /*
- 新增分配人员
- customerId:客户id
- userIds:分配的用户数组
- */
- var distribute_fields = []string{"customer_id", "user_id", "type", "timestamp", "source_type", "source"}
- func (this *Customer) AddDeptDistributeUsers(tx *sql.Tx, customerId string, userIds []string, userName string, personalNumb int64) (bool, error) {
- if len(userIds) == 0 {
- return true, nil
- }
- //删除新增分配中已分配的用户
- value, str := util.GetInForComma(strings.Join(userIds, ","))
- res := util.Mysql.SelectBySqlByTx(tx, `SELECT user_id FROM entniche_user_customer WHERE customer_id=? and user_id in(`+str+`)`, append([]interface{}{customerId}, value...)...)
- addUserid := []string{}
- if res != nil && len(*res) != 0 { //添加的用户中含有已分配的
- for _, id := range userIds {
- has := false
- for _, v := range *res {
- if id == fmt.Sprint(v["user_id"]) {
- has = true
- break
- }
- }
- if !has {
- addUserid = append(addUserid, id)
- }
- }
- if len(addUserid) == 0 {
- return true, nil
- }
- } else {
- addUserid = userIds
- }
- //插入新增的分配
- timestamp := time.Now().Format(Date_Full_Layout)
- values := []interface{}{}
- for i := 0; i < len(addUserid); i++ {
- //获取个人客户数
- count := util.Mysql.Count("entniche_user_customer", api.M{"user_id": addUserid[i]})
- //判断个人客户数
- if count >= personalNumb {
- //判断企业客户数
- return false, errors.New("客户数量超限")
- }
- values = append(values, customerId, addUserid[i], 2, timestamp, 3, 3)
- }
- count, _ := util.Mysql.InsertBatchByTx(tx, util.Entniche_user_customer, distribute_fields, values)
- if count == qutil.Int64All(len(addUserid)) {
- return true, nil
- }
- return false, errors.New(fmt.Sprintf("分配出错:目标%d人,完成%d人", len(addUserid), count))
- }
- /*
- 获取企业客户列表
- ent_id 企业id
- alloc 是否分配 1分配 2未分配
- area 地区
- startTme 查询开始时间
- endTime 查询结束时间
- pageIndex 页码
- pageSize 每页数据量
- */
- func (this *Customer) GetEntCustomerList(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 `
- searchValues := []interface{}{}
- searchValues = append(searchValues, ent_id)
- if name != "" { //名字模糊查询
- searchSql += ` and a.name like ? `
- searchValues = append(searchValues, "%"+name+"%")
- }
- if len(area) > 0 {
- areaStr := ""
- cityStr := ""
- for k, v := range area {
- if len(qutil.ObjArrToStringArr(v.([]interface{}))) == 0 {
- areaStr += `,` + k
- } else {
- for _, v := range qutil.ObjArrToStringArr(v.([]interface{})) {
- cityStr += `,` + qutil.ObjToString(v)
- }
- }
- }
- areaValue, areastr := util.GetInForComma(areaStr)
- 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)
- searchValues = append(searchValues, areaValue...)
- searchValues = append(searchValues, cityValue...)
- } else {
- searchSql += fmt.Sprintf(` and ( a.area in (%s) )`, areastr)
- searchValues = append(searchValues, areaValue...)
- }
- } else {
- if len(citystr) > 0 {
- searchSql += fmt.Sprintf(` and ( a.city in (%s))`, citystr)
- searchValues = append(searchValues, cityValue...)
- }
- }
- }
- if startTme > 0 { //开始时间查询
- searchSql += ` and a.updatetime >= ? `
- searchValues = append(searchValues, time.Unix(startTme, 0).Format(Date_Full_Layout))
- }
- if endTime > 0 { //开始时间查询
- searchSql += ` and a.updatetime <= ? `
- searchValues = append(searchValues, time.Unix(endTime, 0).Format(Date_Full_Layout))
- }
- if industry != "" {
- /*searchSql += ` and a.industry = ? `
- searchValues = append(searchValues, industry)*/
- if industry != "" {
- industryValue, industrystr := util.GetInForComma(industry)
- searchSql += fmt.Sprintf(` and ( a.industry in (%s))`, industrystr)
- searchValues = append(searchValues, industryValue...)
- }
- }
- allocSql := ``
- customersql := ""
- countValue := []interface{}{}
- if alloc == "1" || alloc == "2" {
- if alloc == "2" { //是否分配查询
- allocSql += ` HAVING staff_names IS NULL `
- } else if alloc == "1" {
- if staff_names != "" {
- //_, _ := GetInForComma(staff_names)
- allocSql += fmt.Sprintf(` HAVING FIND_IN_SET (%s,staff_names) `, `"`+staff_names+`"`)
- } else {
- allocSql += `HAVING staff_names IS NOT NULL `
- }
- }
- 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.industry FROM entniche_customer a
- LEFT JOIN entniche_department_parent 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_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.industry FROM entniche_customer a
- LEFT JOIN entniche_department_parent 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`
- 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 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.industry FROM entniche_customer a
- LEFT JOIN entniche_department_parent 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 `+allocSql+` 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.industry FROM entniche_customer a
- LEFT JOIN entniche_department_parent 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 ` + allocSql + ` order by updatetime desc, a.createtime desc`
- customerList = util.Mysql.SelectBySql(customersql, searchValues...)
- countValue = searchValues
- }
- countSql := `select count(*) from (` + customersql + `) d`
- count = util.Mysql.CountBySql(countSql, countValue...)
- if count > 500 {
- count = 500
- }
- return
- }
- /*
- 获取部门客户列表
- dept_id 部门id
- alloc 是否分配 1分配 2未分配
- area 地区
- startTme 查询开始时间
- endTime 查询结束时间
- pageIndex 页码
- 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 := ` 1=1 `
- searchValues := []interface{}{}
- searchValues = append(searchValues, dept_id, dept_id, ent_id)
- if name != "" { //名字模糊查询
- searchSql += ` and b.name like ? `
- searchValues = append(searchValues, "%"+name+"%")
- }
- if len(area) > 0 {
- areaStr := ""
- cityStr := ""
- for k, v := range area {
- if len(qutil.ObjArrToStringArr(v.([]interface{}))) == 0 {
- areaStr += `,` + k
- } else {
- for _, v := range qutil.ObjArrToStringArr(v.([]interface{})) {
- cityStr += `,` + qutil.ObjToString(v)
- }
- }
- }
- areaValue, areastr := util.GetInForComma(areaStr)
- cityValue, citystr := util.GetInForComma(cityStr)
- if len(areastr) > 0 {
- if len(citystr) > 0 {
- 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 ( b.area in (%s) )`, areastr)
- searchValues = append(searchValues, areaValue...)
- }
- } else {
- if len(citystr) > 0 {
- searchSql += fmt.Sprintf(` and ( b.city in (%s))`, citystr)
- searchValues = append(searchValues, cityValue...)
- }
- }
- }
- if startTme > 0 { //开始时间查询
- searchSql += ` and b.updatetime >= ? `
- searchValues = append(searchValues, time.Unix(startTme, 0).Format(Date_Full_Layout))
- }
- if endTime > 0 { //开始时间查询
- 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 ( b.industry in (%s))`, industrystr)
- searchValues = append(searchValues, industryValue...)
- }
- allocSql := ``
- customersql := ""
- countValue := []interface{}{}
- if alloc == "1" || alloc == "2" {
- if alloc == "2" { //是否分配查询
- allocSql += ` HAVING staff_names IS NULL `
- } else if alloc == "1" {
- if staff_names != "" {
- allocSql += fmt.Sprintf(` HAVING FIND_IN_SET (%s,staff_names) `, `"`+staff_names+`"`)
- } else {
- allocSql += `HAVING staff_names IS NOT NULL `
- }
- }
- searchValues = append(searchValues, (pageIndex-1)*pageSize, pageSize)
- 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 )
- 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)
- 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 ) 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`
- count = util.Mysql.CountBySql(countSql, countValue...)
- if count > 500 {
- count = 500
- }
- return
- }
- /*
- 获取员工客户列表
- user_id 员工id
- area 地区
- startTme 查询开始时间
- endTime 查询结束时间
- pageIndex 页码
- pageSize 每页数据量
- */
- func (this *Customer) GetStaffCustomerList(user_id, ent_id int, name string, area map[string]interface{}, startTme, endTime int64, pageIndex, pageSize int, sourceType []int, followStatus []int, industry, label, userId string) (count int64, customerList *[]map[string]interface{}) {
- customerList = &[]map[string]interface{}{}
- searchValues := []interface{}{}
- searchSql := ` and a.ent_id=? and b.user_id=? and a.state=1`
- searchValues = append(searchValues, ent_id, user_id)
- if len(area) > 0 {
- areaStr := ""
- cityStr := ""
- for k, v := range area {
- if len(qutil.ObjArrToStringArr(v.([]interface{}))) == 0 {
- areaStr += `,` + k
- } else {
- for _, v := range qutil.ObjArrToStringArr(v.([]interface{})) {
- cityStr += `,` + qutil.ObjToString(v)
- }
- }
- }
- areaValue, areastr := util.GetInForComma(areaStr)
- 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)
- searchValues = append(searchValues, areaValue...)
- searchValues = append(searchValues, cityValue...)
- } else {
- searchSql += fmt.Sprintf(` and a.area in (%s) `, areastr)
- searchValues = append(searchValues, areaValue...)
- }
- } else {
- if len(citystr) > 0 {
- searchSql += fmt.Sprintf(` and a.city in (%s)`, citystr)
- searchValues = append(searchValues, cityValue...)
- }
- }
- }
- if label != "" { //标签查询
- searchSql += " and("
- value, _ := util.GetInForComma(label)
- for key, v := range value {
- if key == 0 {
- searchSql += fmt.Sprintf(` FIND_IN_SET(%s,d.labelid) `, encrypt.SE.DecodeString(qutil.ObjToString(v)))
- } else {
- searchSql += fmt.Sprintf(` or FIND_IN_SET(%s,d.labelid) `, encrypt.SE.DecodeString(qutil.ObjToString(v)))
- }
- }
- searchSql += " ) "
- searchSql += ` and d.userid=? `
- searchValues = append(searchValues, userId)
- }
- if sourceType != nil && len(sourceType) > 0 && sourceType[0] != 999 { //来源类型:0订阅分配、1认领、2自主添加、3别人划转
- sourceStr := []string{}
- for i := 0; i < len(sourceType); i++ {
- sourceStr = append(sourceStr, "?")
- searchValues = append(searchValues, sourceType[i])
- }
- searchSql += fmt.Sprintf(` and b.source in (%s)`, strings.Join(sourceStr, ","))
- }
- if industry != "" {
- /*searchSql += ` and a.industry = ? `
- searchValues = append(searchValues, industry)*/
- if industry != "" {
- industryValue, industrystr := util.GetInForComma(industry)
- searchSql += fmt.Sprintf(` and ( a.industry in (%s))`, industrystr)
- searchValues = append(searchValues, industryValue...)
- }
- }
- if name != "" { //名字模糊查询
- searchSql += ` and a.name like ? `
- searchValues = append(searchValues, "%"+name+"%")
- }
- timeSql := ``
- if followStatus != nil && len(followStatus) > 0 && followStatus[0] != 999 { //跟踪状态;1-成单,2-继续跟踪,3-跟踪失败 4取消跟踪
- statusStr := []string{}
- for i := 0; i < len(followStatus); i++ {
- statusStr = append(statusStr, "?")
- searchValues = append(searchValues, followStatus[i])
- }
- timeSql += fmt.Sprintf(` having status IN (%s) `, strings.Join(statusStr, ","))
- }
- if startTme > 0 { //开始时间查询
- if timeSql == `` {
- timeSql += ` HAVING updatetime >= ? `
- } else {
- timeSql += ` and updatetime >= ? `
- }
- searchValues = append(searchValues, time.Unix(startTme, 0).Format(Date_Full_Layout))
- }
- if endTime > 0 { //截止时间查询
- if timeSql == `` {
- timeSql += ` HAVING updatetime <= ? `
- } else {
- timeSql += ` and updatetime <= ? `
- }
- searchValues = append(searchValues, time.Unix(endTime, 0).Format(Date_Full_Layout))
- }
- searchValues = append(searchValues, (pageIndex-1)*pageSize, pageSize)
- log.Println(`SELECT a.id as customer_id,a.name as customer_name,a.industry,c.name as staff_names,a.createtime,
- (SELECT e.STATUS FROM entniche_project_track e WHERE e.customer_id = a.id and e.user_id= b.user_id ORDER BY e.time desc LIMIT 0,1 ) AS status,
- (SELECT e.time FROM entniche_project_track e WHERE e.customer_id = a.id and e.user_id= b.user_id ORDER BY e.time desc LIMIT 0,1 ) AS updatetime
- FROM entniche_customer a
- LEFT JOIN bdcollection_entniche d on (d.customer_id = a.id and d.userid="`+userId+`")
- LEFT JOIN entniche_user_customer b on ( a.id=b.customer_id)
- LEFT JOIN entniche_user c on (c.id = b.user_id)
- Where 1=1 `+searchSql+timeSql+`
- order by updatetime desc , a.createtime desc limit ?,?`, searchValues)
- customersql := `SELECT a.id as customer_id,a.industry,a.name as customer_name,c.name as staff_names,a.createtime,
- (SELECT e.STATUS FROM entniche_project_track e WHERE e.customer_id = a.id and e.user_id= b.user_id ORDER BY e.time desc LIMIT 0,1 ) AS status,
- (SELECT e.time FROM entniche_project_track e WHERE e.customer_id = a.id and e.user_id= b.user_id ORDER BY e.time desc LIMIT 0,1 ) AS updatetime
- FROM entniche_customer a
- LEFT JOIN bdcollection_entniche d on (d.customer_id = a.id and d.userid="` + userId + `")
- LEFT JOIN entniche_user_customer b on ( a.id=b.customer_id)
- LEFT JOIN entniche_user c on (c.id = b.user_id)
- Where 1=1 ` + searchSql + timeSql + `
- order by updatetime desc ,a.createtime desc `
- countValue := searchValues[:len(searchValues)-2]
- customerList = util.Mysql.SelectBySql(customersql+` limit ?,?`, searchValues...)
- countSql := `select count(*) from (` + customersql + `) d`
- count = util.Mysql.CountBySql(countSql, countValue...)
- if count > 500 {
- count = 500
- }
- return
- }
- func (this *Customer) GetCustomerNumb(user_id int, personalNumb int64) (data map[string]interface{}) {
- customerNumbList := util.Mysql.SelectBySql(`SELECT
- count(if(source="1",true,null)) as claimed,
- count(if(source="2",true,null)) as autonomousAddition,
- count(if(source="3",true,null)) as distribution,
- count(if(source="4",true,null)) as subscribe
- FROM
- entniche_user_customer
- WHERE
- user_id = ?`, user_id)
- (*customerNumbList)[0]["count"] = personalNumb
- data = (*customerNumbList)[0]
- return
- }
- func (this *Customer) GetExist(cIds, userIds string) *[]map[string]interface{} {
- q := "select group_concat(c.name separator'、') as customer_name,b.name from entniche_user_customer a ,entniche_user b,entniche_customer c where a.user_id in ( %s ) and a.customer_id in (%s) and a.user_id = b.id and c.id=a.customer_id group by b.id"
- return util.Mysql.SelectBySql(fmt.Sprintf(q, userIds, cIds))
- }
|