|
@@ -161,6 +161,9 @@ func (b MessaggeService) UserList(in *messagecenter.UserReq) (data *[]map[string
|
|
|
if in.EndTime != "" {
|
|
|
endTimeSql = "AND DATE_FORMAT(c.create_time,'%Y-%m-%d') <= '" + in.EndTime + "' "
|
|
|
}
|
|
|
+ if in.Page <= 0 {
|
|
|
+ in.Page = 1
|
|
|
+ }
|
|
|
userSql := fmt.Sprintf("SELECT MAX( c.id ) as messageId FROM %s c "+
|
|
|
"LEFT JOIN %s d ON c.own_type=1 AND c.own_id=d.id "+
|
|
|
"LEFT JOIN %s b ON if (c.send_user_type=1 ,c.receive_user_id,c.send_user_id)=b.id "+
|
|
@@ -171,44 +174,35 @@ func (b MessaggeService) UserList(in *messagecenter.UserReq) (data *[]map[string
|
|
|
"GROUP BY ( CASE WHEN c.send_user_type =2 THEN CONCAT( c.send_user_id ) WHEN c.send_user_type =1 THEN CONCAT( c.receive_user_id ) END ) ",
|
|
|
util.SOCIALIZE_MESSAGE_MAILBOX, util.SOCIALIZE_CHAT_SESSION, util.BASE_USER,
|
|
|
in.EntUserId, startTimeSql, endTimeSql, phoneSql)
|
|
|
- countData := util.Mysql.SelectBySql(userSql)
|
|
|
- var d []map[string]interface{}
|
|
|
- if countData != nil && len(*countData) > 0 {
|
|
|
- util.SortData(countData, "messageId", true)
|
|
|
- count = quitl.Int64All(len(*countData))
|
|
|
- if in.Page <= 0 {
|
|
|
- in.Page = 1
|
|
|
- }
|
|
|
- if in.Page*in.Size >= count {
|
|
|
- d = (*countData)[(in.Page-1)*in.Size:]
|
|
|
- } else {
|
|
|
- d = (*countData)[(in.Page-1)*in.Size : in.Page*in.Size]
|
|
|
+ log.Println("查询最新消息数量sql:", userSql)
|
|
|
+ count = util.Mysql.CountBySql(userSql)
|
|
|
+ if count > 0 {
|
|
|
+ countData := util.Mysql.SelectBySql(fmt.Sprintf("SELECT * FROM (%s) as data order by messageId desc LIMIT %d,%d", userSql, in.Page-1, in.Size))
|
|
|
+ if countData != nil && len(*countData) > 0 {
|
|
|
+ customerMessageId := util.Inhandle(countData)
|
|
|
+ //客服的用户列表
|
|
|
+ sqlStr = fmt.Sprintf("SELECT "+
|
|
|
+ "( CASE WHEN SUBSTR( b.nickname, 1, 3 ) = 'JY_' THEN CONCAT( SUBSTR( b.phone, 1, 3 ), '****', SUBSTR( b.phone, 8, 11 ) ) WHEN b.nickname = '' THEN CONCAT( SUBSTR( b.phone, 1, 3 ), '****', SUBSTR( b.phone, 8, 11 ) ) ELSE b.nickname END )"+
|
|
|
+ " AS name, b.id, e.title, b.headimg, e.type, e.link, e.content, a.create_time, "+
|
|
|
+ "( SELECT count( h.id ) FROM %s h "+
|
|
|
+ "LEFT JOIN %s i ON h.own_type = 1 AND h.own_id = i.id "+
|
|
|
+ "WHERE h.own_type = 1 "+
|
|
|
+ "AND i.ent_id=f.ent_id "+
|
|
|
+ "AND i.user_id=f.user_id "+
|
|
|
+ "AND h.isread = 0 "+
|
|
|
+ "AND i.customer_service_id= %d) AS number "+
|
|
|
+ "FROM %s a "+
|
|
|
+ "LEFT JOIN %s b ON if (a.send_user_type=1 ,a.receive_user_id,a.send_user_id)=b.id "+
|
|
|
+ "LEFT JOIN %s e ON e.id = a.messag_id "+
|
|
|
+ "LEFT JOIN %s f ON a.own_type=1 AND a.own_id=f.id "+
|
|
|
+ "WHERE a.id IN ( %s) %s ORDER BY a.create_time DESC",
|
|
|
+ util.SOCIALIZE_MESSAGE_MAILBOX, util.SOCIALIZE_CHAT_SESSION,
|
|
|
+ in.EntUserId, util.SOCIALIZE_MESSAGE_MAILBOX, util.BASE_USER, util.SOCIALIZE_MESSAGE, util.SOCIALIZE_CHAT_SESSION, customerMessageId, phoneSql)
|
|
|
}
|
|
|
}
|
|
|
- if len(d) > 0 {
|
|
|
- customerMessageId := util.InFmt(d)
|
|
|
- //客服的用户列表
|
|
|
- sqlStr = fmt.Sprintf("SELECT "+
|
|
|
- "( CASE WHEN SUBSTR( b.nickname, 1, 3 ) = 'JY_' THEN CONCAT( SUBSTR( b.phone, 1, 3 ), '****', SUBSTR( b.phone, 8, 11 ) ) WHEN b.nickname = '' THEN CONCAT( SUBSTR( b.phone, 1, 3 ), '****', SUBSTR( b.phone, 8, 11 ) ) ELSE b.nickname END )"+
|
|
|
- " AS name, b.id, e.title, b.headimg, e.type, e.link, e.content, a.create_time, "+
|
|
|
- "( SELECT count( h.id ) FROM %s h "+
|
|
|
- "LEFT JOIN %s i ON h.own_type = 1 AND h.own_id = i.id "+
|
|
|
- "WHERE h.own_type = 1 "+
|
|
|
- "AND i.ent_id=f.ent_id "+
|
|
|
- "AND i.user_id=f.user_id "+
|
|
|
- "AND h.isread = 0 "+
|
|
|
- "AND i.customer_service_id= %d) AS number "+
|
|
|
- "FROM %s a "+
|
|
|
- "LEFT JOIN %s b ON if (a.send_user_type=1 ,a.receive_user_id,a.send_user_id)=b.id "+
|
|
|
- "LEFT JOIN %s e ON e.id = a.messag_id "+
|
|
|
- "LEFT JOIN %s f ON a.own_type=1 AND a.own_id=f.id "+
|
|
|
- "WHERE a.id IN ( %s) %s ORDER BY a.create_time DESC",
|
|
|
- util.SOCIALIZE_MESSAGE_MAILBOX, util.SOCIALIZE_CHAT_SESSION,
|
|
|
- in.EntUserId, util.SOCIALIZE_MESSAGE_MAILBOX, util.BASE_USER, util.SOCIALIZE_MESSAGE, util.SOCIALIZE_CHAT_SESSION, customerMessageId, phoneSql)
|
|
|
- }
|
|
|
}
|
|
|
if sqlStr != "" {
|
|
|
- log.Println(sqlStr)
|
|
|
+ log.Println("查询列表sql:", sqlStr)
|
|
|
data = util.Mysql.SelectBySql(sqlStr)
|
|
|
if in.UserType == 2 && data != nil && len(*data) > 0 {
|
|
|
count = quitl.Int64All(len(*data))
|