优化代码
parent
3d4d715471
commit
4620dbc52d
|
@ -12,7 +12,7 @@ abstract class AbstractRedis
|
||||||
|
|
||||||
public static function getInstance()
|
public static function getInstance()
|
||||||
{
|
{
|
||||||
return container()->get(static::class);
|
return di()->get(static::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -52,7 +52,7 @@ class ContactsController extends CController
|
||||||
if ($rows) {
|
if ($rows) {
|
||||||
$runArr = ServerRunID::getInstance()->getServerRunIdAll();
|
$runArr = ServerRunID::getInstance()->getServerRunIdAll();
|
||||||
foreach ($rows as $k => $row) {
|
foreach ($rows as $k => $row) {
|
||||||
$rows[$k]['is_online'] = container()->get(SocketClientService::class)->isOnlineAll($row['id'], $runArr);
|
$rows[$k]['is_online'] = di()->get(SocketClientService::class)->isOnlineAll($row['id'], $runArr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,7 +77,7 @@ class ContactsController extends CController
|
||||||
return $this->response->fail('好友关系解除失败!');
|
return $this->response->fail('好友关系解除失败!');
|
||||||
}
|
}
|
||||||
|
|
||||||
container()->get(TalkListService::class)->deleteByType($user_id, $params['friend_id'], TalkModeConstant::PRIVATE_CHAT);
|
di()->get(TalkListService::class)->deleteByType($user_id, $params['friend_id'], TalkModeConstant::PRIVATE_CHAT);
|
||||||
|
|
||||||
// TODO 推送消息(待完善)
|
// TODO 推送消息(待完善)
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,7 @@ class DownloadController extends CController
|
||||||
{
|
{
|
||||||
private function getFilePath(string $path)
|
private function getFilePath(string $path)
|
||||||
{
|
{
|
||||||
return container()->get(Filesystem::class)->getConfig()->get('root') . '/' . $path;
|
return di()->get(Filesystem::class)->getConfig()->get('root') . '/' . $path;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -70,7 +70,7 @@ class AppExceptionHandler extends ExceptionHandler
|
||||||
email()->send(
|
email()->send(
|
||||||
$adminEmail,
|
$adminEmail,
|
||||||
'系统报错通知',
|
'系统报错通知',
|
||||||
container()->get(MailerTemplate::class)->errorNotice($throwable)
|
di()->get(MailerTemplate::class)->errorNotice($throwable)
|
||||||
);
|
);
|
||||||
} catch (\Exception $exception) {
|
} catch (\Exception $exception) {
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,7 @@ class RedisWebsocketSubscribe extends AbstractProcess
|
||||||
*/
|
*/
|
||||||
public function handle(): void
|
public function handle(): void
|
||||||
{
|
{
|
||||||
$this->handleService = container()->get(SubscribeHandleService::class);
|
$this->handleService = di()->get(SubscribeHandleService::class);
|
||||||
|
|
||||||
redis()->subscribe($this->chans, [$this, 'subscribe']);
|
redis()->subscribe($this->chans, [$this, 'subscribe']);
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,7 +47,7 @@ class ContactApplyService
|
||||||
FriendApply::getInstance()->incr($friend_id, 1);
|
FriendApply::getInstance()->incr($friend_id, 1);
|
||||||
|
|
||||||
// 判断对方是否在线。如果在线发送消息通知
|
// 判断对方是否在线。如果在线发送消息通知
|
||||||
$isOnline = container()->get(SocketClientService::class)->isOnlineAll($friend_id);
|
$isOnline = di()->get(SocketClientService::class)->isOnlineAll($friend_id);
|
||||||
if ($isOnline) {
|
if ($isOnline) {
|
||||||
event()->dispatch(new TalkEvent(TalkEventConstant::EVENT_FRIEND_APPLY, [
|
event()->dispatch(new TalkEvent(TalkEventConstant::EVENT_FRIEND_APPLY, [
|
||||||
'apply_id' => $result->id,
|
'apply_id' => $result->id,
|
||||||
|
@ -98,7 +98,7 @@ class ContactApplyService
|
||||||
}
|
}
|
||||||
|
|
||||||
// 判断对方是否在线。如果在线发送消息通知
|
// 判断对方是否在线。如果在线发送消息通知
|
||||||
$isOnline = container()->get(SocketClientService::class)->isOnlineAll($info->user_id);
|
$isOnline = di()->get(SocketClientService::class)->isOnlineAll($info->user_id);
|
||||||
if ($isOnline) {
|
if ($isOnline) {
|
||||||
event()->dispatch(new TalkEvent(TalkEventConstant::EVENT_FRIEND_APPLY, [
|
event()->dispatch(new TalkEvent(TalkEventConstant::EVENT_FRIEND_APPLY, [
|
||||||
'apply_id' => $apply_id,
|
'apply_id' => $apply_id,
|
||||||
|
|
|
@ -118,7 +118,7 @@ class SubscribeHandleService
|
||||||
if (!$result) return;
|
if (!$result) return;
|
||||||
|
|
||||||
|
|
||||||
$message = container()->get(FormatMessageService::class)->handleChatRecords([$result->toArray()])[0];
|
$message = di()->get(FormatMessageService::class)->handleChatRecords([$result->toArray()])[0];
|
||||||
$notify = [
|
$notify = [
|
||||||
'sender_id' => $sender_id,
|
'sender_id' => $sender_id,
|
||||||
'receiver_id' => $receiver_id,
|
'receiver_id' => $receiver_id,
|
||||||
|
@ -156,7 +156,7 @@ class SubscribeHandleService
|
||||||
|
|
||||||
$fds = [];
|
$fds = [];
|
||||||
|
|
||||||
$ids = container()->get(UserService::class)->getFriendIds($user_id);
|
$ids = di()->get(UserService::class)->getFriendIds($user_id);
|
||||||
foreach ($ids as $friend_id) {
|
foreach ($ids as $friend_id) {
|
||||||
$fds = array_merge($fds, $this->clientService->findUserFds(intval($friend_id)));
|
$fds = array_merge($fds, $this->clientService->findUserFds(intval($friend_id)));
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,7 +68,7 @@ class SplitUploadService
|
||||||
|
|
||||||
$save_path = "tmp/{$hashName}/" . "{$hashName}_{$split_index}_{$fileInfo->file_ext}.tmp";
|
$save_path = "tmp/{$hashName}/" . "{$hashName}_{$split_index}_{$fileInfo->file_ext}.tmp";
|
||||||
try {
|
try {
|
||||||
container()->get(Filesystem::class)->write($save_path, file_get_contents($file->getRealPath()));
|
di()->get(Filesystem::class)->write($save_path, file_get_contents($file->getRealPath()));
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -119,7 +119,7 @@ class SplitUploadService
|
||||||
|
|
||||||
$file_merge = "tmp/{$hash_name}/{$fileInfo->original_name}.tmp";
|
$file_merge = "tmp/{$hash_name}/{$fileInfo->original_name}.tmp";
|
||||||
|
|
||||||
$filesystem = container()->get(Filesystem::class);
|
$filesystem = di()->get(Filesystem::class);
|
||||||
$root_path = $filesystem->getConfig()->get('root');
|
$root_path = $filesystem->getConfig()->get('root');
|
||||||
foreach ($files as $file) {
|
foreach ($files as $file) {
|
||||||
file_put_contents(
|
file_put_contents(
|
||||||
|
|
|
@ -141,8 +141,8 @@ class TalkListService
|
||||||
$data['name'] = $item['nickname'];
|
$data['name'] = $item['nickname'];
|
||||||
$data['avatar'] = $item['user_avatar'];
|
$data['avatar'] = $item['user_avatar'];
|
||||||
$data['unread_num'] = UnreadTalkCache::getInstance()->read($item['receiver_id'], $user_id);
|
$data['unread_num'] = UnreadTalkCache::getInstance()->read($item['receiver_id'], $user_id);
|
||||||
$data['is_online'] = container()->get(SocketClientService::class)->isOnlineAll($item['receiver_id'], $runIdAll);
|
$data['is_online'] = di()->get(SocketClientService::class)->isOnlineAll($item['receiver_id'], $runIdAll);
|
||||||
$data['remark_name'] = container()->get(UserFriendService::class)->getFriendRemark($user_id, $item['receiver_id']);
|
$data['remark_name'] = di()->get(UserFriendService::class)->getFriendRemark($user_id, $item['receiver_id']);
|
||||||
} else if (TalkModeConstant::GROUP_CHAT) {
|
} else if (TalkModeConstant::GROUP_CHAT) {
|
||||||
$data['name'] = strval($item['group_name']);
|
$data['name'] = strval($item['group_name']);
|
||||||
$data['avatar'] = $item['group_avatar'];
|
$data['avatar'] = $item['group_avatar'];
|
||||||
|
|
|
@ -81,7 +81,7 @@ class TalkService extends BaseService
|
||||||
});
|
});
|
||||||
|
|
||||||
$rows = $rowsSqlObj->orderBy('talk_records.id', 'desc')->limit($limit)->get()->toArray();
|
$rows = $rowsSqlObj->orderBy('talk_records.id', 'desc')->limit($limit)->get()->toArray();
|
||||||
return container()->get(FormatMessageService::class)->handleChatRecords($rows);
|
return di()->get(FormatMessageService::class)->handleChatRecords($rows);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -124,7 +124,7 @@ class TalkService extends BaseService
|
||||||
$rowsSqlObj->whereIn('talk_records.id', explode(',', $forward->records_id));
|
$rowsSqlObj->whereIn('talk_records.id', explode(',', $forward->records_id));
|
||||||
$rows = $rowsSqlObj->get()->toArray();
|
$rows = $rowsSqlObj->get()->toArray();
|
||||||
|
|
||||||
return container()->get(FormatMessageService::class)->handleChatRecords($rows);
|
return di()->get(FormatMessageService::class)->handleChatRecords($rows);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -325,7 +325,7 @@ class TalkService extends BaseService
|
||||||
$sqlObj = TalkRecords::whereIn('id', $records_ids);
|
$sqlObj = TalkRecords::whereIn('id', $records_ids);
|
||||||
|
|
||||||
if ($talk_type == TalkModeConstant::PRIVATE_CHAT) {
|
if ($talk_type == TalkModeConstant::PRIVATE_CHAT) {
|
||||||
if (!container()->get(UserFriendService::class)->isFriend($user_id, $receiver_id, true)) return [];
|
if (!di()->get(UserFriendService::class)->isFriend($user_id, $receiver_id, true)) return [];
|
||||||
|
|
||||||
$sqlObj = $sqlObj->where(function ($query) use ($user_id, $receiver_id) {
|
$sqlObj = $sqlObj->where(function ($query) use ($user_id, $receiver_id) {
|
||||||
$query->where([
|
$query->where([
|
||||||
|
@ -476,7 +476,7 @@ class TalkService extends BaseService
|
||||||
}
|
}
|
||||||
|
|
||||||
$rows = $rowsSqlObj->orderBy('talk_records.id', 'desc')->forPage($page, $page_size)->get()->toArray();
|
$rows = $rowsSqlObj->orderBy('talk_records.id', 'desc')->forPage($page, $page_size)->get()->toArray();
|
||||||
$rows = container()->get(FormatMessageService::class)->handleChatRecords($rows);
|
$rows = di()->get(FormatMessageService::class)->handleChatRecords($rows);
|
||||||
|
|
||||||
return $this->getPagingRows($rows, $count, $page, $page_size);
|
return $this->getPagingRows($rows, $count, $page, $page_size);
|
||||||
}
|
}
|
||||||
|
|
|
@ -125,11 +125,11 @@ class UserService extends BaseService
|
||||||
|
|
||||||
// 判断查询信息是否是自己
|
// 判断查询信息是否是自己
|
||||||
if ($friend_id != $me_user_id) {
|
if ($friend_id != $me_user_id) {
|
||||||
$is_friend = container()->get(UserFriendService::class)->isFriend($me_user_id, $friend_id, true);
|
$is_friend = di()->get(UserFriendService::class)->isFriend($me_user_id, $friend_id, true);
|
||||||
|
|
||||||
$info['friend_status'] = $is_friend ? 2 : 1;
|
$info['friend_status'] = $is_friend ? 2 : 1;
|
||||||
if ($is_friend) {
|
if ($is_friend) {
|
||||||
$info['nickname_remark'] = container()->get(UserFriendService::class)->getFriendRemark($me_user_id, $friend_id);
|
$info['nickname_remark'] = di()->get(UserFriendService::class)->getFriendRemark($me_user_id, $friend_id);
|
||||||
} else {
|
} else {
|
||||||
$res = UsersFriendApply::where('user_id', $me_user_id)
|
$res = UsersFriendApply::where('user_id', $me_user_id)
|
||||||
->where('friend_id', $friend_id)
|
->where('friend_id', $friend_id)
|
||||||
|
|
|
@ -21,7 +21,7 @@ class MailerTemplate
|
||||||
*/
|
*/
|
||||||
private function view(string $engine, string $template, $params = []): string
|
private function view(string $engine, string $template, $params = []): string
|
||||||
{
|
{
|
||||||
return container()->get($engine)->render($template, $params, config('view.config', []));
|
return di()->get($engine)->render($template, $params, config('view.config', []));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -59,7 +59,7 @@ class SendEmailCode
|
||||||
// ...执行发送(后期使用队列)
|
// ...执行发送(后期使用队列)
|
||||||
email()->send(
|
email()->send(
|
||||||
$email, 'Lumen IM(绑定邮箱验证码)',
|
$email, 'Lumen IM(绑定邮箱验证码)',
|
||||||
container()->get(MailerTemplate::class)->emailCode($sms_code)
|
di()->get(MailerTemplate::class)->emailCode($sms_code)
|
||||||
);
|
);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -19,7 +19,7 @@ class UserRelation
|
||||||
public static function isFriendOrGroupMember(int $user_id, int $receiver_id, int $talk_type)
|
public static function isFriendOrGroupMember(int $user_id, int $receiver_id, int $talk_type)
|
||||||
{
|
{
|
||||||
if ($talk_type == TalkModeConstant::PRIVATE_CHAT) {
|
if ($talk_type == TalkModeConstant::PRIVATE_CHAT) {
|
||||||
return container()->get(UserFriendService::class)->isFriend($user_id, $receiver_id, true);
|
return di()->get(UserFriendService::class)->isFriend($user_id, $receiver_id, true);
|
||||||
} else if ($talk_type == TalkModeConstant::GROUP_CHAT) {
|
} else if ($talk_type == TalkModeConstant::GROUP_CHAT) {
|
||||||
return Group::isMember($receiver_id, $user_id);
|
return Group::isMember($receiver_id, $user_id);
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,7 @@ use Hyperf\Redis\Redis;
|
||||||
*
|
*
|
||||||
* @return \Psr\Container\ContainerInterface
|
* @return \Psr\Container\ContainerInterface
|
||||||
*/
|
*/
|
||||||
function container()
|
function di()
|
||||||
{
|
{
|
||||||
return ApplicationContext::getContainer();
|
return ApplicationContext::getContainer();
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,7 @@ function container()
|
||||||
*/
|
*/
|
||||||
function redis()
|
function redis()
|
||||||
{
|
{
|
||||||
return container()->get(Redis::class);
|
return di()->get(Redis::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -43,7 +43,7 @@ function redis()
|
||||||
*/
|
*/
|
||||||
function server()
|
function server()
|
||||||
{
|
{
|
||||||
return container()->get(ServerFactory::class)->getServer()->getServer();
|
return di()->get(ServerFactory::class)->getServer()->getServer();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -53,7 +53,7 @@ function server()
|
||||||
*/
|
*/
|
||||||
function frame()
|
function frame()
|
||||||
{
|
{
|
||||||
return container()->get(Frame::class);
|
return di()->get(Frame::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -63,7 +63,7 @@ function frame()
|
||||||
*/
|
*/
|
||||||
function websocket()
|
function websocket()
|
||||||
{
|
{
|
||||||
return container()->get(WebSocketServer::class);
|
return di()->get(WebSocketServer::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -73,7 +73,7 @@ function websocket()
|
||||||
*/
|
*/
|
||||||
function cache()
|
function cache()
|
||||||
{
|
{
|
||||||
return container()->get(Psr\SimpleCache\CacheInterface::class);
|
return di()->get(Psr\SimpleCache\CacheInterface::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -81,7 +81,7 @@ function cache()
|
||||||
*/
|
*/
|
||||||
function event()
|
function event()
|
||||||
{
|
{
|
||||||
return container()->get(\Psr\EventDispatcher\EventDispatcherInterface::class);
|
return di()->get(\Psr\EventDispatcher\EventDispatcherInterface::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -91,7 +91,7 @@ function event()
|
||||||
*/
|
*/
|
||||||
function stdout_log()
|
function stdout_log()
|
||||||
{
|
{
|
||||||
return container()->get(StdoutLoggerInterface::class);
|
return di()->get(StdoutLoggerInterface::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -102,7 +102,7 @@ function stdout_log()
|
||||||
*/
|
*/
|
||||||
function logger(string $name = 'APP')
|
function logger(string $name = 'APP')
|
||||||
{
|
{
|
||||||
return container()->get(LoggerFactory::class)->get($name);
|
return di()->get(LoggerFactory::class)->get($name);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -112,7 +112,7 @@ function logger(string $name = 'APP')
|
||||||
*/
|
*/
|
||||||
function request()
|
function request()
|
||||||
{
|
{
|
||||||
return container()->get(ServerRequestInterface::class);
|
return di()->get(ServerRequestInterface::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -122,13 +122,13 @@ function request()
|
||||||
*/
|
*/
|
||||||
function response()
|
function response()
|
||||||
{
|
{
|
||||||
return container()->get(ResponseInterface::class);
|
return di()->get(ResponseInterface::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function email()
|
function email()
|
||||||
{
|
{
|
||||||
return container()->get(\App\Support\Mail::class);
|
return di()->get(\App\Support\Mail::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -257,7 +257,7 @@ function parse_ids($ids)
|
||||||
*/
|
*/
|
||||||
function push_amqp(\Hyperf\Amqp\Message\ProducerMessage $message, bool $confirm = false, int $timeout = 5)
|
function push_amqp(\Hyperf\Amqp\Message\ProducerMessage $message, bool $confirm = false, int $timeout = 5)
|
||||||
{
|
{
|
||||||
return container()->get(\Hyperf\Amqp\Producer::class)->produce($message, $confirm, $timeout);
|
return di()->get(\Hyperf\Amqp\Producer::class)->produce($message, $confirm, $timeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue