|
@@ -1,4 +1,5 @@
|
|
<?php
|
|
<?php
|
|
|
|
+
|
|
namespace App\JsonRpc;
|
|
namespace App\JsonRpc;
|
|
|
|
|
|
use App\Model\ChatFriends;
|
|
use App\Model\ChatFriends;
|
|
@@ -61,7 +62,7 @@ class ChatService implements ChatServiceInterface
|
|
->where('user.id', '<>', $userId)
|
|
->where('user.id', '<>', $userId)
|
|
->where('user.type_id', '<>', '20000')
|
|
->where('user.type_id', '<>', '20000')
|
|
->select('user.*', 'chat_friends.remark as remark', 'chat_friends.id as isfriend')
|
|
->select('user.*', 'chat_friends.remark as remark', 'chat_friends.id as isfriend')
|
|
- // ->select('user.*', 'chat_friends.friend_id')
|
|
|
|
|
|
+ // ->select('user.*', 'chat_friends.friend_id')
|
|
->get();
|
|
->get();
|
|
|
|
|
|
return Result::success($result);
|
|
return Result::success($result);
|
|
@@ -80,8 +81,7 @@ class ChatService implements ChatServiceInterface
|
|
public function addFriend(array $data): array
|
|
public function addFriend(array $data): array
|
|
{
|
|
{
|
|
Db::beginTransaction();
|
|
Db::beginTransaction();
|
|
- try
|
|
|
|
- {
|
|
|
|
|
|
+ try {
|
|
// 检查是否存在相同的记录
|
|
// 检查是否存在相同的记录
|
|
$existingRecord = ChatFriends::where([
|
|
$existingRecord = ChatFriends::where([
|
|
'user_id' => $data['user_id'],
|
|
'user_id' => $data['user_id'],
|
|
@@ -236,7 +236,6 @@ class ChatService implements ChatServiceInterface
|
|
Db::rollBack();
|
|
Db::rollBack();
|
|
throw new \Exception('记录不存在');
|
|
throw new \Exception('记录不存在');
|
|
}
|
|
}
|
|
-
|
|
|
|
} catch (\Throwable $ex) {
|
|
} catch (\Throwable $ex) {
|
|
Db::rollBack();
|
|
Db::rollBack();
|
|
var_dump($ex->getMessage());
|
|
var_dump($ex->getMessage());
|
|
@@ -340,7 +339,8 @@ class ChatService implements ChatServiceInterface
|
|
'receiver_id' => $data['receiver_id'] ?? '',
|
|
'receiver_id' => $data['receiver_id'] ?? '',
|
|
]];
|
|
]];
|
|
ChatRecords::insert($ChatRecordsData);
|
|
ChatRecords::insert($ChatRecordsData);
|
|
- Db::commit();} catch (\Throwable $ex) {
|
|
|
|
|
|
+ Db::commit();
|
|
|
|
+ } catch (\Throwable $ex) {
|
|
Db::rollBack();
|
|
Db::rollBack();
|
|
var_dump($ex->getMessage());
|
|
var_dump($ex->getMessage());
|
|
return Result::error("存储消息失败", 0);
|
|
return Result::error("存储消息失败", 0);
|
|
@@ -355,7 +355,8 @@ class ChatService implements ChatServiceInterface
|
|
*/
|
|
*/
|
|
public function updateFriend(array $data): array
|
|
public function updateFriend(array $data): array
|
|
{
|
|
{
|
|
- $result = ChatFriends::where(['user_id' => $data['user_id'],
|
|
|
|
|
|
+ $result = ChatFriends::where([
|
|
|
|
+ 'user_id' => $data['user_id'],
|
|
'friend_id' => $data['friend_id'],
|
|
'friend_id' => $data['friend_id'],
|
|
'status' => 2,
|
|
'status' => 2,
|
|
])->update(['remark' => $data['remark']]);
|
|
])->update(['remark' => $data['remark']]);
|
|
@@ -375,7 +376,7 @@ class ChatService implements ChatServiceInterface
|
|
$userId = $data['user_id'];
|
|
$userId = $data['user_id'];
|
|
$unreadMessages = ChatRecords::where('user_id', $userId)
|
|
$unreadMessages = ChatRecords::where('user_id', $userId)
|
|
->where('is_read', 0)
|
|
->where('is_read', 0)
|
|
- // ->where('action', 'recieved')
|
|
|
|
|
|
+ // ->where('action', 'recieved')
|
|
->leftJoin('user', 'chat_records.receiver_id', '=', 'user.id')
|
|
->leftJoin('user', 'chat_records.receiver_id', '=', 'user.id')
|
|
->leftJoin('chat_groups', 'chat_records.receiver_id', '=', 'chat_groups.id')
|
|
->leftJoin('chat_groups', 'chat_records.receiver_id', '=', 'chat_groups.id')
|
|
->select(
|
|
->select(
|
|
@@ -394,7 +395,7 @@ class ChatService implements ChatServiceInterface
|
|
// 查询已读消息,并将 num 字段设置为 0
|
|
// 查询已读消息,并将 num 字段设置为 0
|
|
$readMessages = ChatRecords::where('user_id', $userId)
|
|
$readMessages = ChatRecords::where('user_id', $userId)
|
|
->where('is_read', 1)
|
|
->where('is_read', 1)
|
|
- // ->where('action', 'recieved')
|
|
|
|
|
|
+ // ->where('action', 'recieved')
|
|
->leftJoin('user', 'chat_records.receiver_id', '=', 'user.id')
|
|
->leftJoin('user', 'chat_records.receiver_id', '=', 'user.id')
|
|
->leftJoin('chat_groups', 'chat_records.receiver_id', '=', 'chat_groups.id')
|
|
->leftJoin('chat_groups', 'chat_records.receiver_id', '=', 'chat_groups.id')
|
|
->select(
|
|
->select(
|
|
@@ -420,7 +421,6 @@ class ChatService implements ChatServiceInterface
|
|
|
|
|
|
foreach ($readMessages as $message) {
|
|
foreach ($readMessages as $message) {
|
|
if (strlen($message['receiver_id']) === 18) {
|
|
if (strlen($message['receiver_id']) === 18) {
|
|
-
|
|
|
|
} else {
|
|
} else {
|
|
// $allMessages[$message['receiver_id']] = $message->toArray();
|
|
// $allMessages[$message['receiver_id']] = $message->toArray();
|
|
}
|
|
}
|
|
@@ -477,9 +477,9 @@ class ChatService implements ChatServiceInterface
|
|
$result = ChatRecords::where(function ($query) use ($userId, $friendId) {
|
|
$result = ChatRecords::where(function ($query) use ($userId, $friendId) {
|
|
$query->where('user_id', $userId)->where('receiver_id', $friendId);
|
|
$query->where('user_id', $userId)->where('receiver_id', $friendId);
|
|
})
|
|
})
|
|
- // ->orWhere(function ($query) use ($userId, $friendId) {
|
|
|
|
- // $query->where('user_id', $friendId)->where('receiver_id', $userId);
|
|
|
|
- // })
|
|
|
|
|
|
+ // ->orWhere(function ($query) use ($userId, $friendId) {
|
|
|
|
+ // $query->where('user_id', $friendId)->where('receiver_id', $userId);
|
|
|
|
+ // })
|
|
->leftJoin('user as u1', 'chat_records.user_id', '=', 'u1.id')
|
|
->leftJoin('user as u1', 'chat_records.user_id', '=', 'u1.id')
|
|
->leftJoin('user as u2', 'chat_records.receiver_id', '=', 'u2.id')
|
|
->leftJoin('user as u2', 'chat_records.receiver_id', '=', 'u2.id')
|
|
->select('chat_records.*', 'u1.user_name as user_id_name', 'u1.avatar as user_avatar', 'u2.user_name as receiver_id_name', 'u2.avatar as receiver_avatar')
|
|
->select('chat_records.*', 'u1.user_name as user_id_name', 'u1.avatar as user_avatar', 'u2.user_name as receiver_id_name', 'u2.avatar as receiver_avatar')
|
|
@@ -819,9 +819,13 @@ class ChatService implements ChatServiceInterface
|
|
$result = ChatTopic::where($where)
|
|
$result = ChatTopic::where($where)
|
|
->leftJoin('user', 'user.id', '=', 'chat_topics.user_id')
|
|
->leftJoin('user', 'user.id', '=', 'chat_topics.user_id')
|
|
->leftJoin('chat_topics_reply', 'chat_topics.id', '=', 'chat_topics_reply.topic_id')
|
|
->leftJoin('chat_topics_reply', 'chat_topics.id', '=', 'chat_topics_reply.topic_id')
|
|
- ->select('chat_topics.*', 'user.nickname', 'user.avatar', 'user.user_name'
|
|
|
|
- ,
|
|
|
|
- DB::raw('count(chat_topics_reply.id) as num'))
|
|
|
|
|
|
+ ->select(
|
|
|
|
+ 'chat_topics.*',
|
|
|
|
+ 'user.nickname',
|
|
|
|
+ 'user.avatar',
|
|
|
|
+ 'user.user_name',
|
|
|
|
+ DB::raw('count(chat_topics_reply.id) as num')
|
|
|
|
+ )
|
|
->groupBy('chat_topics.id')
|
|
->groupBy('chat_topics.id')
|
|
->orderBy('chat_topics.id', 'desc')
|
|
->orderBy('chat_topics.id', 'desc')
|
|
->paginate($data['page_size'], ['*'], 'page', $data['page'] ?? 1);
|
|
->paginate($data['page_size'], ['*'], 'page', $data['page'] ?? 1);
|
|
@@ -836,10 +840,13 @@ class ChatService implements ChatServiceInterface
|
|
public function addTopic(array $data): array
|
|
public function addTopic(array $data): array
|
|
{
|
|
{
|
|
$chattopic = [];
|
|
$chattopic = [];
|
|
|
|
+ Db::beginTransaction();
|
|
try {
|
|
try {
|
|
$data['created_at'] = date('Y-m-d H:i:s');
|
|
$data['created_at'] = date('Y-m-d H:i:s');
|
|
$data['updated_at'] = date('Y-m-d H:i:s');
|
|
$data['updated_at'] = date('Y-m-d H:i:s');
|
|
$result = ChatTopic::insertGetId($data);
|
|
$result = ChatTopic::insertGetId($data);
|
|
|
|
+ var_dump($result, 'tedst111111111111111111111111111111');
|
|
|
|
+
|
|
if ($result && $data['is_group'] == 1) {
|
|
if ($result && $data['is_group'] == 1) {
|
|
//chat_group
|
|
//chat_group
|
|
$group_id = PublicData::uuid();
|
|
$group_id = PublicData::uuid();
|
|
@@ -866,7 +873,7 @@ class ChatService implements ChatServiceInterface
|
|
} else {
|
|
} else {
|
|
$chattopic = Chattopic::find($result);
|
|
$chattopic = Chattopic::find($result);
|
|
}
|
|
}
|
|
- Db::beginTransaction();
|
|
|
|
|
|
+
|
|
Db::commit();
|
|
Db::commit();
|
|
} catch (\Exception $e) {
|
|
} catch (\Exception $e) {
|
|
Db::rollBack();
|
|
Db::rollBack();
|
|
@@ -949,7 +956,6 @@ class ChatService implements ChatServiceInterface
|
|
->select('chat_topics.*', 'user.nickname', 'user.avatar', 'user.user_name')
|
|
->select('chat_topics.*', 'user.nickname', 'user.avatar', 'user.user_name')
|
|
->first();
|
|
->first();
|
|
return Result::success($result);
|
|
return Result::success($result);
|
|
-
|
|
|
|
}
|
|
}
|
|
public function addReply(array $data): array
|
|
public function addReply(array $data): array
|
|
{
|
|
{
|
|
@@ -1159,5 +1165,4 @@ class ChatService implements ChatServiceInterface
|
|
$result = ChatTopicClass::where(['id' => $data['id']])->first();
|
|
$result = ChatTopicClass::where(['id' => $data['id']])->first();
|
|
return Result::success($result);
|
|
return Result::success($result);
|
|
}
|
|
}
|
|
-
|
|
|
|
}
|
|
}
|