_,err:=r.o.Raw("SELECT c.id AS cid,c.to_account,c.is_session_end, c.last_message,c.last_message_type,c.from_account, c.create_at AS contact_create_at,u.*, IFNULL(m.`count`,0) AS `read` FROM `contact` c LEFT JOIN `user` u ON c.from_account = u.id LEFT JOIN (SELECT to_account,from_account, COUNT(*) as `count` FROM message WHERE `read` = 1 GROUP BY to_account,from_account) m ON m.to_account = c.to_account AND m.from_account = c.from_account WHERE c.to_account = ? AND c.delete = 0 ORDER BY c.create_at DESC",uid).QueryRows(&contactDto)
_,err:=r.o.Raw("SELECT c.id AS cid,c.to_account,c.last_account,c.is_session_end, c.last_message,c.last_message_type,c.from_account, c.create_at AS contact_create_at,u.*, IFNULL(m.`count`,0) AS `read` FROM `contact` c LEFT JOIN `user` u ON c.from_account = u.id LEFT JOIN (SELECT to_account,from_account, COUNT(*) as `count` FROM message WHERE `read` = 1 GROUP BY to_account,from_account) m ON m.to_account = c.to_account AND m.from_account = c.from_account WHERE c.to_account = ? AND c.delete = 0 ORDER BY c.create_at DESC",uid).QueryRows(&contactDto)
iferr!=nil{
logs.Warn("GetContacts get Contacts------------",err)
iferr:=r.o.Raw("SELECT "+addSQL+" AS `count` FROM services_statistical AS s INNER JOIN (SELECT * FROM `user`) AS u ON s.user_account = u.id AND s.service_account = ? AND s.create_at > ? AND s.create_at < ?",request.Cid,startDate.Unix(),endDate.Unix()).QueryRow(&totalModel);err!=nil{
// is not reception?
INReception:="0,1"
ifrequest.IsReception{
INReception="0"
}
iferr:=r.o.Raw("SELECT "+addSQL+" AS `count` FROM services_statistical AS s INNER JOIN (SELECT * FROM `user`) AS u ON s.user_account = u.id AND s.service_account = ? AND s.create_at > ? AND s.create_at < ? AND is_reception IN("+INReception+")",request.Cid,startDate.Unix(),endDate.Unix()).QueryRow(&totalModel);err!=nil{
logs.Warn("GetCustomerServiceList get Customer Service List1------------",err)
ifcounter,err:=r.o.Raw("SELECT s.id, s.user_account, s.service_account,s.create_at, s.transfer_account,s.platform,u.nickname FROM services_statistical AS s INNER JOIN (SELECT * FROM `user` ) AS u ON s.user_account = u.id AND s.service_account = ? AND s.create_at > ? AND s.create_at < ? "+addSQL1+" ORDER BY s.create_at DESC LIMIT ?,?",request.Cid,startDate.Unix(),endDate.Unix(),(request.PageOn-1)*request.PageSize,request.PageSize).Values(¶ms);counter<=0{
ifcounter,err:=r.o.Raw("SELECT s.id, s.user_account, s.service_account,s.create_at,s.is_reception, s.transfer_account,s.platform,u.nickname FROM services_statistical AS s INNER JOIN (SELECT * FROM `user` ) AS u ON s.user_account = u.id AND s.service_account = ? AND s.create_at > ? AND s.create_at < ? AND is_reception IN("+INReception+") "+addSQL1+" ORDER BY s.create_at DESC LIMIT ?,?",request.Cid,startDate.Unix(),endDate.Unix(),(request.PageOn-1)*request.PageSize,request.PageSize).Values(¶ms);counter<=0{
logs.Warn("GetCustomerServiceList get Customer Service List2------------",err)