Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
T
tl_estate
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
hujun
tl_estate
Commits
4e639277
Commit
4e639277
authored
Jul 16, 2018
by
clone
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
未读消息个数
parent
406215a5
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
68 additions
and
3 deletions
+68
-3
AppChat.php
application/chat/controller/AppChat.php
+21
-2
ChatService.php
application/chat/service/ChatService.php
+19
-1
ChatMsg.php
application/model/ChatMsg.php
+28
-0
No files found.
application/chat/controller/AppChat.php
View file @
4e639277
...
...
@@ -23,6 +23,7 @@ use app\model\HouseImgs;
use
app\model\HouseinfoExts
;
use
app\model\HouseInfos
;
use
think\Cache
;
use
think\Exception
;
use
Think\Log
;
class
AppChat
extends
Basic
...
...
@@ -323,13 +324,31 @@ class AppChat extends Basic
$params
=
$this
->
params
;
/* $params = array(
"target" => "agent_5739",
"is_user"=> 0,//0用户1经纪人
"is_user" => 0,//0用户1经纪人
"relation_list" => '[ { "r_id" : 12, "msg_id" : 111}, { "r_id" : 11, "msg_id" : 111}]',
);*/
if
(
!
isset
(
$params
[
'target'
])
||
!
isset
(
$params
[
"is_user"
]))
{
return
$this
->
response
(
"300"
,
"参数不全"
);
}
$target
=
$params
[
"target"
];
$relationList
=
$this
->
_chat
->
getRelationList
(
$target
,
$params
[
"is_user"
]);
$is_user
=
$params
[
"is_user"
];
$relation_list
=
null
;
if
(
!
empty
(
$params
[
"relation_list"
]))
{
try
{
$relation_
=
json_decode
(
$params
[
"relation_list"
],
true
);
dump
(
$relation_
);
foreach
(
$relation_
as
$item
){
$relation_list
[
$item
[
"r_id"
]][]
=
$item
;
}
}
catch
(
Exception
$exception
)
{
return
$this
->
response
(
"101"
,
"解析关系异常:"
.
$exception
);
}
}
dump
(
$relation_list
);
$relationList
=
$this
->
_chat
->
getRelationList
(
$target
,
$is_user
,
$relation_list
);
return
$this
->
response
(
"200"
,
"success"
,
$relationList
);
...
...
application/chat/service/ChatService.php
View file @
4e639277
...
...
@@ -21,6 +21,7 @@ use app\model\ChatRelation;
use
app\model\ChatUser
;
use
app\model\ChatUserExt
;
use
app\model\Users
;
use
think\Exception
;
class
ChatService
{
...
...
@@ -381,12 +382,13 @@ class ChatService
/**获取聊天列表
* @param $target
* @param $is_user
* @param $relation_list
* @return array
* * @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public
function
getRelationList
(
$target
,
$is_user
)
public
function
getRelationList
(
$target
,
$is_user
,
$relation_list
)
{
$chatRelationModel
=
new
ChatRelation
();
$params
[
"target"
]
=
$target
;
...
...
@@ -420,6 +422,21 @@ class ChatService
$select_
[
"from"
]
=
$item
[
"from_id"
];
$select_
[
"target"
]
=
$item
[
"to_id"
];
$chat_info
=
$msgModel
->
getChatHistory
(
$select_
,
$fields
,
1
,
1
);
if
(
!
empty
(
$relation_list
))
{
$where_
=
$select_
;
try
{
$where_
[
"id"
]
=
array
(
"between"
,
array
(
$relation_list
[
$item
[
"id"
]][
0
][
"msg_id"
],
$chat_info
[
0
][
"id"
]
)
);
//计算未读消息个数
$unread_count
=
$msgModel
->
getTotalUnread
(
$where_
,
"id"
);
$result
[
$key
][
"unread"
]
=
$unread_count
;
}
catch
(
Exception
$exception
)
{
$result
[
$key
][
"unread"
]
=
0
;
}
}
if
(
count
(
$chat_info
)
>
0
)
{
$result
[
$key
][
"chat_info"
]
=
$chat_info
[
0
];
}
else
{
...
...
@@ -430,6 +447,7 @@ class ChatService
return
$this
->
sortByTime
(
array_values
(
$result
));
}
private
function
sortByTime
(
$result
)
{
for
(
$i
=
0
;
$i
<
count
(
$result
);
$i
++
)
{
...
...
application/model/ChatMsg.php
View file @
4e639277
...
...
@@ -78,4 +78,31 @@ class ChatMsg extends Model
return
$data
;
}
public
function
getTotalUnread
(
$params
,
$field
){
if
(
isset
(
$params
[
"from"
]))
{
$where_
[
"a.from_id"
]
=
$params
[
"from"
];
$where_or
[
"a.to_id"
]
=
$params
[
"from"
];
}
if
(
isset
(
$params
[
"target"
]))
{
$where_
[
"a.to_id"
]
=
$params
[
"target"
];
$where_or
[
"a.from_id"
]
=
$params
[
"target"
];
}
if
(
isset
(
$params
[
"id"
]))
{
$where_
[
"a.id"
]
=
$params
[
"id"
];
}
$where_
[
"a.is_del"
]
=
0
;
$data
=
$this
->
db
->
field
(
$field
)
->
alias
(
"a"
)
->
join
(
'chat_msg_ext b'
,
'a.id = b.msg_id'
,
'LEFT'
)
->
where
(
$where_
)
->
whereOr
(
function
(
$query
)
use
(
$where_or
)
{
$query
->
where
(
$where_or
);
})
->
order
(
"a.created_at desc"
)
->
count
();
return
$data
;
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment