优化代码

main
gzydong 2021-06-29 17:30:43 +08:00
parent 8aba19c21d
commit 4481ba558a
7 changed files with 34 additions and 14 deletions

View File

@ -141,11 +141,14 @@ class ChatMessageConsumer extends ConsumerMessage
public function onConsumeTalk(array $data, AMQPMessage $message): string
{
$source = $data['data']['source'];
$fds = $this->socketClientService->findUserFds($data['data']['sender']);
$fds = [];
$groupInfo = null;
if ($source == 1) {// 私聊
$fds = array_merge($fds, $this->socketClientService->findUserFds($data['data']['receive']));
$fds = array_merge(
$this->socketClientService->findUserFds($data['data']['sender']),
$this->socketClientService->findUserFds($data['data']['receive'])
);
} else if ($source == 2) {// 群聊
$userIds = SocketRoom::getInstance()->getRoomMembers(strval($data['data']['receive']));
foreach ($userIds as $uid) {

View File

@ -19,6 +19,8 @@ use App\Cache\SocketFdBindUser;
use App\Cache\SocketRoom;
use App\Cache\SocketUserBindFds;
use App\Cache\UnreadTalk;
use App\Model\Group\Group;
use App\Model\Group\GroupMember;
use App\Service\TalkService;
use Hyperf\Command\Command as HyperfCommand;
use Hyperf\Command\Annotation\Command;
@ -144,14 +146,14 @@ class TestCommand extends HyperfCommand
//SocketFdBindUser::getInstance()->bind(1, 2054);
//SocketUserBindFds::getInstance()->bind(1, 2054);
$model1 = SocketUserBindFds::getInstance();
$model2 = FriendRemark::getInstance();
var_dump($model1 === SocketUserBindFds::getInstance());
var_dump($model2 === FriendRemark::getInstance());
var_dump(SocketUserBindFds::getInstance());
var_dump(FriendRemark::getInstance());
//$model1 = SocketUserBindFds::getInstance();
//$model2 = FriendRemark::getInstance();
//
//var_dump($model1 === SocketUserBindFds::getInstance());
//var_dump($model2 === FriendRemark::getInstance());
//
//var_dump(SocketUserBindFds::getInstance());
//var_dump(FriendRemark::getInstance());
//SocketUserBindFds::getInstance();
//SocketUserBindFds::getInstance();
@ -169,5 +171,7 @@ class TestCommand extends HyperfCommand
//var_dump(SocketUserBindFds::getInstance());
//var_dump(SocketRoom::getInstance());
//var_dump(FriendRemark::getInstance());
//var_dump(Group::isManager(2054,116));
}
}

View File

@ -147,6 +147,7 @@ class ArticleController extends CController
* @RequestMapping(path="del-article-class", methods="post")
*
* @return ResponseInterface
* @throws \Exception
*/
public function delArticleClass()
{
@ -418,7 +419,7 @@ class ArticleController extends CController
$params = $this->request->inputs(['article_id', 'tags']);
$this->validate($params, [
'article_id' => 'required|integer|min:0',
'tags' => 'required|array'
'tags' => 'present|array'
]);
$isTrue = $this->articleService->updateArticleTag($this->uid(), (int)$params['article_id'], $params['tags']);

View File

@ -61,8 +61,9 @@ class AuthController extends CController
return $this->response->success([
'authorize' => [
'type' => 'Bearer',
'access_token' => $token,
'expires_in' => $this->guard()->getJwtManager()->getTtl()
'expires_in' => $this->guard()->getJwtManager()->getTtl(),
],
'user_info' => [
'nickname' => $userInfo->nickname,
@ -155,11 +156,12 @@ class AuthController extends CController
public function refresh()
{
if ($this->guard()->guest()) {
return $this->response->fail('登录 token 刷新失败!');
return $this->response->fail('token 刷新失败!');
}
return $this->response->success([
'authorize' => [
'type' => 'Bearer',
'token' => $this->guard()->refresh(),
'expire' => $this->guard()->getJwtManager()->getTtl()
]

View File

@ -487,7 +487,7 @@ class ArticleService extends BaseService
*/
public function updateArticleTag(int $uid, int $article_id, array $tags)
{
return (bool)Article::where('id', $article_id)->where('user_id', $uid)->update(['tags_id' => implode(',', $tags)]);
return (bool)Article::where('id', $article_id)->where('user_id', $uid)->update(['tags_id' => implode(',', $tags), 'updated_at' => date('Y-m-d H:i:s')]);
}
/**

View File

@ -288,6 +288,7 @@ class GroupService extends BaseService
*/
public function quit(int $user_id, int $group_id)
{
// 判断是否属于管理员
if (Group::isManager($user_id, $group_id)) {
return [false, 0];
}

View File

@ -24,4 +24,13 @@ trait StaticInstance
return static::$instance;
}
public function __construct()
{
}
public function __clone()
{
}
}