优化代码

main
gzydong 2021-07-29 23:30:42 +08:00
parent 1fea98efb8
commit 2104cf3684
10 changed files with 32 additions and 7 deletions

View File

@ -3,6 +3,7 @@
namespace App\Cache; namespace App\Cache;
use App\Cache\Repository\HashRedis; use App\Cache\Repository\HashRedis;
use App\Traits\StaticInstance;
/** /**
* 好友申请未读数 - 缓存助手 * 好友申请未读数 - 缓存助手
@ -11,5 +12,7 @@ use App\Cache\Repository\HashRedis;
*/ */
class FriendApply extends HashRedis class FriendApply extends HashRedis
{ {
use StaticInstance;
public $name = 'friend-apply'; public $name = 'friend-apply';
} }

View File

@ -4,6 +4,7 @@ namespace App\Cache;
use App\Cache\Repository\HashRedis; use App\Cache\Repository\HashRedis;
use App\Model\UsersFriend; use App\Model\UsersFriend;
use App\Traits\StaticInstance;
/** /**
* 好友备注 - 缓存助手 * 好友备注 - 缓存助手
@ -12,6 +13,8 @@ use App\Model\UsersFriend;
*/ */
class FriendRemark extends HashRedis class FriendRemark extends HashRedis
{ {
use StaticInstance;
public $name = 'friend-remark'; public $name = 'friend-remark';
/** /**

View File

@ -3,6 +3,7 @@
namespace App\Cache; namespace App\Cache;
use App\Cache\Repository\HashRedis; use App\Cache\Repository\HashRedis;
use App\Traits\StaticInstance;
/** /**
* 聊天最新消息 - 缓存助手 * 聊天最新消息 - 缓存助手
@ -11,6 +12,8 @@ use App\Cache\Repository\HashRedis;
*/ */
class LastMessage extends HashRedis class LastMessage extends HashRedis
{ {
use StaticInstance;
public $name = 'last-message'; public $name = 'last-message';
/** /**

View File

@ -3,6 +3,7 @@
namespace App\Cache; namespace App\Cache;
use App\Cache\Repository\HashRedis; use App\Cache\Repository\HashRedis;
use App\Traits\StaticInstance;
/** /**
* 服务运行ID - 缓存助手 * 服务运行ID - 缓存助手
@ -11,6 +12,8 @@ use App\Cache\Repository\HashRedis;
*/ */
class ServerRunID extends HashRedis class ServerRunID extends HashRedis
{ {
use StaticInstance;
protected $prefix = 'SERVER_RUN_ID'; protected $prefix = 'SERVER_RUN_ID';
protected $name = ''; protected $name = '';

View File

@ -3,6 +3,7 @@
namespace App\Cache; namespace App\Cache;
use App\Cache\Repository\HashGroupRedis; use App\Cache\Repository\HashGroupRedis;
use App\Traits\StaticInstance;
/** /**
* :客户端ID与用户ID绑定(多对一关系) * :客户端ID与用户ID绑定(多对一关系)
@ -11,6 +12,8 @@ use App\Cache\Repository\HashGroupRedis;
*/ */
class SocketFdBindUser extends HashGroupRedis class SocketFdBindUser extends HashGroupRedis
{ {
use StaticInstance;
protected $name = 'ws:fd-user'; protected $name = 'ws:fd-user';
/** /**

View File

@ -3,6 +3,7 @@
namespace App\Cache; namespace App\Cache;
use App\Cache\Repository\SetGroupRedis; use App\Cache\Repository\SetGroupRedis;
use App\Traits\StaticInstance;
/** /**
* 聊天室 - 缓存助手 * 聊天室 - 缓存助手
@ -11,6 +12,8 @@ use App\Cache\Repository\SetGroupRedis;
*/ */
class SocketRoom extends SetGroupRedis class SocketRoom extends SetGroupRedis
{ {
use StaticInstance;
protected $name = 'ws:room'; protected $name = 'ws:room';
/** /**

View File

@ -3,6 +3,7 @@
namespace App\Cache; namespace App\Cache;
use App\Cache\Repository\SetGroupRedis; use App\Cache\Repository\SetGroupRedis;
use App\Traits\StaticInstance;
/** /**
* :用户ID与客户端ID绑定(一对多关系) * :用户ID与客户端ID绑定(一对多关系)
@ -11,6 +12,8 @@ use App\Cache\Repository\SetGroupRedis;
*/ */
class SocketUserBindFds extends SetGroupRedis class SocketUserBindFds extends SetGroupRedis
{ {
use StaticInstance;
protected $name = 'ws:user-fds'; protected $name = 'ws:user-fds';
/** /**

View File

@ -3,6 +3,7 @@
namespace App\Cache; namespace App\Cache;
use App\Cache\Repository\HashRedis; use App\Cache\Repository\HashRedis;
use App\Traits\StaticInstance;
/** /**
* 私信消息未读数 - 缓存助手 * 私信消息未读数 - 缓存助手
@ -11,6 +12,8 @@ use App\Cache\Repository\HashRedis;
*/ */
class UnreadTalkCache extends HashRedis class UnreadTalkCache extends HashRedis
{ {
use StaticInstance;
public $name = 'unread-talk'; public $name = 'unread-talk';
/** /**

View File

@ -10,10 +10,10 @@ use App\Traits\StaticInstance;
class VoteStatisticsCache extends StringRedis class VoteStatisticsCache extends StringRedis
{ {
protected $name = 'vote-statistic-cache';
use StaticInstance; use StaticInstance;
protected $name = 'vote-statistic-cache';
/** /**
* 更新投票统计缓存 * 更新投票统计缓存
* *

View File

@ -1,4 +1,5 @@
<?php <?php
declare(strict_types=1);
namespace App\Controller\Api\V1; namespace App\Controller\Api\V1;
@ -55,7 +56,7 @@ class TalkMessageController extends CController
]); ]);
$user_id = $this->uid(); $user_id = $this->uid();
if (!UserRelation::isFriendOrGroupMember($user_id, $params['receiver_id'], $params['talk_type'])) { if (!UserRelation::isFriendOrGroupMember($user_id, (int)$params['receiver_id'], (int)$params['talk_type'])) {
return $this->response->fail('暂不属于好友关系或群聊成员,无法发送聊天消息!'); return $this->response->fail('暂不属于好友关系或群聊成员,无法发送聊天消息!');
} }
@ -87,7 +88,7 @@ class TalkMessageController extends CController
]); ]);
$user_id = $this->uid(); $user_id = $this->uid();
if (!UserRelation::isFriendOrGroupMember($user_id, $params['receiver_id'], $params['talk_type'])) { if (!UserRelation::isFriendOrGroupMember($user_id, (int)$params['receiver_id'], (int)$params['talk_type'])) {
return $this->response->fail('暂不属于好友关系或群聊成员,无法发送聊天消息!'); return $this->response->fail('暂不属于好友关系或群聊成员,无法发送聊天消息!');
} }
@ -140,7 +141,7 @@ class TalkMessageController extends CController
]); ]);
$user_id = $this->uid(); $user_id = $this->uid();
if (!UserRelation::isFriendOrGroupMember($user_id, $params['receiver_id'], $params['talk_type'])) { if (!UserRelation::isFriendOrGroupMember($user_id, (int)$params['receiver_id'], (int)$params['talk_type'])) {
return $this->response->fail('暂不属于好友关系或群聊成员,无法发送聊天消息!'); return $this->response->fail('暂不属于好友关系或群聊成员,无法发送聊天消息!');
} }
@ -189,7 +190,7 @@ class TalkMessageController extends CController
]); ]);
$user_id = $this->uid(); $user_id = $this->uid();
if (!UserRelation::isFriendOrGroupMember($user_id, $params['receiver_id'], TalkModeConstant::GROUP_CHAT)) { if (!UserRelation::isFriendOrGroupMember($user_id, (int)$params['receiver_id'], TalkModeConstant::GROUP_CHAT)) {
return $this->response->fail('暂不属于好友关系或群聊成员,无法发送聊天消息!'); return $this->response->fail('暂不属于好友关系或群聊成员,无法发送聊天消息!');
} }
@ -247,7 +248,7 @@ class TalkMessageController extends CController
]); ]);
$user_id = $this->uid(); $user_id = $this->uid();
if (!UserRelation::isFriendOrGroupMember($user_id, $params['receiver_id'], $params['talk_type'])) { if (!UserRelation::isFriendOrGroupMember($user_id, (int)$params['receiver_id'], (int)$params['talk_type'])) {
return $this->response->fail('暂不属于好友关系或群聊成员,无法发送聊天消息!'); return $this->response->fail('暂不属于好友关系或群聊成员,无法发送聊天消息!');
} }