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
ccab486e
Commit
ccab486e
authored
Jan 19, 2018
by
clone
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
sendMsg
parent
8cf2aff0
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
130 additions
and
9 deletions
+130
-9
ChatService.php
application/chat/service/ChatService.php
+46
-9
ChatMsg.php
application/model/ChatMsg.php
+42
-0
ChatMsgExt.php
application/model/ChatMsgExt.php
+42
-0
No files found.
application/chat/service/ChatService.php
View file @
ccab486e
...
...
@@ -13,6 +13,8 @@ namespace app\chat\service;
use
app\chat\utils\RegisterUtil
;
use
app\chat\utils\RPush
;
use
app\model\Agents
;
use
app\model\ChatMsg
;
use
app\model\ChatMsgExt
;
use
app\model\ChatUser
;
use
app\model\Users
;
...
...
@@ -133,12 +135,15 @@ class ChatService
* @param $accessToken
* @return bool
*/
public
function
sendMsg
(
$target_type
,
$target
,
$source
,
$is_user
,
$type
,
$msg_content
,
$from
,
$accessToken
)
public
function
sendMsg
(
$target_type
,
$target
,
$source
,
$is_user
,
$type
,
$msg_content
,
$from
,
$accessToken
)
{
//todo
$this
->
insertMsg
(
$target_type
,
$target
,
$source
,
$is_user
,
$type
,
$msg_content
,
$from
);
$this
->
insertMsg
(
$target_type
,
$target
,
$source
,
$is_user
,
$type
,
$msg_content
,
$from
);
$rPush
=
new
RPush
();
$rPush
->
send
(
$target_type
,
$target
,
$type
,
$msg_content
,
$from
,
$accessToken
,
[
$this
,
'saveSendStatus'
]);
//todo 消息接收人必须是数据
$rPush
->
send
(
$target_type
,
[
$target
],
$type
,
$msg_content
,
$from
,
$accessToken
,
[
$this
,
'saveSendStatus'
]);
//返回消息发送成功
return
true
;
}
...
...
@@ -168,19 +173,51 @@ class ChatService
* @param $msg_content
* @param $from
*/
private
function
insertMsg
(
$target_type
,
$target
,
$source
,
$is_user
,
$type
,
$msg_content
,
$from
)
private
function
insertMsg
(
$target_type
,
$target
,
$source
,
$is_user
,
$type
,
$msg_content
,
$from
)
{
//todo
$params
[
"msg_type"
]
=
1
;
//目前只用到了环信的文本消息
$params
[
"to_id"
]
=
$target
;
$params
[
"from_id"
]
=
$from
;
$params
[
"msg_type"
]
=
1
;
//目前只用到了环信的文本消息
$params
[
"to_id"
]
=
$target
;
$params
[
"from_id"
]
=
$from
;
$params
[
"is_group"
]
=
$target_type
==
"users"
?
0
:
1
;
$params
[
"account_type"
]
=
date
(
"Y-m-d H:i:s"
,
time
())
;
$params
[
"account_type"
]
=
1
;
$params
[
"source"
]
=
$source
;
$params
[
"is_user"
]
=
$is_user
;
$params
[
"created_at"
]
=
date
(
"Y-m-d H:i:s"
,
time
());
$params
[
"updated_at"
]
=
date
(
"Y-m-d H:i:s"
,
time
());
$this
->
chatUserModel
->
addChatUser
(
$params
);
$msgModel
=
new
ChatMsg
();
$id
=
$msgModel
->
addChatMsg
(
$params
);
if
(
$id
>
0
)
{
//todo 插入msg_ext
$group_id
=
0
;
if
(
$target_type
!=
"users"
)
{
$group_id
=
$from
;
}
$this
->
insetMsgExt
(
$id
,
$type
,
$msg_content
,
$params
[
"is_group"
],
$group_id
);
}
}
/**
* 记录消息body
* @param $id
* @param $type
* @param $msg_content
* @param $is_group
* @param $group_id
*/
private
function
insetMsgExt
(
$id
,
$type
,
$msg_content
,
$is_group
,
$group_id
)
{
$params
[
"msg_id"
]
=
$id
;
$params
[
"type"
]
=
$type
;
$params
[
"body"
]
=
$msg_content
;
$params
[
"send_type"
]
=
$is_group
;
$params
[
"group_id"
]
=
$group_id
;
$params
[
"create_at"
]
=
date
(
"Y-m-d H:i:s"
,
time
());
$params
[
"updated_at"
]
=
date
(
"Y-m-d H:i:s"
,
time
());
$msgExtModel
=
new
ChatMsgExt
();
$msgExtModel
->
addChatMsgExt
(
$params
);
}
/** 获取聊天记录
...
...
application/model/ChatMsg.php
0 → 100644
View file @
ccab486e
<?php
/**
* Created by PhpStorm.
* User : zw
* Date : 2018/1/18
* Time : 15:33
* Intro:
*/
namespace
app\model
;
use
think\Model
;
use
think\Db
;
class
ChatMsg
extends
Model
{
// 设置当前模型对应的完整数据表名称
protected
$table
=
'chat_msg'
;
protected
$db
;
public
function
__construct
()
{
$this
->
db
=
Db
(
$this
->
table
);
}
public
function
addChatMsg
(
$params
)
{
Db
::
startTrans
();
try
{
$this
->
save
(
$params
);
$id
=
$this
->
id
;
return
$id
;
Db
::
commit
();
}
catch
(
\Exception
$e
)
{
Db
::
rollback
();
}
return
0
;
}
}
\ No newline at end of file
application/model/ChatMsgExt.php
0 → 100644
View file @
ccab486e
<?php
/**
* Created by PhpStorm.
* User : zw
* Date : 2018/1/18
* Time : 15:33
* Intro:
*/
namespace
app\model
;
use
think\Model
;
use
think\Db
;
class
ChatMsgExt
extends
Model
{
// 设置当前模型对应的完整数据表名称
protected
$table
=
'chat_msg_ext'
;
protected
$db
;
public
function
__construct
()
{
$this
->
db
=
Db
(
$this
->
table
);
}
public
function
addChatMsgExt
(
$params
)
{
Db
::
startTrans
();
try
{
$this
->
save
(
$params
);
$id
=
$this
->
id
;
return
$id
;
Db
::
commit
();
}
catch
(
\Exception
$e
)
{
Db
::
rollback
();
}
return
0
;
}
}
\ 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