feat:兼容开发

main
gzydong 2022-01-17 21:06:27 +08:00
parent 3cea1388fb
commit cdbf6fdc56
21 changed files with 257 additions and 189 deletions

View File

@ -3,7 +3,7 @@
namespace App\Cache; namespace App\Cache;
use App\Cache\Repository\HashRedis; use App\Cache\Repository\HashRedis;
use App\Model\Contact; use App\Model\Contact\Contact;
/** /**
* 好友备注 - 缓存助手 * 好友备注 - 缓存助手

View File

@ -5,7 +5,7 @@ namespace App\Command;
use App\Cache\IpAddressCache; use App\Cache\IpAddressCache;
use App\Constants\RobotConstant; use App\Constants\RobotConstant;
use App\Model\Contact; use App\Model\Contact\Contact;
use App\Repository\ExampleRepository; use App\Repository\ExampleRepository;
use App\Repository\RobotRepository; use App\Repository\RobotRepository;
use App\Service\RobotService; use App\Service\RobotService;

View File

@ -1,11 +1,12 @@
<?php <?php
declare(strict_types=1); declare(strict_types=1);
namespace App\Controller\Api\V1; namespace App\Controller\Api\V1\Talk;
use App\Cache\UnreadTalkCache; use App\Cache\UnreadTalkCache;
use App\Constants\TalkEventConstant; use App\Constants\TalkEventConstant;
use App\Constants\TalkModeConstant; use App\Constants\TalkModeConstant;
use App\Controller\Api\V1\CController;
use App\Event\TalkEvent; use App\Event\TalkEvent;
use App\Model\EmoticonItem; use App\Model\EmoticonItem;
use App\Model\FileSplitUpload; use App\Model\FileSplitUpload;
@ -29,7 +30,7 @@ use Psr\Http\Message\ResponseInterface;
* *
* @package App\Controller\Api\V1 * @package App\Controller\Api\V1
*/ */
class TalkMessageController extends CController class MessageController extends CController
{ {
/** /**
* @Inject * @Inject
@ -75,6 +76,7 @@ class TalkMessageController extends CController
public function code(): ResponseInterface public function code(): ResponseInterface
{ {
$params = $this->request->inputs(['talk_type', 'receiver_id', 'lang', 'code']); $params = $this->request->inputs(['talk_type', 'receiver_id', 'lang', 'code']);
$this->validate($params, [ $this->validate($params, [
'talk_type' => 'required|in:1,2', 'talk_type' => 'required|in:1,2',
'receiver_id' => 'required|integer|min:1', 'receiver_id' => 'required|integer|min:1',
@ -83,6 +85,7 @@ class TalkMessageController extends CController
]); ]);
$user_id = $this->uid(); $user_id = $this->uid();
if (!UserRelation::isFriendOrGroupMember($user_id, (int)$params['receiver_id'], (int)$params['talk_type'])) { if (!UserRelation::isFriendOrGroupMember($user_id, (int)$params['receiver_id'], (int)$params['talk_type'])) {
return $this->response->fail('暂不属于好友关系或群聊成员,无法发送聊天消息!'); return $this->response->fail('暂不属于好友关系或群聊成员,无法发送聊天消息!');
} }
@ -92,9 +95,9 @@ class TalkMessageController extends CController
'user_id' => $user_id, 'user_id' => $user_id,
'receiver_id' => $params['receiver_id'], 'receiver_id' => $params['receiver_id'],
], [ ], [
'user_id' => $user_id, 'user_id' => $user_id,
'code_lang' => $params['lang'], 'lang' => $params['lang'],
'code' => $params['code'] 'code' => $params['code']
]); ]);
if (!$isTrue) return $this->response->fail('消息发送失败!'); if (!$isTrue) return $this->response->fail('消息发送失败!');
@ -110,12 +113,14 @@ class TalkMessageController extends CController
public function image(Filesystem $filesystem): ResponseInterface public function image(Filesystem $filesystem): ResponseInterface
{ {
$params = $this->request->inputs(['talk_type', 'receiver_id']); $params = $this->request->inputs(['talk_type', 'receiver_id']);
$this->validate($params, [ $this->validate($params, [
'talk_type' => 'required|in:1,2', 'talk_type' => 'required|in:1,2',
'receiver_id' => 'required|integer|min:1' 'receiver_id' => 'required|integer|min:1'
]); ]);
$user_id = $this->uid(); $user_id = $this->uid();
if (!UserRelation::isFriendOrGroupMember($user_id, (int)$params['receiver_id'], (int)$params['talk_type'])) { if (!UserRelation::isFriendOrGroupMember($user_id, (int)$params['receiver_id'], (int)$params['talk_type'])) {
return $this->response->fail('暂不属于好友关系或群聊成员,无法发送聊天消息!'); return $this->response->fail('暂不属于好友关系或群聊成员,无法发送聊天消息!');
} }
@ -163,6 +168,7 @@ class TalkMessageController extends CController
public function file(Filesystem $filesystem): ResponseInterface public function file(Filesystem $filesystem): ResponseInterface
{ {
$params = $this->request->inputs(['talk_type', 'receiver_id', 'hash_name']); $params = $this->request->inputs(['talk_type', 'receiver_id', 'hash_name']);
$this->validate($params, [ $this->validate($params, [
'talk_type' => 'required|in:1,2', 'talk_type' => 'required|in:1,2',
'receiver_id' => 'required|integer|min:1', 'receiver_id' => 'required|integer|min:1',
@ -314,11 +320,11 @@ class TalkMessageController extends CController
}; };
if (isset($params['receive_user_ids']) && !empty($params['receive_user_ids'])) { if (isset($params['receive_user_ids']) && !empty($params['receive_user_ids'])) {
$receive_user_ids = $func($params['receive_user_ids'], TalkModeConstant::PRIVATE_CHAT); $receive_user_ids = $func(parse_ids($params['receive_user_ids']), TalkModeConstant::PRIVATE_CHAT);
} }
if (isset($params['receive_group_ids']) && !empty($params['receive_group_ids'])) { if (isset($params['receive_group_ids']) && !empty($params['receive_group_ids'])) {
$receive_group_ids = $func($params['receive_group_ids'], TalkModeConstant::GROUP_CHAT); $receive_group_ids = $func(parse_ids($params['receive_group_ids']), TalkModeConstant::GROUP_CHAT);
} }
// 需要转发的好友或者群组 // 需要转发的好友或者群组
@ -326,7 +332,7 @@ class TalkMessageController extends CController
$method = $params['forward_mode'] == 1 ? "multiSplitForward" : "multiMergeForward"; $method = $params['forward_mode'] == 1 ? "multiSplitForward" : "multiMergeForward";
$ids = $forwardService->{$method}($user_id, (int)$params['receiver_id'], (int)$params['talk_type'], $params['records_ids'], $items); $ids = $forwardService->{$method}($user_id, (int)$params['receiver_id'], (int)$params['talk_type'], parse_ids($params['records_ids']), $items);
if (!$ids) return $this->response->fail('转发失败!'); if (!$ids) return $this->response->fail('转发失败!');
@ -434,6 +440,7 @@ class TalkMessageController extends CController
public function handleVote(): ResponseInterface public function handleVote(): ResponseInterface
{ {
$params = $this->request->inputs(['record_id', 'options']); $params = $this->request->inputs(['record_id', 'options']);
$this->validate($params, [ $this->validate($params, [
'record_id' => 'required|integer|min:1', 'record_id' => 'required|integer|min:1',
'options' => 'required', 'options' => 'required',

View File

@ -0,0 +1,148 @@
<?php
declare(strict_types=1);
namespace App\Controller\Api\V1\Talk;
use App\Constants\TalkMessageType;
use App\Constants\TalkModeConstant;
use App\Controller\Api\V1\CController;
use App\Service\Group\GroupMemberService;
use App\Service\TalkListService;
use App\Service\TalkService;
use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\RequestMapping;
use Hyperf\HttpServer\Annotation\Middleware;
use App\Middleware\JWTAuthMiddleware;
use Psr\Http\Message\ResponseInterface;
/**
* Class RecordController
*
* @Controller(prefix="/api/v1/talk/records")
* @Middleware(JWTAuthMiddleware::class)
*
* @package App\Controller\Api\V1\Talk
*/
class RecordsController extends CController
{
/**
* @Inject
* @var TalkService
*/
public $talkService;
/**
* @Inject
* @var TalkListService
*/
public $talkListService;
/**
* 获取对话面板中的聊天记录
*
* @RequestMapping(path="", methods="get")
*/
public function records(): ResponseInterface
{
$params = $this->request->inputs(['talk_type', 'receiver_id', 'record_id']);
$this->validate($params, [
'talk_type' => 'required|in:1,2',
'receiver_id' => 'required|integer|min:1',
'record_id' => 'required|integer|min:0',
]);
$user_id = $this->uid();
if ($params['talk_type'] == TalkModeConstant::GROUP_CHAT && !di()->get(GroupMemberService::class)->isMember((int)$params['receiver_id'], $user_id)) {
return $this->response->fail('暂不属于好友关系或群聊成员,无法查看聊天记录!');
}
$limit = 30;
$result = $this->talkService->getChatRecords(
$user_id,
intval($params['receiver_id']),
intval($params['talk_type']),
intval($params['record_id']),
$limit
);
return $this->response->success([
'rows' => $result,
'record_id' => $result ? end($result)['id'] : 0,
'limit' => $limit
]);
}
/**
* 查询聊天历史记录
*
* @RequestMapping(path="history", methods="get")
*/
public function history(): ResponseInterface
{
$params = $this->request->inputs(['talk_type', 'receiver_id', 'record_id', 'msg_type']);
$this->validate($params, [
'talk_type' => 'required|in:1,2',
'receiver_id' => 'required|integer|min:1',
'record_id' => 'required|integer|min:0',
'msg_type' => 'required|integer',
]);
$user_id = $this->uid();
if ($params['talk_type'] == TalkModeConstant::GROUP_CHAT && !di()->get(GroupMemberService::class)->isMember((int)$params['receiver_id'], $user_id)) {
return $this->response->fail('暂不属于好友关系或群聊成员,无法查看聊天记录!');
}
$types = [
TalkMessageType::TEXT_MESSAGE,
TalkMessageType::FILE_MESSAGE,
TalkMessageType::FORWARD_MESSAGE,
TalkMessageType::CODE_MESSAGE,
TalkMessageType::VOTE_MESSAGE
];
if (in_array($params['msg_type'], $types)) {
$msg_type = [$params['msg_type']];
} else {
$msg_type = $types;
}
$limit = 30;
$result = $this->talkService->getChatRecords(
$user_id,
(int)$params['receiver_id'],
(int)$params['talk_type'],
(int)$params['record_id'],
$limit,
$msg_type
);
return $this->response->success([
'rows' => $result,
'record_id' => $result ? end($result)['id'] : 0,
'limit' => $limit
]);
}
/**
* 获取转发记录详情
*
* @RequestMapping(path="forward", methods="get")
*/
public function forwards(): ResponseInterface
{
$params = $this->request->inputs(['record_id']);
$this->validate($params, [
'record_id' => 'required|integer|min:1'
]);
$rows = $this->talkService->getForwardRecords($this->uid(), intval($params['record_id']));
return $this->response->success(['rows' => $rows]);
}
}

View File

@ -1,14 +1,18 @@
<?php <?php
declare(strict_types=1);
namespace App\Controller\Api\V1; namespace App\Controller\Api\V1\Talk;
use App\Cache\LastMessage; use App\Cache\LastMessage;
use App\Cache\Repository\LockRedis; use App\Cache\Repository\LockRedis;
use App\Cache\UnreadTalkCache; use App\Cache\UnreadTalkCache;
use App\Constants\TalkMessageType;
use App\Constants\TalkModeConstant; use App\Constants\TalkModeConstant;
use App\Controller\Api\V1\CController;
use App\Model\Group\Group;
use App\Model\Talk\TalkSession; use App\Model\Talk\TalkSession;
use App\Service\Group\GroupMemberService; use App\Model\User;
use App\Service\TalkListService;
use App\Service\TalkService;
use App\Service\UserFriendService; use App\Service\UserFriendService;
use App\Support\UserRelation; use App\Support\UserRelation;
use Hyperf\Di\Annotation\Inject; use Hyperf\Di\Annotation\Inject;
@ -17,10 +21,6 @@ use Hyperf\HttpServer\Annotation\RequestMapping;
use Hyperf\HttpServer\Annotation\Middleware; use Hyperf\HttpServer\Annotation\Middleware;
use App\Middleware\JWTAuthMiddleware; use App\Middleware\JWTAuthMiddleware;
use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ResponseInterface;
use App\Model\User;
use App\Model\Group\Group;
use App\Service\TalkService;
use App\Service\TalkListService;
/** /**
* Class TalkController * Class TalkController
@ -65,6 +65,7 @@ class TalkController extends CController
/** /**
* 新增对话列表 * 新增对话列表
*
* @RequestMapping(path="create", methods="post") * @RequestMapping(path="create", methods="post")
*/ */
public function create(UserFriendService $service): ResponseInterface public function create(UserFriendService $service): ResponseInterface
@ -124,6 +125,7 @@ class TalkController extends CController
/** /**
* 删除对话列表 * 删除对话列表
*
* @RequestMapping(path="delete", methods="post") * @RequestMapping(path="delete", methods="post")
*/ */
public function delete(): ResponseInterface public function delete(): ResponseInterface
@ -140,6 +142,7 @@ class TalkController extends CController
/** /**
* 对话列表置顶 * 对话列表置顶
*
* @RequestMapping(path="topping", methods="post") * @RequestMapping(path="topping", methods="post")
*/ */
public function topping(): ResponseInterface public function topping(): ResponseInterface
@ -157,6 +160,7 @@ class TalkController extends CController
/** /**
* 设置消息免打扰状态 * 设置消息免打扰状态
*
* @RequestMapping(path="disturb", methods="post") * @RequestMapping(path="disturb", methods="post")
*/ */
public function disturb(): ResponseInterface public function disturb(): ResponseInterface
@ -175,7 +179,7 @@ class TalkController extends CController
/** /**
* 更新对话列表未读数 * 更新对话列表未读数
* @RequestMapping(path="update-unread-num", methods="post") * @RequestMapping(path="unread/clear", methods="post")
*/ */
public function updateUnreadNum(): ResponseInterface public function updateUnreadNum(): ResponseInterface
{ {
@ -192,105 +196,4 @@ class TalkController extends CController
return $this->response->success(); return $this->response->success();
} }
/**
* 获取对话面板中的聊天记录
* @RequestMapping(path="records", methods="get")
*/
public function getChatRecords(): ResponseInterface
{
$params = $this->request->inputs(['talk_type', 'receiver_id', 'record_id']);
$this->validate($params, [
'talk_type' => 'required|in:1,2',
'receiver_id' => 'required|integer|min:1',
'record_id' => 'required|integer|min:0',
]);
$user_id = $this->uid();
if ($params['talk_type'] == TalkModeConstant::GROUP_CHAT && !di()->get(GroupMemberService::class)->isMember((int)$params['receiver_id'], $user_id)) {
return $this->response->fail('暂不属于好友关系或群聊成员,无法查看聊天记录!');
}
$limit = 30;
$result = $this->talkService->getChatRecords(
$user_id,
$params['receiver_id'],
$params['talk_type'],
$params['record_id'],
$limit
);
return $this->response->success([
'rows' => $result,
'record_id' => $result ? end($result)['id'] : 0,
'limit' => $limit
]);
}
/**
* 获取转发记录详情
* @RequestMapping(path="get-forward-records", methods="get")
*/
public function getForwardRecords(): ResponseInterface
{
$params = $this->request->inputs(['record_id']);
$this->validate($params, [
'record_id' => 'required|integer|min:1'
]);
$rows = $this->talkService->getForwardRecords($this->uid(), $params['record_id']);
return $this->response->success(['rows' => $rows]);
}
/**
* 查询聊天记录
* @RequestMapping(path="find-chat-records", methods="get")
*/
public function findChatRecords(): ResponseInterface
{
$params = $this->request->inputs(['talk_type', 'receiver_id', 'record_id', 'msg_type']);
$this->validate($params, [
'talk_type' => 'required|in:1,2',
'receiver_id' => 'required|integer|min:1',
'record_id' => 'required|integer|min:0',
'msg_type' => 'required|integer',
]);
$user_id = $this->uid();
if ($params['talk_type'] == TalkModeConstant::GROUP_CHAT && !di()->get(GroupMemberService::class)->isMember((int)$params['receiver_id'], $user_id)) {
return $this->response->fail('暂不属于好友关系或群聊成员,无法查看聊天记录!');
}
$types = [
TalkMessageType::TEXT_MESSAGE,
TalkMessageType::FILE_MESSAGE,
TalkMessageType::FORWARD_MESSAGE,
TalkMessageType::CODE_MESSAGE,
TalkMessageType::VOTE_MESSAGE
];
if (in_array($params['msg_type'], $types)) {
$msg_type = [$params['msg_type']];
} else {
$msg_type = $types;
}
$limit = 30;
$result = $this->talkService->getChatRecords(
$user_id,
$params['receiver_id'],
$params['talk_type'],
$params['record_id'],
$limit,
$msg_type
);
return $this->response->success([
'rows' => $result,
'record_id' => $result ? end($result)['id'] : 0,
'limit' => $limit
]);
}
} }

View File

@ -30,6 +30,7 @@ class Article extends BaseModel
protected $fillable = [ protected $fillable = [
'user_id', 'user_id',
'class_id', 'class_id',
'tags_id',
'title', 'title',
'abstract', 'abstract',
'image', 'image',
@ -37,6 +38,7 @@ class Article extends BaseModel
'status', 'status',
'created_at', 'created_at',
'updated_at', 'updated_at',
'deleted_at',
]; ];
protected $casts = [ protected $casts = [

View File

@ -9,17 +9,19 @@ use App\Model\BaseModel;
/** /**
* 笔记附件数据表模型 * 笔记附件数据表模型
* *
* @property integer $id 笔记附件ID * @property int $id 自增ID
* @property integer $user_id 用户ID * @property int $user_id 用户ID
* @property integer $article_id 笔记ID * @property int $article_id 笔记ID
* @property integer $drive 文件驱动 * @property int $drive 文件驱动
* @property string $file_suffix 文件后缀名 * @property string $suffix 文件后缀名
* @property int $file_size 文件大小 * @property int $size 文件大小
* @property string $path 文件相对路径 * @property string $path 文件地址
* @property string $original_name 文件原名 * @property string $original_name 文件原名
* @property integer $status 文件状态 * @property int $status 文件状态
* @property string $created_at 上传时间 * @property string $created_at 创建时间
* @property string $deleted_at 删除时间 * @property string $updated_at 更新时间
* @property string $deleted_at 删除时间
*
* @package App\Model\Article * @package App\Model\Article
*/ */
class ArticleAnnex extends BaseModel class ArticleAnnex extends BaseModel

View File

@ -15,12 +15,12 @@ use App\Model\BaseModel;
* @property integer $sort 排序[值越小越靠前] * @property integer $sort 排序[值越小越靠前]
* @property integer $is_default 默认分类[1:;0:不是] * @property integer $is_default 默认分类[1:;0:不是]
* @property string $created_at 创建时间 * @property string $created_at 创建时间
* @property string $updated_at 更新时间
*
* @package App\Model\Article * @package App\Model\Article
*/ */
class ArticleClass extends BaseModel class ArticleClass extends BaseModel
{ {
protected $table = 'article_class'; protected $table = 'article_class';
public $timestamps = true; public $timestamps = true;

View File

@ -13,6 +13,7 @@ use App\Model\BaseModel;
* @property integer $article_id 笔记ID * @property integer $article_id 笔记ID
* @property string $md_content 笔记MD格式内容 * @property string $md_content 笔记MD格式内容
* @property string $content 笔记html格式内容 * @property string $content 笔记html格式内容
*
* @package App\Model\Article * @package App\Model\Article
*/ */
class ArticleDetail extends BaseModel class ArticleDetail extends BaseModel

View File

@ -14,6 +14,7 @@ use App\Model\BaseModel;
* @property string $tag_name 标签名称 * @property string $tag_name 标签名称
* @property integer $sort 标签排序 * @property integer $sort 标签排序
* @property integer $created_at 创建时间 * @property integer $created_at 创建时间
* @property integer $updated_at 更新时间
*/ */
class ArticleTag extends BaseModel class ArticleTag extends BaseModel
{ {

View File

@ -2,9 +2,9 @@
declare (strict_types=1); declare (strict_types=1);
namespace App\Model; namespace App\Model\Contact;
use App\Cache\FriendRemark; use App\Model\BaseModel;
/** /**
* 表情包收藏数据表模型 * 表情包收藏数据表模型

View File

@ -2,7 +2,9 @@
declare (strict_types=1); declare (strict_types=1);
namespace App\Model; namespace App\Model\Contact;
use App\Model\BaseModel;
/** /**
* 好友添加申请数据表模型 * 好友添加申请数据表模型
@ -23,7 +25,6 @@ class ContactApply extends BaseModel
'friend_id', 'friend_id',
'remark', 'remark',
'created_at', 'created_at',
'updated_at'
]; ];
protected $casts = [ protected $casts = [

View File

@ -19,6 +19,7 @@ use App\Model\BaseModel;
* @property integer $is_dismiss 是否已解散[0:;1:;] * @property integer $is_dismiss 是否已解散[0:;1:;]
* @property string $created_at 创建时间 * @property string $created_at 创建时间
* @property string $dismissed_at 解散时间 * @property string $dismissed_at 解散时间
*
* @package App\Model\Group * @package App\Model\Group
*/ */
class Group extends BaseModel class Group extends BaseModel

View File

@ -12,7 +12,7 @@ use App\Model\BaseModel;
* @property int $id 代码块ID * @property int $id 代码块ID
* @property int $record_id 聊天记录ID * @property int $record_id 聊天记录ID
* @property int $user_id 用户ID * @property int $user_id 用户ID
* @property string $code_lang 代码语言 * @property string $lang 代码语言
* @property string $code 代码详情 * @property string $code 代码详情
* @property string $created_at 创建时间 * @property string $created_at 创建时间
* @package App\Model\Chat * @package App\Model\Chat
@ -24,7 +24,7 @@ class TalkRecordsCode extends BaseModel
protected $fillable = [ protected $fillable = [
'record_id', 'record_id',
'user_id', 'user_id',
'code_lang', 'lang',
'code', 'code',
'created_at' 'created_at'
]; ];

View File

@ -12,14 +12,13 @@ use App\Model\BaseModel;
* @property int $id 文件消息ID * @property int $id 文件消息ID
* @property int $record_id 聊天记录ID * @property int $record_id 聊天记录ID
* @property int $user_id 用户ID * @property int $user_id 用户ID
* @property int $file_source 文件上传来源 * @property int $source 文件上传来源
* @property int $file_type 文件类型 * @property int $type 文件类型
* @property int $save_type 文件保存类型 * @property int $drive 文件保存类型
* @property string $original_name 文件原始名称 * @property string $original_name 文件原始名称
* @property string $file_suffix 文件后缀名 * @property string $suffix 文件后缀名
* @property int $file_size 文件大小 * @property int $size 文件大小
* @property string $save_dir 文件保存路径 * @property string $path 文件保存路径
* @property int $is_delete 是否已删除
* @property string $created_at 上传时间 * @property string $created_at 上传时间
* @package App\Model\Chat * @package App\Model\Chat
*/ */
@ -30,25 +29,23 @@ class TalkRecordsFile extends BaseModel
protected $fillable = [ protected $fillable = [
'record_id', 'record_id',
'user_id', 'user_id',
'file_source', 'source',
'file_type', 'type',
'save_type', 'drive',
'original_name', 'original_name',
'file_suffix', 'suffix',
'file_size', 'size',
'save_dir', 'path',
'is_delete',
'created_at' 'created_at'
]; ];
protected $casts = [ protected $casts = [
'record_id' => 'integer', 'record_id' => 'integer',
'user_id' => 'integer', 'user_id' => 'integer',
'file_source' => 'integer', 'source' => 'integer',
'file_type' => 'integer', 'type' => 'integer',
'save_type' => 'integer', 'drive' => 'integer',
'file_size' => 'integer', 'size' => 'integer',
'is_delete' => 'integer', 'created_at' => 'datetime'
'created_at' => 'datetime'
]; ];
} }

View File

@ -50,6 +50,8 @@ class RedisWebsocketSubscribe extends AbstractProcess
//echo PHP_EOL . "chan : $chan , msg : $message"; //echo PHP_EOL . "chan : $chan , msg : $message";
$data = json_decode($message, true); $data = json_decode($message, true);
var_dump("subscribe ====> {$message}");
$this->handleService->handle($data); $this->handleService->handle($data);
} }
} }

View File

@ -6,8 +6,8 @@ use App\Cache\FriendApply;
use App\Constants\TalkEventConstant; use App\Constants\TalkEventConstant;
use App\Event\TalkEvent; use App\Event\TalkEvent;
use App\Model\User; use App\Model\User;
use App\Model\Contact; use App\Model\Contact\Contact;
use App\Model\ContactApply; use App\Model\Contact\ContactApply;
use App\Traits\PagingTrait; use App\Traits\PagingTrait;
use Hyperf\DbConnection\Db; use Hyperf\DbConnection\Db;

View File

@ -96,8 +96,8 @@ class FormatMessageService
// 查询聊天文件信息 // 查询聊天文件信息
if ($files) { if ($files) {
$files = TalkRecordsFile::whereIn('record_id', $files)->get([ $files = TalkRecordsFile::whereIn('record_id', $files)->get([
'id', 'record_id', 'user_id', 'file_source', 'file_type', 'save_type', 'id', 'record_id', 'user_id', 'source', 'type', 'drive',
'original_name', 'file_suffix', 'file_size', 'save_dir' 'original_name', 'suffix', 'size', 'path'
])->keyBy('record_id')->toArray(); ])->keyBy('record_id')->toArray();
} }
@ -111,7 +111,7 @@ class FormatMessageService
// 查询代码块消息 // 查询代码块消息
if ($codes) { if ($codes) {
$codes = TalkRecordsCode::whereIn('record_id', $codes)->get([ $codes = TalkRecordsCode::whereIn('record_id', $codes)->get([
'record_id', 'code_lang', 'code' 'record_id', 'lang', 'code'
])->keyBy('record_id')->toArray(); ])->keyBy('record_id')->toArray();
} }
@ -149,7 +149,7 @@ class FormatMessageService
case TalkMessageType::FILE_MESSAGE: case TalkMessageType::FILE_MESSAGE:
$rows[$k]['file'] = $files[$row['id']] ?? []; $rows[$k]['file'] = $files[$row['id']] ?? [];
if ($rows[$k]['file']) { if ($rows[$k]['file']) {
$rows[$k]['file']['file_url'] = get_media_url($rows[$k]['file']['save_dir']); $rows[$k]['file']['file_url'] = get_media_url($rows[$k]['file']['path']);
} }
break; break;

View File

@ -49,14 +49,14 @@ class SubscribeHandleService
/** /**
* @param array $data 数据 * @param array $data 数据
* <pre> * <pre>
* [ * [
* 'uuid' => '', * 'uuid' => '',
* 'event' => '', * 'event' => '',
* 'data' => '', * 'data' => '',
* 'options' => '' * 'options' => ''
* ]; * ];
* </pre> * </pre>
*/ */
public function handle(array $data) public function handle(array $data)
{ {
@ -120,7 +120,8 @@ class SubscribeHandleService
if (!$result) return; if (!$result) return;
$message = di()->get(FormatMessageService::class)->handleChatRecords([$result->toArray()])[0]; $message = di()->get(FormatMessageService::class)->handleChatRecords([$result->toArray()])[0];
$push = [
$this->push($fds, $this->toJson(TalkEventConstant::EVENT_TALK, [
'sender_id' => $sender_id, 'sender_id' => $sender_id,
'receiver_id' => $receiver_id, 'receiver_id' => $receiver_id,
'talk_type' => $talk_type, 'talk_type' => $talk_type,
@ -128,9 +129,7 @@ class SubscribeHandleService
'group_name' => $groupInfo ? $groupInfo['group_name'] : '', 'group_name' => $groupInfo ? $groupInfo['group_name'] : '',
'group_avatar' => $groupInfo ? $groupInfo['avatar'] : '' 'group_avatar' => $groupInfo ? $groupInfo['avatar'] : ''
]) ])
]; ]));
$this->push($fds, json_encode([TalkEventConstant::EVENT_TALK, $push]));
} }
/** /**
@ -142,7 +141,7 @@ class SubscribeHandleService
{ {
$fds = $this->clientService->findUserFds($data['data']['receiver_id']); $fds = $this->clientService->findUserFds($data['data']['receiver_id']);
$this->push($fds, json_encode([TalkEventConstant::EVENT_KEYBOARD, $data['data']])); $this->push($fds, $this->toJson(TalkEventConstant::EVENT_KEYBOARD, $data['data']));
} }
/** /**
@ -166,11 +165,9 @@ class SubscribeHandleService
$fds = array_unique(array_merge(...$fds)); $fds = array_unique(array_merge(...$fds));
$this->push($fds, json_encode([ $this->push($fds, $this->toJson(TalkEventConstant::EVENT_ONLINE_STATUS, [
TalkEventConstant::EVENT_ONLINE_STATUS, [ 'user_id' => $user_id,
'user_id' => $user_id, 'status' => $status
'status' => $status
]
])); ]));
} }
@ -199,12 +196,12 @@ class SubscribeHandleService
if (!$fds) return; if (!$fds) return;
$this->push($fds, json_encode([TalkEventConstant::EVENT_REVOKE_TALK, [ $this->push($fds, $this->toJson(TalkEventConstant::EVENT_REVOKE_TALK, [
'talk_type' => $record->talk_type, 'talk_type' => $record->talk_type,
'sender_id' => $record->user_id, 'sender_id' => $record->user_id,
'receiver_id' => $record->receiver_id, 'receiver_id' => $record->receiver_id,
'record_id' => $record->id, 'record_id' => $record->id,
]])); ]));
} }
/** /**
@ -245,7 +242,12 @@ class SubscribeHandleService
'mobile' => $friendInfo->mobile, 'mobile' => $friendInfo->mobile,
]; ];
$this->push(array_unique($fds), json_encode([TalkEventConstant::EVENT_FRIEND_APPLY, $msg])); $this->push(array_unique($fds), $this->toJson(TalkEventConstant::EVENT_FRIEND_APPLY, $msg));
}
private function toJson(string $event, array $data): string
{
return json_encode(["event" => $event, "content" => $data]);
} }
/** /**

View File

@ -206,7 +206,7 @@ class TalkForwardService extends BaseService
$code[] = [ $code[] = [
'record_id' => $res->id, 'record_id' => $res->id,
'user_id' => $user_id, 'user_id' => $user_id,
'code_lang' => $codeInfo['code_lang'], 'code_lang' => $codeInfo['lang'],
'code' => $codeInfo['code'], 'code' => $codeInfo['code'],
'created_at' => date('Y-m-d H:i:s') 'created_at' => date('Y-m-d H:i:s')
]; ];

View File

@ -39,9 +39,10 @@ class Response
$resp = [ $resp = [
"code" => ResponseCode::SUCCESS, "code" => ResponseCode::SUCCESS,
"message" => $message, "message" => $message,
"data" => $data,
]; ];
if ($data) $resp["data"] = $data; // if ($data) $resp["data"] = $data;
return $this->response->json($resp); return $this->response->json($resp);
} }