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
b3390c85
Commit
b3390c85
authored
Jan 19, 2018
by
clone
Committed by
hujun
Mar 01, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
sendMsg
parent
58393c5b
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
126 additions
and
6 deletions
+126
-6
ChatService.php
application/chat/service/ChatService.php
+42
-6
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 @
b3390c85
...
@@ -13,6 +13,8 @@ namespace app\chat\service;
...
@@ -13,6 +13,8 @@ namespace app\chat\service;
use
app\chat\utils\RegisterUtil
;
use
app\chat\utils\RegisterUtil
;
use
app\chat\utils\RPush
;
use
app\chat\utils\RPush
;
use
app\model\Agents
;
use
app\model\Agents
;
use
app\model\ChatMsg
;
use
app\model\ChatMsgExt
;
use
app\model\ChatUser
;
use
app\model\ChatUser
;
use
app\model\Users
;
use
app\model\Users
;
...
@@ -151,6 +153,8 @@ class ChatService
...
@@ -151,6 +153,8 @@ class ChatService
//todo
//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
=
new
RPush
();
//todo 消息接收人必须是数据
$rPush
->
send
(
$target_type
,
$target
,
$type
,
$msg_content
,
$from
,
$accessToken
,
[
$this
,
'saveSendStatus'
]);
$rPush
->
send
(
$target_type
,
$target
,
$type
,
$msg_content
,
$from
,
$accessToken
,
[
$this
,
'saveSendStatus'
]);
//返回消息发送成功
//返回消息发送成功
return
true
;
return
true
;
...
@@ -181,19 +185,51 @@ class ChatService
...
@@ -181,19 +185,51 @@ class ChatService
* @param $msg_content
* @param $msg_content
* @param $from
* @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
//todo
$params
[
"msg_type"
]
=
1
;
//目前只用到了环信的文本消息
$params
[
"msg_type"
]
=
1
;
//目前只用到了环信的文本消息
$params
[
"to_id"
]
=
$target
;
$params
[
"to_id"
]
=
$target
;
$params
[
"from_id"
]
=
$from
;
$params
[
"from_id"
]
=
$from
;
$params
[
"is_group"
]
=
$target_type
==
"users"
?
0
:
1
;
$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
[
"source"
]
=
$source
;
$params
[
"is_user"
]
=
$is_user
;
$params
[
"is_user"
]
=
$is_user
;
$params
[
"created_at"
]
=
date
(
"Y-m-d H:i:s"
,
time
());
$params
[
"created_at"
]
=
date
(
"Y-m-d H:i:s"
,
time
());
$params
[
"updated_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 @
b3390c85
<?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 @
b3390c85
<?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