优化代码
parent
73fc864806
commit
2d110bad77
|
@ -94,8 +94,9 @@ class ChatMessageConsumer extends ConsumerMessage
|
|||
|
||||
/**
|
||||
* ChatMessageConsumer constructor.
|
||||
*
|
||||
* @param SocketClientService $socketClientService
|
||||
* @param SocketRoomService $socketRoomService
|
||||
* @param SocketRoomService $socketRoomService
|
||||
*/
|
||||
public function __construct(SocketClientService $socketClientService, SocketRoomService $socketRoomService)
|
||||
{
|
||||
|
@ -121,8 +122,9 @@ class ChatMessageConsumer extends ConsumerMessage
|
|||
/**
|
||||
* 消费队列消息
|
||||
*
|
||||
* @param $data
|
||||
* @param $data
|
||||
* @param AMQPMessage $message
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function consumeMessage($data, AMQPMessage $message): string
|
||||
|
@ -146,8 +148,9 @@ class ChatMessageConsumer extends ConsumerMessage
|
|||
/**
|
||||
* 对话聊天消息
|
||||
*
|
||||
* @param array $data 队列消息
|
||||
* @param array $data 队列消息
|
||||
* @param AMQPMessage $message
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function onConsumeTalk(array $data, AMQPMessage $message): string
|
||||
|
@ -261,8 +264,9 @@ class ChatMessageConsumer extends ConsumerMessage
|
|||
/**
|
||||
* 键盘输入事件消息
|
||||
*
|
||||
* @param array $data 队列消息
|
||||
* @param array $data 队列消息
|
||||
* @param AMQPMessage $message
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function onConsumeKeyboard(array $data, AMQPMessage $message): string
|
||||
|
@ -277,8 +281,9 @@ class ChatMessageConsumer extends ConsumerMessage
|
|||
/**
|
||||
* 用户上线或下线消息
|
||||
*
|
||||
* @param array $data 队列消息
|
||||
* @param array $data 队列消息
|
||||
* @param AMQPMessage $message
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function onConsumeOnlineStatus(array $data, AMQPMessage $message): string
|
||||
|
@ -298,8 +303,9 @@ class ChatMessageConsumer extends ConsumerMessage
|
|||
/**
|
||||
* 撤销聊天消息
|
||||
*
|
||||
* @param array $data 队列消息
|
||||
* @param array $data 队列消息
|
||||
* @param AMQPMessage $message
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function onConsumeRevokeTalk(array $data, AMQPMessage $message): string
|
||||
|
@ -334,8 +340,9 @@ class ChatMessageConsumer extends ConsumerMessage
|
|||
/**
|
||||
* 好友申请消息
|
||||
*
|
||||
* @param array $data 队列消息
|
||||
* @param array $data 队列消息
|
||||
* @param AMQPMessage $message
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function onConsumeFriendApply(array $data, AMQPMessage $message): string
|
||||
|
@ -365,6 +372,7 @@ class ChatMessageConsumer extends ConsumerMessage
|
|||
* 格式化对话的消息体
|
||||
*
|
||||
* @param array $data 对话的消息
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function formatTalkMessage(array $data): array
|
||||
|
@ -373,10 +381,10 @@ class ChatMessageConsumer extends ConsumerMessage
|
|||
"id" => 0,// 消息记录ID
|
||||
"source" => 1,// 消息来源[1:好友私信;2:群聊]
|
||||
"msg_type" => 1,
|
||||
"user_id" => 0,// 发送者用户ID
|
||||
"receive_id" => 0,// 接收者ID[好友ID或群ID]
|
||||
"user_id" => 0, // 发送者用户ID
|
||||
"receive_id" => 0, // 接收者ID[好友ID或群ID]
|
||||
"content" => '',// 文本消息
|
||||
"is_revoke" => 0,// 消息是否撤销
|
||||
"is_revoke" => 0, // 消息是否撤销
|
||||
|
||||
// 发送消息人的信息
|
||||
"nickname" => "",// 用户昵称
|
||||
|
|
|
@ -42,16 +42,16 @@ class ChatMessageProducer extends ProducerMessage
|
|||
/**
|
||||
* 实例化处理
|
||||
*
|
||||
* @param string $event 事件名
|
||||
* @param array $data 数据
|
||||
* @param array $options 其它参数
|
||||
* @param string $event 事件名
|
||||
* @param array $data 数据
|
||||
* @param array $options 其它参数
|
||||
*/
|
||||
public function __construct(string $event, array $data, array $options = [])
|
||||
{
|
||||
$message = [
|
||||
'uuid' => $this->uuid(),// 自定义消息ID
|
||||
'event' => $event,
|
||||
'data' => $data,
|
||||
'uuid' => $this->uuid(),// 自定义消息ID
|
||||
'event' => $event,
|
||||
'data' => $data,
|
||||
'options' => $options
|
||||
];
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
* @author Yuandong<837215079@qq.com>
|
||||
* @link https://github.com/gzydong/hyperf-chat
|
||||
*/
|
||||
|
||||
namespace App\Bootstrap;
|
||||
|
||||
use Hyperf\Framework\Bootstrap\ServerStartCallback;
|
||||
|
@ -19,6 +20,7 @@ use Hyperf\Redis\Redis;
|
|||
* 自定义服务启动前回调事件
|
||||
*
|
||||
* Class ServerStart
|
||||
*
|
||||
* @package App\Bootstrap
|
||||
*/
|
||||
class ServerStart extends ServerStartCallback
|
||||
|
|
|
@ -4,6 +4,7 @@ namespace App\Cache;
|
|||
|
||||
/**
|
||||
* Class ApplyNumCache
|
||||
*
|
||||
* @package App\Cache
|
||||
*/
|
||||
class ApplyNumCache
|
||||
|
@ -15,6 +16,7 @@ class ApplyNumCache
|
|||
* 获取好友未读申请数
|
||||
*
|
||||
* @param int $user_id 用户ID
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function get(int $user_id)
|
||||
|
@ -26,6 +28,7 @@ class ApplyNumCache
|
|||
* 设置未读好友申请数(自增加1)
|
||||
*
|
||||
* @param int $user_id 用户ID
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public static function setInc(int $user_id)
|
||||
|
|
|
@ -4,6 +4,7 @@ namespace App\Cache;
|
|||
|
||||
/**
|
||||
* Class FriendRemarkCache
|
||||
*
|
||||
* @package App\Cache
|
||||
*/
|
||||
class FriendRemarkCache
|
||||
|
@ -13,9 +14,9 @@ class FriendRemarkCache
|
|||
/**
|
||||
* 设置好友备注缓存
|
||||
*
|
||||
* @param int $user_id 用户ID
|
||||
* @param int $friend_id 好友ID
|
||||
* @param string $remark 好友备注
|
||||
* @param int $user_id 用户ID
|
||||
* @param int $friend_id 好友ID
|
||||
* @param string $remark 好友备注
|
||||
*/
|
||||
public static function set(int $user_id, int $friend_id, string $remark)
|
||||
{
|
||||
|
@ -25,8 +26,9 @@ class FriendRemarkCache
|
|||
/**
|
||||
* 获取好友备注
|
||||
*
|
||||
* @param int $user_id 用户ID
|
||||
* @param int $user_id 用户ID
|
||||
* @param int $friend_id 好友ID
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function get(int $user_id, int $friend_id)
|
||||
|
|
|
@ -4,6 +4,7 @@ namespace App\Cache;
|
|||
|
||||
/**
|
||||
* Class LastMsgCache
|
||||
*
|
||||
* @package App\Cache
|
||||
*/
|
||||
class LastMsgCache
|
||||
|
@ -12,6 +13,7 @@ class LastMsgCache
|
|||
* 用户聊天或群聊的最后一条消息hash存储的hash名
|
||||
*
|
||||
* @param int $sender
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private static function _name($sender = 0)
|
||||
|
@ -23,7 +25,8 @@ class LastMsgCache
|
|||
* 获取hash key
|
||||
*
|
||||
* @param int $receive 接收者
|
||||
* @param int $sender 发送者
|
||||
* @param int $sender 发送者
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private static function _key(int $receive, int $sender)
|
||||
|
@ -35,8 +38,8 @@ class LastMsgCache
|
|||
* 设置好友之间或群聊中发送的最后一条消息缓存
|
||||
*
|
||||
* @param array $message 消息内容
|
||||
* @param int $receive 接收者
|
||||
* @param int $sender 发送者(注:若聊天消息类型为群聊消息 $sender 应设置为0)
|
||||
* @param int $receive 接收者
|
||||
* @param int $sender 发送者(注:若聊天消息类型为群聊消息 $sender 应设置为0)
|
||||
*/
|
||||
public static function set(array $message, int $receive, $sender = 0)
|
||||
{
|
||||
|
@ -47,7 +50,8 @@ class LastMsgCache
|
|||
* 获取好友之间或群聊中发送的最后一条消息缓存
|
||||
*
|
||||
* @param int $receive 接收者
|
||||
* @param int $sender 发送者(注:若聊天消息类型为群聊消息 $sender 应设置为0)
|
||||
* @param int $sender 发送者(注:若聊天消息类型为群聊消息 $sender 应设置为0)
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function get(int $receive, $sender = 0)
|
||||
|
|
|
@ -4,6 +4,7 @@ namespace App\Cache;
|
|||
|
||||
/**
|
||||
* Class UnreadTalkCache
|
||||
*
|
||||
* @package App\Cache
|
||||
*/
|
||||
class UnreadTalkCache
|
||||
|
@ -13,8 +14,9 @@ class UnreadTalkCache
|
|||
/**
|
||||
* 设置用户未读消息(自增加1)
|
||||
*
|
||||
* @param int $user_id 用户ID
|
||||
* @param int $user_id 用户ID
|
||||
* @param string $friend_id 好友ID
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function setInc(int $user_id, string $friend_id)
|
||||
|
@ -27,8 +29,9 @@ class UnreadTalkCache
|
|||
/**
|
||||
* 获取用户指定好友的未读消息数
|
||||
*
|
||||
* @param int $user_id 用户ID
|
||||
* @param int $user_id 用户ID
|
||||
* @param string $friend_id 好友ID
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function get(int $user_id, string $friend_id)
|
||||
|
@ -40,6 +43,7 @@ class UnreadTalkCache
|
|||
* 获取用户未读消息列表
|
||||
*
|
||||
* @param int $user_id 用户ID
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getAll(int $user_id)
|
||||
|
@ -50,8 +54,9 @@ class UnreadTalkCache
|
|||
/**
|
||||
* 清除用户指定好友的未读消息
|
||||
*
|
||||
* @param int $user_id 用户ID
|
||||
* @param int $user_id 用户ID
|
||||
* @param string $friend_id 好友ID
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function del(int $user_id, string $friend_id)
|
||||
|
@ -63,6 +68,7 @@ class UnreadTalkCache
|
|||
* 清除用户所有好友未读数
|
||||
*
|
||||
* @param int $user_id
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function delAll(int $user_id)
|
||||
|
@ -74,6 +80,7 @@ class UnreadTalkCache
|
|||
* 获取缓存key
|
||||
*
|
||||
* @param int $user_id 用户ID
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function _key(int $user_id)
|
||||
|
|
|
@ -9,18 +9,20 @@
|
|||
* @author Yuandong<837215079@qq.com>
|
||||
* @link https://github.com/gzydong/hyperf-chat
|
||||
*/
|
||||
|
||||
namespace App\Constants;
|
||||
|
||||
/**
|
||||
* HTTP 响应状态码枚举
|
||||
*
|
||||
* Class ResponseCode
|
||||
*
|
||||
* @package App\Constants
|
||||
*/
|
||||
class ResponseCode
|
||||
{
|
||||
const SUCCESS = 200; // 接口处理成功
|
||||
const FAIL = 305; // 接口处理失败
|
||||
const FAIL = 305; // 接口处理失败
|
||||
|
||||
/**
|
||||
* Server Error!
|
||||
|
|
|
@ -16,6 +16,7 @@ namespace App\Constants;
|
|||
* WebSocket 消息事件枚举
|
||||
*
|
||||
* Class SocketConstants
|
||||
*
|
||||
* @package App\Constants
|
||||
*/
|
||||
class SocketConstants
|
||||
|
@ -56,11 +57,11 @@ class SocketConstants
|
|||
public static function getMap(): array
|
||||
{
|
||||
return [
|
||||
self::EVENT_TALK => '对话消息通知',
|
||||
self::EVENT_KEYBOARD => '键盘输入事件通知',
|
||||
self::EVENT_TALK => '对话消息通知',
|
||||
self::EVENT_KEYBOARD => '键盘输入事件通知',
|
||||
self::EVENT_ONLINE_STATUS => '用户在线状态通知',
|
||||
self::EVENT_REVOKE_TALK => '聊天消息撤销通知',
|
||||
self::EVENT_FRIEND_APPLY => '好友申请消息通知'
|
||||
self::EVENT_REVOKE_TALK => '聊天消息撤销通知',
|
||||
self::EVENT_FRIEND_APPLY => '好友申请消息通知'
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -78,15 +78,15 @@ class ArticleController extends CController
|
|||
$params1 = $this->request->inputs(['keyword', 'find_type', 'cid', 'page']);
|
||||
$this->validate($params1, [
|
||||
// 搜索关键词
|
||||
'keyword' => "present",
|
||||
'keyword' => "present",
|
||||
// 查询类型 $findType 1:获取近期日记 2:获取星标日记 3:获取指定分类文章 4:获取指定标签文章 5:获取已删除文章 6:关键词搜索
|
||||
'find_type' => 'required|in:0,1,2,3,4,5,6',
|
||||
// 分类ID
|
||||
'cid' => 'present|integer|min:-1',
|
||||
'page' => 'present|integer|min:1'
|
||||
'cid' => 'present|integer|min:-1',
|
||||
'page' => 'present|integer|min:1'
|
||||
]);
|
||||
|
||||
$params = [];
|
||||
$params = [];
|
||||
$params['find_type'] = $params1['find_type'];
|
||||
if (in_array($params1['find_type'], [3, 4])) {
|
||||
$params['class_id'] = $params1['cid'];
|
||||
|
@ -127,7 +127,7 @@ class ArticleController extends CController
|
|||
{
|
||||
$params = $this->request->inputs(['class_id', 'class_name']);
|
||||
$this->validate($params, [
|
||||
'class_id' => 'required|integer',
|
||||
'class_id' => 'required|integer',
|
||||
'class_name' => 'required|max:20'
|
||||
]);
|
||||
|
||||
|
@ -167,7 +167,7 @@ class ArticleController extends CController
|
|||
{
|
||||
$params = $this->request->inputs(['class_id', 'sort_type']);
|
||||
$this->validate($params, [
|
||||
'class_id' => 'required|integer',
|
||||
'class_id' => 'required|integer',
|
||||
'sort_type' => 'required|in:1,2'
|
||||
]);
|
||||
|
||||
|
@ -198,7 +198,7 @@ class ArticleController extends CController
|
|||
$params = $this->request->inputs(['class_id', 'toid']);
|
||||
$this->validate($params, [
|
||||
'class_id' => 'required|integer',
|
||||
'toid' => 'required|integer'
|
||||
'toid' => 'required|integer'
|
||||
]);
|
||||
|
||||
$isTrue = $this->articleService->mergeArticleClass($this->uid(), (int)$params['class_id'], (int)$params['toid']);
|
||||
|
@ -217,7 +217,7 @@ class ArticleController extends CController
|
|||
{
|
||||
$params = $this->request->inputs(['tag_id', 'tag_name']);
|
||||
$this->validate($params, [
|
||||
'tag_id' => 'required|integer|min:0',
|
||||
'tag_id' => 'required|integer|min:0',
|
||||
'tag_name' => 'required|max:20'
|
||||
]);
|
||||
|
||||
|
@ -257,19 +257,19 @@ class ArticleController extends CController
|
|||
$params = $this->request->all();
|
||||
$this->validate($params, [
|
||||
'article_id' => 'required|integer|min:0',
|
||||
'class_id' => 'required|integer|min:0',
|
||||
'title' => 'required|max:255',
|
||||
'content' => 'required',
|
||||
'class_id' => 'required|integer|min:0',
|
||||
'title' => 'required|max:255',
|
||||
'content' => 'required',
|
||||
'md_content' => 'required'
|
||||
]);
|
||||
|
||||
$id = $this->articleService->editArticle($this->uid(), (int)$params['article_id'], [
|
||||
'title' => $params['title'],
|
||||
'abstract' => mb_substr(strip_tags($params['content']), 0, 200),
|
||||
'class_id' => $params['class_id'],
|
||||
'image' => get_html_images($params['content']),
|
||||
'title' => $params['title'],
|
||||
'abstract' => mb_substr(strip_tags($params['content']), 0, 200),
|
||||
'class_id' => $params['class_id'],
|
||||
'image' => get_html_images($params['content']),
|
||||
'md_content' => htmlspecialchars($params['md_content']),
|
||||
'content' => htmlspecialchars($params['content'])
|
||||
'content' => htmlspecialchars($params['content'])
|
||||
]);
|
||||
|
||||
return $id
|
||||
|
@ -355,7 +355,7 @@ class ArticleController extends CController
|
|||
$params = $this->request->inputs(['article_id', 'class_id']);
|
||||
$this->validate($params, [
|
||||
'article_id' => 'required|integer|min:0',
|
||||
'class_id' => 'required|integer|min:0'
|
||||
'class_id' => 'required|integer|min:0'
|
||||
]);
|
||||
|
||||
$isTrue = $this->articleService->moveArticle(
|
||||
|
@ -379,7 +379,7 @@ class ArticleController extends CController
|
|||
$params = $this->request->inputs(['article_id', 'type']);
|
||||
$this->validate($params, [
|
||||
'article_id' => 'required|integer|min:0',
|
||||
'type' => 'required|in:1,2'
|
||||
'type' => 'required|in:1,2'
|
||||
]);
|
||||
|
||||
$isTrue = $this->articleService->setAsteriskArticle(
|
||||
|
@ -403,7 +403,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' => 'required|array'
|
||||
]);
|
||||
|
||||
$isTrue = $this->articleService->updateArticleTag($this->uid(), (int)$params['article_id'], $params['tags']);
|
||||
|
@ -450,9 +450,9 @@ class ArticleController extends CController
|
|||
}
|
||||
|
||||
$annex = [
|
||||
'file_suffix' => $file->getExtension(),
|
||||
'file_size' => $file->getSize(),
|
||||
'save_dir' => '',
|
||||
'file_suffix' => $file->getExtension(),
|
||||
'file_size' => $file->getSize(),
|
||||
'save_dir' => '',
|
||||
'original_name' => $file->getClientFilename()
|
||||
];
|
||||
|
||||
|
@ -466,7 +466,7 @@ class ArticleController extends CController
|
|||
}
|
||||
|
||||
$annex['save_dir'] = $path;
|
||||
$annex['id'] = $this->articleService->insertArticleAnnex($this->uid(), (int)$params['article_id'], $annex);
|
||||
$annex['id'] = $this->articleService->insertArticleAnnex($this->uid(), (int)$params['article_id'], $annex);
|
||||
if (!$annex['id']) {
|
||||
return $this->response->fail('附件上传失败,请稍后再试...');
|
||||
}
|
||||
|
@ -528,7 +528,7 @@ class ArticleController extends CController
|
|||
};
|
||||
|
||||
array_walk($rows, function (&$item) use ($getDay) {
|
||||
$item['day'] = $getDay($item['deleted_at']);
|
||||
$item['day'] = $getDay($item['deleted_at']);
|
||||
$item['visible'] = false;
|
||||
});
|
||||
}
|
||||
|
|
|
@ -57,7 +57,7 @@ class AuthController extends CController
|
|||
{
|
||||
$params = $this->request->inputs(['mobile', 'password', 'platform']);
|
||||
$this->validate($params, [
|
||||
'mobile' => "required|regex:/^1[345789][0-9]{9}$/",
|
||||
'mobile' => "required|regex:/^1[345789][0-9]{9}$/",
|
||||
'password' => 'required',
|
||||
'platform' => 'required|in:h5,ios,windows,mac,web',
|
||||
]);
|
||||
|
@ -69,7 +69,7 @@ class AuthController extends CController
|
|||
|
||||
try {
|
||||
$token = $this->jwt->getToken([
|
||||
'user_id' => $userInfo['id'],
|
||||
'user_id' => $userInfo['id'],
|
||||
'platform' => $params['platform'],
|
||||
]);
|
||||
} catch (\Exception $exception) {
|
||||
|
@ -79,14 +79,14 @@ class AuthController extends CController
|
|||
return $this->response->success([
|
||||
'authorize' => [
|
||||
'access_token' => $token,
|
||||
'expires_in' => $this->jwt->getTTL()
|
||||
'expires_in' => $this->jwt->getTTL()
|
||||
],
|
||||
'user_info' => [
|
||||
'nickname' => $userInfo['nickname'],
|
||||
'avatar' => $userInfo['avatar'],
|
||||
'gender' => $userInfo['gender'],
|
||||
'motto' => $userInfo['motto'],
|
||||
'email' => $userInfo['email'],
|
||||
'avatar' => $userInfo['avatar'],
|
||||
'gender' => $userInfo['gender'],
|
||||
'motto' => $userInfo['motto'],
|
||||
'email' => $userInfo['email'],
|
||||
]
|
||||
]);
|
||||
}
|
||||
|
@ -114,7 +114,7 @@ class AuthController extends CController
|
|||
$params = $this->request->all();
|
||||
$this->validate($params, [
|
||||
'nickname' => "required|max:20",
|
||||
'mobile' => "required|regex:/^1[345789][0-9]{9}$/",
|
||||
'mobile' => "required|regex:/^1[345789][0-9]{9}$/",
|
||||
'password' => 'required|max:16',
|
||||
'sms_code' => 'required|digits:6',
|
||||
'platform' => 'required|in:h5,ios,windows,mac,web',
|
||||
|
@ -125,7 +125,7 @@ class AuthController extends CController
|
|||
}
|
||||
|
||||
$isTrue = $this->userService->register([
|
||||
'mobile' => $params['mobile'],
|
||||
'mobile' => $params['mobile'],
|
||||
'password' => $params['password'],
|
||||
'nickname' => strip_tags($params['nickname']),
|
||||
]);
|
||||
|
@ -149,7 +149,7 @@ class AuthController extends CController
|
|||
{
|
||||
$params = $this->request->inputs(['mobile', 'password', 'sms_code']);
|
||||
$this->validate($params, [
|
||||
'mobile' => "required|regex:/^1[345789][0-9]{9}$/",
|
||||
'mobile' => "required|regex:/^1[345789][0-9]{9}$/",
|
||||
'password' => 'required|max:16',
|
||||
'sms_code' => 'required|digits:6',
|
||||
]);
|
||||
|
@ -179,7 +179,7 @@ class AuthController extends CController
|
|||
{
|
||||
return $this->response->success([
|
||||
'authorize' => [
|
||||
'token' => $this->jwt->refreshToken(),
|
||||
'token' => $this->jwt->refreshToken(),
|
||||
'expire' => $this->jwt->getTTL()
|
||||
]
|
||||
]);
|
||||
|
@ -194,7 +194,7 @@ class AuthController extends CController
|
|||
{
|
||||
$params = $this->request->inputs(['type', 'mobile']);
|
||||
$this->validate($params, [
|
||||
'type' => "required",
|
||||
'type' => "required",
|
||||
'mobile' => "required|regex:/^1[345789][0-9]{9}$/"
|
||||
]);
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@ use App\Support\Response;
|
|||
* 基类控制器
|
||||
*
|
||||
* Class CController
|
||||
*
|
||||
* @package App\Controller\Api\V1
|
||||
*/
|
||||
class CController extends AbstractController
|
||||
|
|
|
@ -83,6 +83,7 @@ class ContactsController extends CController
|
|||
* @RequestMapping(path="add", methods="post")
|
||||
*
|
||||
* @param UserService $userService
|
||||
*
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
public function addContact(UserService $userService)
|
||||
|
@ -90,7 +91,7 @@ class ContactsController extends CController
|
|||
$params = $this->request->inputs(['friend_id', 'remarks']);
|
||||
$this->validate($params, [
|
||||
'friend_id' => 'required|integer',
|
||||
'remarks' => 'present|max:50'
|
||||
'remarks' => 'present|max:50'
|
||||
]);
|
||||
|
||||
$user = $userService->findById($params['friend_id']);
|
||||
|
@ -111,11 +112,11 @@ class ContactsController extends CController
|
|||
$this->producer->produce(
|
||||
// 消息待完善
|
||||
new ChatMessageProducer(SocketConstants::EVENT_FRIEND_APPLY, [
|
||||
'sender' => $user_id,
|
||||
'sender' => $user_id,
|
||||
'receive' => intval($params['friend_id']),
|
||||
'type' => 1,
|
||||
'status' => 1,
|
||||
'remark' => ''
|
||||
'type' => 1,
|
||||
'status' => 1,
|
||||
'remark' => ''
|
||||
])
|
||||
);
|
||||
}
|
||||
|
@ -159,11 +160,11 @@ class ContactsController extends CController
|
|||
$params = $this->request->inputs(['apply_id', 'remarks']);
|
||||
$this->validate($params, [
|
||||
'apply_id' => 'required|integer',
|
||||
'remarks' => 'present|max:20'
|
||||
'remarks' => 'present|max:20'
|
||||
]);
|
||||
|
||||
$user_id = $this->uid();
|
||||
$isTrue = $this->contactsService->acceptInvitation($user_id, intval($params['apply_id']), $params['remarks']);
|
||||
$isTrue = $this->contactsService->acceptInvitation($user_id, intval($params['apply_id']), $params['remarks']);
|
||||
if (!$isTrue) {
|
||||
return $this->response->fail('处理失败...');
|
||||
}
|
||||
|
@ -177,11 +178,11 @@ class ContactsController extends CController
|
|||
// 待完善
|
||||
$this->producer->produce(
|
||||
new ChatMessageProducer(SocketConstants::EVENT_FRIEND_APPLY, [
|
||||
'sender' => $user_id,
|
||||
'sender' => $user_id,
|
||||
'receive' => $friend_id,
|
||||
'type' => 1,
|
||||
'status' => 1,
|
||||
'remark' => ''
|
||||
'type' => 1,
|
||||
'status' => 1,
|
||||
'remark' => ''
|
||||
])
|
||||
);
|
||||
}
|
||||
|
@ -199,7 +200,7 @@ class ContactsController extends CController
|
|||
$params = $this->request->inputs(['apply_id', 'remarks']);
|
||||
$this->validate($params, [
|
||||
'apply_id' => 'required|integer',
|
||||
'remarks' => 'present|max:20'
|
||||
'remarks' => 'present|max:20'
|
||||
]);
|
||||
|
||||
$isTrue = $this->contactsService->declineInvitation($this->uid(), intval($params['apply_id']), $params['remarks']);
|
||||
|
@ -250,13 +251,13 @@ class ContactsController extends CController
|
|||
{
|
||||
$params = $this->request->inputs(['page', 'page_size']);
|
||||
$this->validate($params, [
|
||||
'page' => 'present|integer',
|
||||
'page' => 'present|integer',
|
||||
'page_size' => 'present|integer'
|
||||
]);
|
||||
|
||||
$page = $this->request->input('page', 1);
|
||||
$page = $this->request->input('page', 1);
|
||||
$page_size = $this->request->input('page_size', 10);
|
||||
$user_id = $this->uid();
|
||||
$user_id = $this->uid();
|
||||
|
||||
$data = $this->contactsService->getContactApplyRecords($user_id, $page, $page_size);
|
||||
|
||||
|
@ -291,11 +292,11 @@ class ContactsController extends CController
|
|||
$params = $this->request->inputs(['friend_id', 'remarks']);
|
||||
$this->validate($params, [
|
||||
'friend_id' => 'required|integer|min:1',
|
||||
'remarks' => "required|max:20"
|
||||
'remarks' => "required|max:20"
|
||||
]);
|
||||
|
||||
$user_id = $this->uid();
|
||||
$isTrue = $this->contactsService->editContactRemark($user_id, intval($params['friend_id']), $params['remarks']);
|
||||
$isTrue = $this->contactsService->editContactRemark($user_id, intval($params['friend_id']), $params['remarks']);
|
||||
if (!$isTrue) {
|
||||
return $this->response->fail('备注修改失败...');
|
||||
}
|
||||
|
|
|
@ -40,7 +40,8 @@ class DownloadController extends CController
|
|||
* @RequestMapping(path="user-chat-file", methods="get")
|
||||
*
|
||||
* @param ResponseInterface $response
|
||||
* @param UploadService $uploadService
|
||||
* @param UploadService $uploadService
|
||||
*
|
||||
* @return \Psr\Http\Message\ResponseInterface
|
||||
*/
|
||||
public function userChatFile(ResponseInterface $response, UploadService $uploadService)
|
||||
|
@ -84,7 +85,8 @@ class DownloadController extends CController
|
|||
* @RequestMapping(path="article-annex", methods="get")
|
||||
*
|
||||
* @param ResponseInterface $response
|
||||
* @param UploadService $uploadService
|
||||
* @param UploadService $uploadService
|
||||
*
|
||||
* @return \Psr\Http\Message\ResponseInterface
|
||||
*/
|
||||
public function articleAnnex(ResponseInterface $response, UploadService $uploadService)
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
* @author Yuandong<837215079@qq.com>
|
||||
* @link https://github.com/gzydong/hyperf-chat
|
||||
*/
|
||||
|
||||
namespace App\Controller\Api\V1;
|
||||
|
||||
use Hyperf\Di\Annotation\Inject;
|
||||
|
@ -47,16 +48,16 @@ class EmoticonController extends CController
|
|||
public function getUserEmoticon()
|
||||
{
|
||||
$emoticonList = [];
|
||||
$user_id = $this->uid();
|
||||
$user_id = $this->uid();
|
||||
|
||||
if ($ids = $this->emoticonService->getInstallIds($user_id)) {
|
||||
$items = Emoticon::whereIn('id', $ids)->get(['id', 'name', 'url']);
|
||||
foreach ($items as $item) {
|
||||
$emoticonList[] = [
|
||||
'emoticon_id' => $item->id,
|
||||
'url' => get_media_url($item->url),
|
||||
'name' => $item->name,
|
||||
'list' => $this->emoticonService->getDetailsAll([
|
||||
'url' => get_media_url($item->url),
|
||||
'name' => $item->name,
|
||||
'list' => $this->emoticonService->getDetailsAll([
|
||||
['emoticon_id', '=', $item->id],
|
||||
['user_id', '=', 0]
|
||||
])
|
||||
|
@ -65,7 +66,7 @@ class EmoticonController extends CController
|
|||
}
|
||||
|
||||
return $this->response->success([
|
||||
'sys_emoticon' => $emoticonList,
|
||||
'sys_emoticon' => $emoticonList,
|
||||
'collect_emoticon' => $this->emoticonService->getDetailsAll([
|
||||
['emoticon_id', '=', 0],
|
||||
['user_id', '=', $user_id]
|
||||
|
@ -85,7 +86,7 @@ class EmoticonController extends CController
|
|||
$ids = $this->emoticonService->getInstallIds($this->uid());
|
||||
array_walk($items, function (&$item) use ($ids) {
|
||||
$item['status'] = in_array($item['id'], $ids) ? 1 : 0;
|
||||
$item['url'] = get_media_url($item['url']);
|
||||
$item['url'] = get_media_url($item['url']);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -102,7 +103,7 @@ class EmoticonController extends CController
|
|||
$params = $this->request->all();
|
||||
$this->validate($params, [
|
||||
'emoticon_id' => 'required|integer',
|
||||
'type' => 'required|in:1,2'
|
||||
'type' => 'required|in:1,2'
|
||||
]);
|
||||
|
||||
$user_id = $this->uid();
|
||||
|
@ -127,9 +128,9 @@ class EmoticonController extends CController
|
|||
|
||||
$data = [
|
||||
'emoticon_id' => $emoticonInfo->id,
|
||||
'url' => get_media_url($emoticonInfo->url),
|
||||
'name' => $emoticonInfo->name,
|
||||
'list' => $this->emoticonService->getDetailsAll([
|
||||
'url' => get_media_url($emoticonInfo->url),
|
||||
'name' => $emoticonInfo->name,
|
||||
'list' => $this->emoticonService->getDetailsAll([
|
||||
['emoticon_id', '=', $emoticonInfo->id]
|
||||
])
|
||||
];
|
||||
|
@ -144,6 +145,7 @@ class EmoticonController extends CController
|
|||
* @RequestMapping(path="upload-emoticon", methods="post")
|
||||
*
|
||||
* @param UploadService $uploadService
|
||||
*
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
public function uploadEmoticon(UploadService $uploadService)
|
||||
|
@ -176,11 +178,11 @@ class EmoticonController extends CController
|
|||
}
|
||||
|
||||
$result = EmoticonDetail::create([
|
||||
'user_id' => $this->uid(),
|
||||
'url' => $save_path,
|
||||
'user_id' => $this->uid(),
|
||||
'url' => $save_path,
|
||||
'file_suffix' => $ext,
|
||||
'file_size' => $file->getSize(),
|
||||
'created_at' => time()
|
||||
'file_size' => $file->getSize(),
|
||||
'created_at' => time()
|
||||
]);
|
||||
|
||||
if (!$result) {
|
||||
|
@ -189,7 +191,7 @@ class EmoticonController extends CController
|
|||
|
||||
return $this->response->success([
|
||||
'media_id' => $result->id,
|
||||
'src' => get_media_url($result->url)
|
||||
'src' => get_media_url($result->url)
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
* @author Yuandong<837215079@qq.com>
|
||||
* @link https://github.com/gzydong/hyperf-chat
|
||||
*/
|
||||
|
||||
namespace App\Controller\Api\V1;
|
||||
|
||||
use Hyperf\Di\Annotation\Inject;
|
||||
|
@ -91,7 +92,7 @@ class TalkController extends CController
|
|||
{
|
||||
$params = $this->request->inputs(['type', 'receive_id']);
|
||||
$this->validate($params, [
|
||||
'type' => 'required|in:1,2',
|
||||
'type' => 'required|in:1,2',
|
||||
'receive_id' => 'present|integer|min:0'
|
||||
]);
|
||||
|
||||
|
@ -112,35 +113,35 @@ class TalkController extends CController
|
|||
}
|
||||
|
||||
$data = [
|
||||
'id' => $result['id'],
|
||||
'type' => $result['type'],
|
||||
'group_id' => $result['group_id'],
|
||||
'friend_id' => $result['friend_id'],
|
||||
'is_top' => 0,
|
||||
'msg_text' => '',
|
||||
'id' => $result['id'],
|
||||
'type' => $result['type'],
|
||||
'group_id' => $result['group_id'],
|
||||
'friend_id' => $result['friend_id'],
|
||||
'is_top' => 0,
|
||||
'msg_text' => '',
|
||||
'not_disturb' => 0,
|
||||
'online' => 1,
|
||||
'name' => '',
|
||||
'online' => 1,
|
||||
'name' => '',
|
||||
'remark_name' => '',
|
||||
'avatar' => '',
|
||||
'unread_num' => 0,
|
||||
'updated_at' => date('Y-m-d H:i:s')
|
||||
'avatar' => '',
|
||||
'unread_num' => 0,
|
||||
'updated_at' => date('Y-m-d H:i:s')
|
||||
];
|
||||
|
||||
if ($result['type'] == 1) {
|
||||
$data['unread_num'] = $this->unreadTalkCache->get($user_id, $result['friend_id']);
|
||||
$userInfo = User::where('id', $user_id)->first(['nickname', 'avatar']);
|
||||
$data['name'] = $userInfo->nickname;
|
||||
$data['avatar'] = $userInfo->avatar;
|
||||
$userInfo = User::where('id', $user_id)->first(['nickname', 'avatar']);
|
||||
$data['name'] = $userInfo->nickname;
|
||||
$data['avatar'] = $userInfo->avatar;
|
||||
} else if ($result['type'] == 2) {
|
||||
$groupInfo = Group::where('id', $result['group_id'])->first(['group_name', 'avatar']);
|
||||
$data['name'] = $groupInfo->group_name;
|
||||
$groupInfo = Group::where('id', $result['group_id'])->first(['group_name', 'avatar']);
|
||||
$data['name'] = $groupInfo->group_name;
|
||||
$data['avatar'] = $groupInfo->avatar;
|
||||
}
|
||||
|
||||
$records = LastMsgCache::get($result['type'] == 1 ? $result['friend_id'] : $result['group_id'], $result['type'] == 1 ? $user_id : 0);
|
||||
if ($records) {
|
||||
$data['msg_text'] = $records['text'];
|
||||
$data['msg_text'] = $records['text'];
|
||||
$data['updated_at'] = $records['created_at'];
|
||||
}
|
||||
|
||||
|
@ -174,7 +175,7 @@ class TalkController extends CController
|
|||
$params = $this->request->inputs(['list_id', 'type']);
|
||||
$this->validate($params, [
|
||||
'list_id' => 'required|integer|min:0',
|
||||
'type' => 'required|in:1,2',
|
||||
'type' => 'required|in:1,2',
|
||||
]);
|
||||
|
||||
return UsersChatList::topItem($this->uid(), $params['list_id'], $params['type'] == 1)
|
||||
|
@ -191,8 +192,8 @@ class TalkController extends CController
|
|||
{
|
||||
$params = $this->request->inputs(['receive_id', 'type', 'not_disturb']);
|
||||
$this->validate($params, [
|
||||
'receive_id' => 'required|integer|min:0',
|
||||
'type' => 'required|in:1,2',
|
||||
'receive_id' => 'required|integer|min:0',
|
||||
'type' => 'required|in:1,2',
|
||||
'not_disturb' => 'required|in:0,1',
|
||||
]);
|
||||
|
||||
|
@ -213,7 +214,7 @@ class TalkController extends CController
|
|||
$params = $this->request->inputs(['receive', 'type']);
|
||||
$this->validate($params, [
|
||||
'receive' => 'required|integer|min:0',
|
||||
'type' => 'required|integer|min:0'
|
||||
'type' => 'required|integer|min:0'
|
||||
]);
|
||||
|
||||
// 设置好友消息未读数
|
||||
|
@ -259,8 +260,8 @@ class TalkController extends CController
|
|||
{
|
||||
$params = $this->request->inputs(['source', 'record_id', 'receive_id']);
|
||||
$this->validate($params, [
|
||||
'source' => 'required|in:1,2',//消息来源(1:好友消息 2:群聊消息)
|
||||
'record_id' => 'required|ids',
|
||||
'source' => 'required|in:1,2',//消息来源(1:好友消息 2:群聊消息)
|
||||
'record_id' => 'required|ids',
|
||||
'receive_id' => 'required|integer|min:0'
|
||||
]);
|
||||
|
||||
|
@ -288,11 +289,11 @@ class TalkController extends CController
|
|||
$params = $this->request->inputs(['source', 'records_ids', 'receive_id', 'forward_mode', 'receive_user_ids', 'receive_group_ids']);
|
||||
$this->validate($params, [
|
||||
//消息来源[1:好友消息 2:群聊消息]
|
||||
'source' => 'required|in:1,2',
|
||||
'source' => 'required|in:1,2',
|
||||
//聊天记录ID,多个逗号拼接
|
||||
'records_ids' => 'required',
|
||||
'records_ids' => 'required',
|
||||
//接收者ID(好友ID或者群聊ID)
|
||||
'receive_id' => 'required|integer|min:0',
|
||||
'receive_id' => 'required|integer|min:0',
|
||||
//转发方方式[1:逐条转发;2:合并转发]
|
||||
'forward_mode' => 'required|in:1,2',
|
||||
//转发的好友的ID
|
||||
|
@ -337,9 +338,9 @@ class TalkController extends CController
|
|||
foreach ($ids as $value) {
|
||||
$this->producer->produce(
|
||||
new ChatMessageProducer(SocketConstants::EVENT_TALK, [
|
||||
'sender' => $user_id, //发送者ID
|
||||
'receive' => intval($value['receive_id']), //接收者ID
|
||||
'source' => intval($value['source']), //接收者类型 1:好友;2:群组
|
||||
'sender' => $user_id, //发送者ID
|
||||
'receive' => intval($value['receive_id']), //接收者ID
|
||||
'source' => intval($value['source']), //接收者类型 1:好友;2:群组
|
||||
'record_id' => $value['record_id']
|
||||
])
|
||||
);
|
||||
|
@ -357,20 +358,20 @@ class TalkController extends CController
|
|||
{
|
||||
$params = $this->request->inputs(['record_id', 'source', 'receive_id']);
|
||||
$this->validate($params, [
|
||||
'source' => 'required|in:1,2',//消息来源(1:好友消息 2:群聊消息)
|
||||
'record_id' => 'required|integer|min:0',
|
||||
'source' => 'required|in:1,2',//消息来源(1:好友消息 2:群聊消息)
|
||||
'record_id' => 'required|integer|min:0',
|
||||
'receive_id' => 'required|integer|min:1',
|
||||
]);
|
||||
|
||||
$user_id = $this->uid();
|
||||
$limit = 30;
|
||||
$limit = 30;
|
||||
|
||||
// 判断是否属于群成员
|
||||
if ($params['source'] == 2 && Group::isMember($params['receive_id'], $user_id) == false) {
|
||||
return $this->response->success([
|
||||
'rows' => [],
|
||||
'rows' => [],
|
||||
'record_id' => 0,
|
||||
'limit' => $limit
|
||||
'limit' => $limit
|
||||
], '非群聊成员不能查看群聊信息...');
|
||||
}
|
||||
|
||||
|
@ -383,9 +384,9 @@ class TalkController extends CController
|
|||
);
|
||||
|
||||
return $this->response->success([
|
||||
'rows' => $result,
|
||||
'rows' => $result,
|
||||
'record_id' => $result ? end($result)['id'] : 0,
|
||||
'limit' => $limit
|
||||
'limit' => $limit
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -418,21 +419,21 @@ class TalkController extends CController
|
|||
{
|
||||
$params = $this->request->inputs(['record_id', 'source', 'receive_id', 'msg_type']);
|
||||
$this->validate($params, [
|
||||
'source' => 'required|in:1,2',//消息来源(1:好友消息 2:群聊消息)
|
||||
'record_id' => 'required|integer|min:0',
|
||||
'source' => 'required|in:1,2',//消息来源(1:好友消息 2:群聊消息)
|
||||
'record_id' => 'required|integer|min:0',
|
||||
'receive_id' => 'required|integer|min:1',
|
||||
'msg_type' => 'required|in:0,1,2,3,4,5,6',
|
||||
'msg_type' => 'required|in:0,1,2,3,4,5,6',
|
||||
]);
|
||||
|
||||
$user_id = $this->uid();
|
||||
$limit = 30;
|
||||
$limit = 30;
|
||||
|
||||
// 判断是否属于群成员
|
||||
if ($params['source'] == 2 && Group::isMember($params['receive_id'], $user_id) == false) {
|
||||
return $this->response->success([
|
||||
'rows' => [],
|
||||
'rows' => [],
|
||||
'record_id' => 0,
|
||||
'limit' => $limit
|
||||
'limit' => $limit
|
||||
], '非群聊成员不能查看群聊信息...');
|
||||
}
|
||||
|
||||
|
@ -452,9 +453,9 @@ class TalkController extends CController
|
|||
);
|
||||
|
||||
return $this->response->success([
|
||||
'rows' => $result,
|
||||
'rows' => $result,
|
||||
'record_id' => $result ? end($result)['id'] : 0,
|
||||
'limit' => $limit
|
||||
'limit' => $limit
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -484,6 +485,7 @@ class TalkController extends CController
|
|||
* @RequestMapping(path="send-image", methods="post")
|
||||
*
|
||||
* @param UploadService $uploadService
|
||||
*
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
public function sendImage(UploadService $uploadService)
|
||||
|
@ -491,7 +493,7 @@ class TalkController extends CController
|
|||
$params = $this->request->inputs(['source', 'receive_id']);
|
||||
$this->validate($params, [
|
||||
//消息来源(1:好友消息 2:群聊消息)
|
||||
'source' => 'required|in:1,2',
|
||||
'source' => 'required|in:1,2',
|
||||
'receive_id' => 'required|integer|min:1'
|
||||
]);
|
||||
|
||||
|
@ -517,16 +519,16 @@ class TalkController extends CController
|
|||
|
||||
// 创建图片消息记录
|
||||
$record_id = $this->talkService->createImgMessage([
|
||||
'source' => $params['source'],
|
||||
'msg_type' => 2,
|
||||
'user_id' => $user_id,
|
||||
'source' => $params['source'],
|
||||
'msg_type' => 2,
|
||||
'user_id' => $user_id,
|
||||
'receive_id' => $params['receive_id'],
|
||||
], [
|
||||
'user_id' => $user_id,
|
||||
'file_type' => 1,
|
||||
'file_suffix' => $ext,
|
||||
'file_size' => $file->getSize(),
|
||||
'save_dir' => $path,
|
||||
'user_id' => $user_id,
|
||||
'file_type' => 1,
|
||||
'file_suffix' => $ext,
|
||||
'file_size' => $file->getSize(),
|
||||
'save_dir' => $path,
|
||||
'original_name' => $file->getClientFilename(),
|
||||
]);
|
||||
|
||||
|
@ -537,17 +539,17 @@ class TalkController extends CController
|
|||
// ...消息推送队列
|
||||
$this->producer->produce(
|
||||
new ChatMessageProducer(SocketConstants::EVENT_TALK, [
|
||||
'sender' => $user_id, //发送者ID
|
||||
'receive' => intval($params['receive_id']), //接收者ID
|
||||
'source' => intval($params['source']), //接收者类型 1:好友;2:群组
|
||||
'sender' => $user_id, //发送者ID
|
||||
'receive' => intval($params['receive_id']), //接收者ID
|
||||
'source' => intval($params['source']), //接收者类型 1:好友;2:群组
|
||||
'record_id' => $record_id
|
||||
])
|
||||
);
|
||||
|
||||
LastMsgCache::set([
|
||||
'text' => '[图片消息]',
|
||||
'text' => '[图片消息]',
|
||||
'created_at' => date('Y-m-d H:i:s')
|
||||
],intval($params['receive_id']), $params['source'] == 1 ? $user_id : 0);
|
||||
], intval($params['receive_id']), $params['source'] == 1 ? $user_id : 0);
|
||||
|
||||
return $this->response->success();
|
||||
}
|
||||
|
@ -562,22 +564,22 @@ class TalkController extends CController
|
|||
$params = $this->request->inputs(['source', 'receive_id', 'lang', 'code']);
|
||||
$this->validate($params, [
|
||||
//消息来源(1:好友消息 2:群聊消息)
|
||||
'source' => 'required|in:1,2',
|
||||
'source' => 'required|in:1,2',
|
||||
'receive_id' => 'required|integer|min:1',
|
||||
'lang' => 'required',
|
||||
'code' => 'required'
|
||||
'lang' => 'required',
|
||||
'code' => 'required'
|
||||
]);
|
||||
|
||||
$user_id = $this->uid();
|
||||
$user_id = $this->uid();
|
||||
$record_id = $this->talkService->createCodeMessage([
|
||||
'source' => $params['source'],
|
||||
'msg_type' => 5,
|
||||
'user_id' => $user_id,
|
||||
'source' => $params['source'],
|
||||
'msg_type' => 5,
|
||||
'user_id' => $user_id,
|
||||
'receive_id' => $params['receive_id'],
|
||||
], [
|
||||
'user_id' => $user_id,
|
||||
'user_id' => $user_id,
|
||||
'code_lang' => $params['lang'],
|
||||
'code' => $params['code']
|
||||
'code' => $params['code']
|
||||
]);
|
||||
|
||||
if (!$record_id) {
|
||||
|
@ -587,17 +589,17 @@ class TalkController extends CController
|
|||
// ...消息推送队列
|
||||
$this->producer->produce(
|
||||
new ChatMessageProducer(SocketConstants::EVENT_TALK, [
|
||||
'sender' => $user_id, //发送者ID
|
||||
'receive' => intval($params['receive_id']), //接收者ID
|
||||
'source' => intval($params['source']), //接收者类型 1:好友;2:群组
|
||||
'sender' => $user_id, //发送者ID
|
||||
'receive' => intval($params['receive_id']), //接收者ID
|
||||
'source' => intval($params['source']), //接收者类型 1:好友;2:群组
|
||||
'record_id' => $record_id
|
||||
])
|
||||
);
|
||||
|
||||
LastMsgCache::set([
|
||||
'text' => '[代码消息]',
|
||||
'text' => '[代码消息]',
|
||||
'created_at' => date('Y-m-d H:i:s')
|
||||
],intval($params['receive_id']), $params['source'] == 1 ? $user_id : 0);
|
||||
], intval($params['receive_id']), $params['source'] == 1 ? $user_id : 0);
|
||||
|
||||
return $this->response->success();
|
||||
}
|
||||
|
@ -608,6 +610,7 @@ class TalkController extends CController
|
|||
* @RequestMapping(path="send-file", methods="post")
|
||||
*
|
||||
* @param UploadService $uploadService
|
||||
*
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
public function sendFile(UploadService $uploadService)
|
||||
|
@ -615,9 +618,9 @@ class TalkController extends CController
|
|||
$params = $this->request->inputs(['hash_name', 'receive_id', 'source']);
|
||||
$this->validate($params, [
|
||||
//消息来源(1:好友消息 2:群聊消息)
|
||||
'source' => 'required|in:1,2',
|
||||
'source' => 'required|in:1,2',
|
||||
'receive_id' => 'required|integer|min:1',
|
||||
'hash_name' => 'required',
|
||||
'hash_name' => 'required',
|
||||
]);
|
||||
|
||||
$user_id = $this->uid();
|
||||
|
@ -628,7 +631,7 @@ class TalkController extends CController
|
|||
}
|
||||
|
||||
$file_hash_name = uniqid() . Str::random(10) . '.' . $file->file_ext;
|
||||
$save_dir = "files/talks/" . date('Ymd') . '/' . $file_hash_name;
|
||||
$save_dir = "files/talks/" . date('Ymd') . '/' . $file_hash_name;
|
||||
|
||||
$uploadService->makeDirectory($uploadService->driver("files/talks/" . date('Ymd')));
|
||||
|
||||
|
@ -636,18 +639,18 @@ class TalkController extends CController
|
|||
@copy($uploadService->driver($file->save_dir), $uploadService->driver($save_dir));
|
||||
|
||||
$record_id = $this->talkService->createFileMessage([
|
||||
'source' => $params['source'],
|
||||
'msg_type' => 2,
|
||||
'user_id' => $user_id,
|
||||
'source' => $params['source'],
|
||||
'msg_type' => 2,
|
||||
'user_id' => $user_id,
|
||||
'receive_id' => $params['receive_id']
|
||||
], [
|
||||
'user_id' => $user_id,
|
||||
'file_source' => 1,
|
||||
'file_type' => 4,
|
||||
'user_id' => $user_id,
|
||||
'file_source' => 1,
|
||||
'file_type' => 4,
|
||||
'original_name' => $file->original_name,
|
||||
'file_suffix' => $file->file_ext,
|
||||
'file_size' => $file->file_size,
|
||||
'save_dir' => $save_dir,
|
||||
'file_suffix' => $file->file_ext,
|
||||
'file_size' => $file->file_size,
|
||||
'save_dir' => $save_dir,
|
||||
]);
|
||||
|
||||
if (!$record_id) {
|
||||
|
@ -657,17 +660,17 @@ class TalkController extends CController
|
|||
// ...消息推送队列
|
||||
$this->producer->produce(
|
||||
new ChatMessageProducer(SocketConstants::EVENT_TALK, [
|
||||
'sender' => $user_id, //发送者ID
|
||||
'receive' => intval($params['receive_id']), //接收者ID
|
||||
'source' => intval($params['source']), //接收者类型 1:好友;2:群组
|
||||
'sender' => $user_id, //发送者ID
|
||||
'receive' => intval($params['receive_id']), //接收者ID
|
||||
'source' => intval($params['source']), //接收者类型 1:好友;2:群组
|
||||
'record_id' => $record_id
|
||||
])
|
||||
);
|
||||
|
||||
LastMsgCache::set([
|
||||
'text' => '[文件消息]',
|
||||
'text' => '[文件消息]',
|
||||
'created_at' => date('Y-m-d H:i:s')
|
||||
],intval($params['receive_id']), $params['source'] == 1 ? $user_id : 0);
|
||||
], intval($params['receive_id']), $params['source'] == 1 ? $user_id : 0);
|
||||
|
||||
return $this->response->success();
|
||||
}
|
||||
|
@ -682,12 +685,12 @@ class TalkController extends CController
|
|||
$params = $this->request->inputs(['source', 'receive_id', 'emoticon_id']);
|
||||
$this->validate($params, [
|
||||
//消息来源(1:好友消息 2:群聊消息)
|
||||
'source' => 'required|in:1,2',
|
||||
'receive_id' => 'required|integer|min:1',
|
||||
'source' => 'required|in:1,2',
|
||||
'receive_id' => 'required|integer|min:1',
|
||||
'emoticon_id' => 'required|integer|min:1',
|
||||
]);
|
||||
|
||||
$user_id = $this->uid();
|
||||
$user_id = $this->uid();
|
||||
$emoticon = EmoticonDetail::where('id', $params['emoticon_id'])->where('user_id', $user_id)->first([
|
||||
'url', 'file_suffix', 'file_size'
|
||||
]);
|
||||
|
@ -697,16 +700,16 @@ class TalkController extends CController
|
|||
}
|
||||
|
||||
$record_id = $this->talkService->createEmoticonMessage([
|
||||
'source' => $params['source'],
|
||||
'msg_type' => 2,
|
||||
'user_id' => $user_id,
|
||||
'source' => $params['source'],
|
||||
'msg_type' => 2,
|
||||
'user_id' => $user_id,
|
||||
'receive_id' => $params['receive_id'],
|
||||
], [
|
||||
'user_id' => $user_id,
|
||||
'file_type' => 1,
|
||||
'file_suffix' => $emoticon->file_suffix,
|
||||
'file_size' => $emoticon->file_size,
|
||||
'save_dir' => $emoticon->url,
|
||||
'user_id' => $user_id,
|
||||
'file_type' => 1,
|
||||
'file_suffix' => $emoticon->file_suffix,
|
||||
'file_size' => $emoticon->file_size,
|
||||
'save_dir' => $emoticon->url,
|
||||
'original_name' => '表情',
|
||||
]);
|
||||
|
||||
|
@ -717,17 +720,17 @@ class TalkController extends CController
|
|||
// ...消息推送队列
|
||||
$this->producer->produce(
|
||||
new ChatMessageProducer(SocketConstants::EVENT_TALK, [
|
||||
'sender' => $user_id, //发送者ID
|
||||
'receive' => intval($params['receive_id']), //接收者ID
|
||||
'source' => intval($params['source']), //接收者类型 1:好友;2:群组
|
||||
'sender' => $user_id, //发送者ID
|
||||
'receive' => intval($params['receive_id']), //接收者ID
|
||||
'source' => intval($params['source']), //接收者类型 1:好友;2:群组
|
||||
'record_id' => $record_id
|
||||
])
|
||||
);
|
||||
|
||||
LastMsgCache::set([
|
||||
'text' => '[表情包消息]',
|
||||
'text' => '[表情包消息]',
|
||||
'created_at' => date('Y-m-d H:i:s')
|
||||
],intval($params['receive_id']), $params['source'] == 1 ? $user_id : 0);
|
||||
], intval($params['receive_id']), $params['source'] == 1 ? $user_id : 0);
|
||||
|
||||
return $this->response->success();
|
||||
}
|
||||
|
|
|
@ -56,7 +56,7 @@ class UploadController extends CController
|
|||
public function fileStream()
|
||||
{
|
||||
$fileStream = $this->request->post('fileStream', '');
|
||||
$data = base64_decode(str_replace(['data:image/png;base64,', ' '], ['', '+'], $fileStream));
|
||||
$data = base64_decode(str_replace(['data:image/png;base64,', ' '], ['', '+'], $fileStream));
|
||||
|
||||
$path = '/media/images/avatar/' . date('Ymd') . '/' . uniqid() . date('His') . '.png';
|
||||
$this->uploadService->makeDirectory($this->uploadService->driver('/media/images/avatar/' . date('Ymd') . '/'));
|
||||
|
@ -89,22 +89,22 @@ class UploadController extends CController
|
|||
*/
|
||||
public function fileSubareaUpload()
|
||||
{
|
||||
$file = $this->request->file('file');
|
||||
$file = $this->request->file('file');
|
||||
$params = $this->request->inputs(['name', 'hash', 'ext', 'size', 'split_index', 'split_num']);
|
||||
$this->validate($params, [
|
||||
'name' => "required",
|
||||
'hash' => 'required',
|
||||
'ext' => 'required',
|
||||
'size' => 'required',
|
||||
'name' => "required",
|
||||
'hash' => 'required',
|
||||
'ext' => 'required',
|
||||
'size' => 'required',
|
||||
'split_index' => 'required',
|
||||
'split_num' => 'required'
|
||||
'split_num' => 'required'
|
||||
]);
|
||||
|
||||
if (!$file->isValid()) {
|
||||
return $this->response->fail();
|
||||
}
|
||||
|
||||
$user_id = $this->uid();
|
||||
$user_id = $this->uid();
|
||||
$uploadRes = $this->splitUploadService->upload($user_id, $file, $params['hash'], intval($params['split_index']), intval($params['size']));
|
||||
if (!$uploadRes) {
|
||||
return $this->response->fail('上传文件失败...');
|
||||
|
@ -118,7 +118,7 @@ class UploadController extends CController
|
|||
|
||||
return $this->response->success([
|
||||
'is_file_merge' => true,
|
||||
'hash' => $params['hash']
|
||||
'hash' => $params['hash']
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
* @author Yuandong<837215079@qq.com>
|
||||
* @link https://github.com/gzydong/hyperf-chat
|
||||
*/
|
||||
|
||||
namespace App\Controller\Api\V1;
|
||||
|
||||
use Hyperf\Di\Annotation\Inject;
|
||||
|
@ -49,12 +50,12 @@ class UsersController extends CController
|
|||
{
|
||||
$userInfo = $this->userService->findById($this->uid(), ['mobile', 'nickname', 'avatar', 'motto', 'email', 'gender']);
|
||||
return $this->response->success([
|
||||
'mobile' => $userInfo->mobile,
|
||||
'mobile' => $userInfo->mobile,
|
||||
'nickname' => $userInfo->nickname,
|
||||
'avatar' => $userInfo->avatar,
|
||||
'motto' => $userInfo->motto,
|
||||
'email' => $userInfo->email,
|
||||
'gender' => $userInfo->gender
|
||||
'avatar' => $userInfo->avatar,
|
||||
'motto' => $userInfo->motto,
|
||||
'email' => $userInfo->email,
|
||||
'gender' => $userInfo->gender
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -68,17 +69,17 @@ class UsersController extends CController
|
|||
$userInfo = $this->userService->findById($this->uid(), ['id', 'nickname', 'avatar', 'motto', 'gender']);
|
||||
return $this->response->success([
|
||||
'user_info' => [
|
||||
'uid' => $userInfo->id,
|
||||
'uid' => $userInfo->id,
|
||||
'nickname' => $userInfo->nickname,
|
||||
'avatar' => $userInfo->avatar,
|
||||
'motto' => $userInfo->motto,
|
||||
'gender' => $userInfo->gender
|
||||
'avatar' => $userInfo->avatar,
|
||||
'motto' => $userInfo->motto,
|
||||
'gender' => $userInfo->gender
|
||||
],
|
||||
'setting' => [
|
||||
'theme_mode' => '',
|
||||
'theme_bag_img' => '',
|
||||
'theme_color' => '',
|
||||
'notify_cue_tone' => '',
|
||||
'setting' => [
|
||||
'theme_mode' => '',
|
||||
'theme_bag_img' => '',
|
||||
'theme_color' => '',
|
||||
'notify_cue_tone' => '',
|
||||
'keyboard_event_notify' => ''
|
||||
]
|
||||
]);
|
||||
|
@ -94,9 +95,9 @@ class UsersController extends CController
|
|||
$params = $this->request->inputs(['nickname', 'avatar', 'motto', 'gender']);
|
||||
$this->validate($params, [
|
||||
'nickname' => 'required',
|
||||
'motto' => 'present|max:100',
|
||||
'gender' => 'required|in:0,1,2',
|
||||
'avatar' => 'present|url'
|
||||
'motto' => 'present|max:100',
|
||||
'gender' => 'required|in:0,1,2',
|
||||
'avatar' => 'present|url'
|
||||
]);
|
||||
|
||||
$isTrue = User::where('id', $this->uid())->update($params);
|
||||
|
@ -135,7 +136,7 @@ class UsersController extends CController
|
|||
$params = $this->request->inputs(['user_id']);
|
||||
$this->validate($params, ['user_id' => 'required|integer']);
|
||||
|
||||
if ($data = $this->userService->getUserCard($params['user_id'],$this->uid())) {
|
||||
if ($data = $this->userService->getUserCard($params['user_id'], $this->uid())) {
|
||||
return $this->response->success($data);
|
||||
}
|
||||
|
||||
|
@ -174,13 +175,14 @@ class UsersController extends CController
|
|||
* @RequestMapping(path="change-mobile", methods="post")
|
||||
*
|
||||
* @param SmsCodeService $smsCodeService
|
||||
*
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
public function editUserMobile(SmsCodeService $smsCodeService)
|
||||
{
|
||||
$params = $this->request->inputs(['mobile', 'password', 'sms_code']);
|
||||
$this->validate($params, [
|
||||
'mobile' => "required|regex:/^1[345789][0-9]{9}$/",
|
||||
'mobile' => "required|regex:/^1[345789][0-9]{9}$/",
|
||||
'password' => 'required',
|
||||
'sms_code' => 'required|digits:6'
|
||||
]);
|
||||
|
@ -214,8 +216,8 @@ class UsersController extends CController
|
|||
{
|
||||
$params = $this->request->inputs(['email', 'password', 'email_code']);
|
||||
$this->validate($params, [
|
||||
'email' => 'required|email',
|
||||
'password' => 'required',
|
||||
'email' => 'required|email',
|
||||
'password' => 'required',
|
||||
'email_code' => 'required|digits:6'
|
||||
]);
|
||||
|
||||
|
@ -224,7 +226,7 @@ class UsersController extends CController
|
|||
return $this->response->fail('验证码填写错误...');
|
||||
}
|
||||
|
||||
$uid = $this->uid();
|
||||
$uid = $this->uid();
|
||||
$user_password = User::where('id', $uid)->value('password');
|
||||
if (!Hash::check($params['password'], $user_password)) {
|
||||
return $this->response->fail('账号密码验证失败...');
|
||||
|
@ -246,6 +248,7 @@ class UsersController extends CController
|
|||
* @RequestMapping(path="send-mobile-code", methods="post")
|
||||
*
|
||||
* @param SmsCodeService $smsCodeService
|
||||
*
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
public function sendMobileCode(SmsCodeService $smsCodeService)
|
||||
|
@ -283,6 +286,7 @@ class UsersController extends CController
|
|||
* @RequestMapping(path="send-change-email-code", methods="post")
|
||||
*
|
||||
* @param SendEmailCode $sendEmailCode
|
||||
*
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
public function sendChangeEmailCode(SendEmailCode $sendEmailCode)
|
||||
|
|
|
@ -19,11 +19,11 @@ class IndexController extends AbstractController
|
|||
{
|
||||
public function index(ResponseInterface $response)
|
||||
{
|
||||
$user = $this->request->input('user', 'Hyperf');
|
||||
$user = $this->request->input('user', 'Hyperf');
|
||||
$method = $this->request->getMethod();
|
||||
|
||||
return [
|
||||
'method' => $method,
|
||||
'method' => $method,
|
||||
'message' => "Hello {$user}.",
|
||||
];
|
||||
}
|
||||
|
|
|
@ -33,6 +33,7 @@ use App\Support\SocketIOParser;
|
|||
|
||||
/**
|
||||
* Class WebSocketController
|
||||
*
|
||||
* @package App\Controller
|
||||
*/
|
||||
class WebSocketController implements OnMessageInterface, OnOpenInterface, OnCloseInterface
|
||||
|
@ -71,7 +72,7 @@ class WebSocketController implements OnMessageInterface, OnOpenInterface, OnClos
|
|||
* 消息事件绑定
|
||||
*/
|
||||
const EVENTS = [
|
||||
SocketConstants::EVENT_TALK => 'onTalk',
|
||||
SocketConstants::EVENT_TALK => 'onTalk',
|
||||
SocketConstants::EVENT_KEYBOARD => 'onKeyboard',
|
||||
];
|
||||
|
||||
|
@ -79,11 +80,11 @@ class WebSocketController implements OnMessageInterface, OnOpenInterface, OnClos
|
|||
* 连接创建成功回调事件
|
||||
*
|
||||
* @param Response|Server $server
|
||||
* @param Request $request
|
||||
* @param Request $request
|
||||
*/
|
||||
public function onOpen($server, Request $request): void
|
||||
{
|
||||
$token = $request->get['token'] ?? '';
|
||||
$token = $request->get['token'] ?? '';
|
||||
$userInfo = $this->jwt->getParserData($token);
|
||||
stdout_log()->notice("用户连接信息 : user_id:{$userInfo['user_id']} | fd:{$request->fd} 时间:" . date('Y-m-d H:i:s'));
|
||||
|
||||
|
@ -109,8 +110,8 @@ class WebSocketController implements OnMessageInterface, OnOpenInterface, OnClos
|
|||
$this->producer->produce(
|
||||
new ChatMessageProducer(SocketConstants::EVENT_ONLINE_STATUS, [
|
||||
'user_id' => $userInfo['user_id'],
|
||||
'status' => 1,
|
||||
'notify' => '好友上线通知...'
|
||||
'status' => 1,
|
||||
'notify' => '好友上线通知...'
|
||||
])
|
||||
);
|
||||
}
|
||||
|
@ -120,7 +121,7 @@ class WebSocketController implements OnMessageInterface, OnOpenInterface, OnClos
|
|||
* 消息接收回调事件
|
||||
*
|
||||
* @param Response|Server $server
|
||||
* @param Frame $frame
|
||||
* @param Frame $frame
|
||||
*/
|
||||
public function onMessage($server, Frame $frame): void
|
||||
{
|
||||
|
@ -148,8 +149,8 @@ class WebSocketController implements OnMessageInterface, OnOpenInterface, OnClos
|
|||
* 连接创建成功回调事件
|
||||
*
|
||||
* @param Response|\Swoole\Server $server
|
||||
* @param int $fd
|
||||
* @param int $reactorId
|
||||
* @param int $fd
|
||||
* @param int $reactorId
|
||||
*/
|
||||
public function onClose($server, int $fd, int $reactorId): void
|
||||
{
|
||||
|
@ -167,8 +168,8 @@ class WebSocketController implements OnMessageInterface, OnOpenInterface, OnClos
|
|||
$this->producer->produce(
|
||||
new ChatMessageProducer(SocketConstants::EVENT_ONLINE_STATUS, [
|
||||
'user_id' => $user_id,
|
||||
'status' => 0,
|
||||
'notify' => '好友离线通知通知...'
|
||||
'status' => 0,
|
||||
'notify' => '好友离线通知通知...'
|
||||
])
|
||||
);
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ class AppExceptionHandler extends ExceptionHandler
|
|||
$this->logger->error($throwable->getTraceAsString());
|
||||
|
||||
$data = json_encode([
|
||||
'code' => ResponseCode::SERVER_ERROR,
|
||||
'code' => ResponseCode::SERVER_ERROR,
|
||||
'message' => 'Internal Server Error.'
|
||||
], JSON_UNESCAPED_UNICODE);
|
||||
|
||||
|
@ -38,6 +38,7 @@ class AppExceptionHandler extends ExceptionHandler
|
|||
|
||||
/**
|
||||
* @param Throwable $throwable
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isValid(Throwable $throwable): bool
|
||||
|
|
|
@ -11,6 +11,7 @@ use Hyperf\WebSocketServer\Exception\WebSocketHandeShakeException;
|
|||
|
||||
/**
|
||||
* Class JwtAuthExceptionHandler
|
||||
*
|
||||
* @package App\Exception\Handler
|
||||
*/
|
||||
class JwtAuthExceptionHandler extends ExceptionHandler
|
||||
|
@ -21,9 +22,9 @@ class JwtAuthExceptionHandler extends ExceptionHandler
|
|||
if ($throwable instanceof TokenValidException) {
|
||||
// 格式化输出
|
||||
$data = json_encode([
|
||||
'code' => $throwable->getCode(),
|
||||
'code' => $throwable->getCode(),
|
||||
'message' => $throwable->getMessage(),
|
||||
'data' => []
|
||||
'data' => []
|
||||
], JSON_UNESCAPED_UNICODE);
|
||||
|
||||
// 阻止异常冒泡
|
||||
|
@ -38,6 +39,7 @@ class JwtAuthExceptionHandler extends ExceptionHandler
|
|||
* 判断该异常处理器是否要对该异常进行处理
|
||||
*
|
||||
* @param Throwable $throwable
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isValid(Throwable $throwable): bool
|
||||
|
|
|
@ -12,13 +12,15 @@ use Throwable;
|
|||
* 验证器异常处理类
|
||||
*
|
||||
* Class ValidateExceptionHandler
|
||||
*
|
||||
* @package App\Exception\Handler
|
||||
*/
|
||||
class ValidateExceptionHandler extends ExceptionHandler
|
||||
{
|
||||
/**
|
||||
* @param Throwable $throwable
|
||||
* @param Throwable $throwable
|
||||
* @param ResponseInterface $response
|
||||
*
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
public function handle(Throwable $throwable, ResponseInterface $response)
|
||||
|
@ -27,9 +29,9 @@ class ValidateExceptionHandler extends ExceptionHandler
|
|||
if ($throwable instanceof ValidateException) {
|
||||
// 格式化输出
|
||||
$data = json_encode([
|
||||
'code' => $throwable->getCode(),
|
||||
'code' => $throwable->getCode(),
|
||||
'message' => $throwable->getMessage(),
|
||||
'data' => []
|
||||
'data' => []
|
||||
], JSON_UNESCAPED_UNICODE);
|
||||
|
||||
// 阻止异常冒泡
|
||||
|
@ -45,6 +47,7 @@ class ValidateExceptionHandler extends ExceptionHandler
|
|||
* 判断该异常处理器是否要对该异常进行处理
|
||||
*
|
||||
* @param Throwable $throwable
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isValid(Throwable $throwable): bool
|
||||
|
|
|
@ -23,13 +23,13 @@ class WebSocketExceptionHandler extends ExceptionHandler
|
|||
|
||||
public function __construct(StdoutLoggerInterface $logger, FormatterInterface $formatter)
|
||||
{
|
||||
$this->logger = $logger;
|
||||
$this->logger = $logger;
|
||||
$this->formatter = $formatter;
|
||||
}
|
||||
|
||||
public function handle(Throwable $throwable, ResponseInterface $response)
|
||||
{
|
||||
$stream = new SwooleStream((string) $throwable->getMessage());
|
||||
$stream = new SwooleStream((string)$throwable->getMessage());
|
||||
return $response->withBody($stream);
|
||||
}
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
* @author Yuandong<837215079@qq.com>
|
||||
* @link https://github.com/gzydong/hyperf-chat
|
||||
*/
|
||||
|
||||
namespace App\Exception;
|
||||
|
||||
use Hyperf\Server\Exception\ServerException;
|
||||
|
@ -17,6 +18,7 @@ use Hyperf\Server\Exception\ServerException;
|
|||
* 验证器异常类
|
||||
*
|
||||
* Class ValidateException
|
||||
*
|
||||
* @package App\Exception
|
||||
*/
|
||||
class ValidateException extends ServerException
|
||||
|
|
|
@ -23,6 +23,7 @@ class Hash
|
|||
* Hash the given value.
|
||||
*
|
||||
* @param string $value
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function make(string $value)
|
||||
|
@ -35,6 +36,7 @@ class Hash
|
|||
*
|
||||
* @param string $value
|
||||
* @param string $hashedValue
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function check(string $value, string $hashedValue)
|
||||
|
|
|
@ -44,6 +44,7 @@ class HashIdsHelper
|
|||
* 加密
|
||||
*
|
||||
* @param mixed ...$numbers
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function encode(...$numbers)
|
||||
|
@ -55,6 +56,7 @@ class HashIdsHelper
|
|||
* 解密
|
||||
*
|
||||
* @param string $hash
|
||||
*
|
||||
* @return array|mixed
|
||||
* @throws \Exception
|
||||
*/
|
||||
|
|
|
@ -17,6 +17,7 @@ namespace App\Helper;
|
|||
* 字符串助手类
|
||||
*
|
||||
* Class StringHelper
|
||||
*
|
||||
* @package App\Helper
|
||||
*/
|
||||
class StringHelper
|
||||
|
@ -25,6 +26,7 @@ class StringHelper
|
|||
* 将字符串转换成二进制
|
||||
*
|
||||
* @param string $str
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function str2Bin(string $str): string
|
||||
|
@ -34,7 +36,7 @@ class StringHelper
|
|||
//unpack字符
|
||||
foreach ($arr as &$v) {
|
||||
$temp = unpack('H*', $v);
|
||||
$v = base_convert($temp[1], 16, 2);
|
||||
$v = base_convert($temp[1], 16, 2);
|
||||
unset($temp);
|
||||
}
|
||||
|
||||
|
@ -45,6 +47,7 @@ class StringHelper
|
|||
* 将二进制转换成字符串
|
||||
*
|
||||
* @param string $str
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function bin2Str(string $str): string
|
||||
|
|
|
@ -9,6 +9,7 @@ declare(strict_types=1);
|
|||
* @contact group@hyperf.io
|
||||
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
|
||||
*/
|
||||
|
||||
namespace App\Listener;
|
||||
|
||||
use Hyperf\Database\Events\QueryExecuted;
|
||||
|
@ -49,7 +50,7 @@ class DbQueryExecutedListener implements ListenerInterface
|
|||
{
|
||||
if ($event instanceof QueryExecuted) {
|
||||
$sql = $event->sql;
|
||||
if (! Arr::isAssoc($event->bindings)) {
|
||||
if (!Arr::isAssoc($event->bindings)) {
|
||||
foreach ($event->bindings as $key => $value) {
|
||||
$sql = Str::replaceFirst('?', "'{$value}'", $sql);
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ declare(strict_types=1);
|
|||
* @contact group@hyperf.io
|
||||
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
|
||||
*/
|
||||
|
||||
namespace App\Listener;
|
||||
|
||||
use Hyperf\AsyncQueue\Event\AfterHandle;
|
||||
|
@ -38,7 +39,7 @@ class QueueHandleListener implements ListenerInterface
|
|||
|
||||
public function __construct(LoggerFactory $loggerFactory, FormatterInterface $formatter)
|
||||
{
|
||||
$this->logger = $loggerFactory->get('queue');
|
||||
$this->logger = $loggerFactory->get('queue');
|
||||
$this->formatter = $formatter;
|
||||
}
|
||||
|
||||
|
@ -55,9 +56,9 @@ class QueueHandleListener implements ListenerInterface
|
|||
public function process(object $event)
|
||||
{
|
||||
if ($event instanceof Event && $event->message->job()) {
|
||||
$job = $event->message->job();
|
||||
$job = $event->message->job();
|
||||
$jobClass = get_class($job);
|
||||
$date = date('Y-m-d H:i:s');
|
||||
$date = date('Y-m-d H:i:s');
|
||||
|
||||
switch (true) {
|
||||
case $event instanceof BeforeHandle:
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
* @author Yuandong<837215079@qq.com>
|
||||
* @link https://github.com/gzydong/hyperf-chat
|
||||
*/
|
||||
|
||||
namespace App\Middleware;
|
||||
|
||||
use Hyperf\HttpServer\Contract\RequestInterface;
|
||||
|
@ -46,8 +47,8 @@ class JWTAuthMiddleware implements MiddlewareInterface
|
|||
public function __construct(HttpResponse $response, RequestInterface $request, JWT $jwt)
|
||||
{
|
||||
$this->response = $response;
|
||||
$this->request = $request;
|
||||
$this->jwt = $jwt;
|
||||
$this->request = $request;
|
||||
$this->jwt = $jwt;
|
||||
}
|
||||
|
||||
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
|
||||
|
@ -73,7 +74,7 @@ class JWTAuthMiddleware implements MiddlewareInterface
|
|||
|
||||
if (!$isValidToken) {
|
||||
return $this->response->withStatus(401)->json([
|
||||
'code' => 401,
|
||||
'code' => 401,
|
||||
'message' => 'Token authentication does not pass',
|
||||
]);
|
||||
}
|
||||
|
|
|
@ -9,18 +9,18 @@ use App\Model\BaseModel;
|
|||
/**
|
||||
* 笔记数据表模型
|
||||
*
|
||||
* @property integer $id 笔记ID
|
||||
* @property integer $user_id 用户ID
|
||||
* @property integer $class_id 分类ID
|
||||
* @property string $tags_id 笔记标签ID
|
||||
* @property string $title 笔记标题
|
||||
* @property string $abstract 笔记摘要
|
||||
* @property string $image 笔记头图
|
||||
* @property integer $id 笔记ID
|
||||
* @property integer $user_id 用户ID
|
||||
* @property integer $class_id 分类ID
|
||||
* @property string $tags_id 笔记标签ID
|
||||
* @property string $title 笔记标题
|
||||
* @property string $abstract 笔记摘要
|
||||
* @property string $image 笔记头图
|
||||
* @property integer $is_asterisk 是否标记星号
|
||||
* @property integer $status 笔记状态
|
||||
* @property string $created_at 创建时间
|
||||
* @property string $updated_at 更新时间
|
||||
* @property string $deleted_at 删除时间
|
||||
* @property integer $status 笔记状态
|
||||
* @property string $created_at 创建时间
|
||||
* @property string $updated_at 更新时间
|
||||
* @property string $deleted_at 删除时间
|
||||
*
|
||||
* @package App\Model\Article
|
||||
*/
|
||||
|
@ -56,13 +56,13 @@ class Article extends BaseModel
|
|||
* @var array
|
||||
*/
|
||||
protected $casts = [
|
||||
'id' => 'integer',
|
||||
'user_id' => 'integer',
|
||||
'class_id' => 'integer',
|
||||
'id' => 'integer',
|
||||
'user_id' => 'integer',
|
||||
'class_id' => 'integer',
|
||||
'is_asterisk' => 'integer',
|
||||
'status' => 'integer',
|
||||
'created_at' => 'datetime',
|
||||
'updated_at' => 'datetime'
|
||||
'status' => 'integer',
|
||||
'created_at' => 'datetime',
|
||||
'updated_at' => 'datetime'
|
||||
];
|
||||
|
||||
/**
|
||||
|
|
|
@ -9,16 +9,16 @@ use App\Model\BaseModel;
|
|||
/**
|
||||
* 笔记附件数据表模型
|
||||
*
|
||||
* @property integer $id 笔记附件ID
|
||||
* @property integer $user_id 用户ID
|
||||
* @property integer $article_id 笔记ID
|
||||
* @property string $file_suffix 文件后缀名
|
||||
* @property int $file_size 文件大小
|
||||
* @property string $save_dir 文件相对路径
|
||||
* @property string $original_name 文件原名
|
||||
* @property integer $status 文件状态
|
||||
* @property string $created_at 上传时间
|
||||
* @property string $deleted_at 删除时间
|
||||
* @property integer $id 笔记附件ID
|
||||
* @property integer $user_id 用户ID
|
||||
* @property integer $article_id 笔记ID
|
||||
* @property string $file_suffix 文件后缀名
|
||||
* @property int $file_size 文件大小
|
||||
* @property string $save_dir 文件相对路径
|
||||
* @property string $original_name 文件原名
|
||||
* @property integer $status 文件状态
|
||||
* @property string $created_at 上传时间
|
||||
* @property string $deleted_at 删除时间
|
||||
*
|
||||
* @package App\Model\Article
|
||||
*/
|
||||
|
@ -47,18 +47,18 @@ class ArticleAnnex extends BaseModel
|
|||
'created_at',
|
||||
'deleted_at'
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* The attributes that should be cast to native types.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $casts = [
|
||||
'id' => 'integer',
|
||||
'user_id' => 'integer',
|
||||
'id' => 'integer',
|
||||
'user_id' => 'integer',
|
||||
'article_id' => 'integer',
|
||||
'file_size' => 'integer',
|
||||
'status' => 'integer',
|
||||
'file_size' => 'integer',
|
||||
'status' => 'integer',
|
||||
'created_at' => 'datetime'
|
||||
];
|
||||
}
|
||||
|
|
|
@ -9,12 +9,12 @@ use App\Model\BaseModel;
|
|||
/**
|
||||
* 笔记分类数据表模型
|
||||
*
|
||||
* @property integer $id 分类ID
|
||||
* @property integer $user_id 用户ID
|
||||
* @property string $class_name 分类名
|
||||
* @property integer $sort 排序[值越小越靠前]
|
||||
* @property integer $id 分类ID
|
||||
* @property integer $user_id 用户ID
|
||||
* @property string $class_name 分类名
|
||||
* @property integer $sort 排序[值越小越靠前]
|
||||
* @property integer $is_default 默认分类[1:是;0:不是]
|
||||
* @property string $created_at 创建时间
|
||||
* @property string $created_at 创建时间
|
||||
*
|
||||
* @package App\Model\Article
|
||||
*/
|
||||
|
@ -46,9 +46,9 @@ class ArticleClass extends BaseModel
|
|||
* @var array
|
||||
*/
|
||||
protected $casts = [
|
||||
'id' => 'integer',
|
||||
'user_id' => 'integer',
|
||||
'sort' => 'integer',
|
||||
'id' => 'integer',
|
||||
'user_id' => 'integer',
|
||||
'sort' => 'integer',
|
||||
'is_default' => 'integer',
|
||||
'created_at' => 'int'
|
||||
];
|
||||
|
|
|
@ -9,10 +9,10 @@ use App\Model\BaseModel;
|
|||
/**
|
||||
* 笔记详情数据表模型
|
||||
*
|
||||
* @property integer $id 笔记详情ID
|
||||
* @property integer $id 笔记详情ID
|
||||
* @property integer $article_id 笔记ID
|
||||
* @property string $md_content 笔记MD格式内容
|
||||
* @property string $content 笔记html格式内容
|
||||
* @property string $md_content 笔记MD格式内容
|
||||
* @property string $content 笔记html格式内容
|
||||
*
|
||||
* @package App\Model\Article
|
||||
*/
|
||||
|
@ -42,7 +42,7 @@ class ArticleDetail extends BaseModel
|
|||
* @var array
|
||||
*/
|
||||
protected $casts = [
|
||||
'id' => 'integer',
|
||||
'id' => 'integer',
|
||||
'article_id' => 'integer'
|
||||
];
|
||||
}
|
||||
|
|
|
@ -7,10 +7,10 @@ namespace App\Model\Article;
|
|||
use App\Model\BaseModel;
|
||||
|
||||
/**
|
||||
* @property integer $id 标签ID
|
||||
* @property integer $user_id 用户ID
|
||||
* @property string $tag_name 标签名称
|
||||
* @property integer $sort 标签排序
|
||||
* @property integer $id 标签ID
|
||||
* @property integer $user_id 用户ID
|
||||
* @property string $tag_name 标签名称
|
||||
* @property integer $sort 标签排序
|
||||
* @property integer $created_at 创建时间
|
||||
*/
|
||||
class ArticleTag extends BaseModel
|
||||
|
@ -28,7 +28,7 @@ class ArticleTag extends BaseModel
|
|||
* @var array
|
||||
*/
|
||||
protected $fillable = [
|
||||
'user_id','tag_name','sort','created_at'
|
||||
'user_id', 'tag_name', 'sort', 'created_at'
|
||||
];
|
||||
|
||||
/**
|
||||
|
@ -37,9 +37,9 @@ class ArticleTag extends BaseModel
|
|||
* @var array
|
||||
*/
|
||||
protected $casts = [
|
||||
'id' => 'integer',
|
||||
'user_id' => 'integer',
|
||||
'sort' => 'integer',
|
||||
'id' => 'integer',
|
||||
'user_id' => 'integer',
|
||||
'sort' => 'integer',
|
||||
'created_at' => 'integer'
|
||||
];
|
||||
}
|
||||
|
|
|
@ -9,13 +9,13 @@ use App\Model\BaseModel;
|
|||
/**
|
||||
* 聊天记录数据表模型
|
||||
*
|
||||
* @property int $id 聊天消息ID
|
||||
* @property int $source 消息来源[1:好友消息;2:群聊消息]
|
||||
* @property int $msg_type 消息类型[1:文本消息;2:文件消息;3:入群消息/退群消息;4:会话记录消息;5:代码块消息]
|
||||
* @property int $user_id 发送者ID[0:代表系统消息; >0: 用户ID]
|
||||
* @property int $receive_id 接收者ID[用户ID 或 群ID]
|
||||
* @property string $content 文本消息
|
||||
* @property int $is_revoke 是否撤回消息[0:否;1:是]
|
||||
* @property int $id 聊天消息ID
|
||||
* @property int $source 消息来源[1:好友消息;2:群聊消息]
|
||||
* @property int $msg_type 消息类型[1:文本消息;2:文件消息;3:入群消息/退群消息;4:会话记录消息;5:代码块消息]
|
||||
* @property int $user_id 发送者ID[0:代表系统消息; >0: 用户ID]
|
||||
* @property int $receive_id 接收者ID[用户ID 或 群ID]
|
||||
* @property string $content 文本消息
|
||||
* @property int $is_revoke 是否撤回消息[0:否;1:是]
|
||||
* @property string $created_at 创建时间
|
||||
*
|
||||
* @package App\Model\Chat
|
||||
|
@ -50,11 +50,11 @@ class ChatRecord extends BaseModel
|
|||
* @var array
|
||||
*/
|
||||
protected $casts = [
|
||||
'id' => 'integer',
|
||||
'source' => 'integer',
|
||||
'msg_type' => 'integer',
|
||||
'user_id' => 'integer',
|
||||
'id' => 'integer',
|
||||
'source' => 'integer',
|
||||
'msg_type' => 'integer',
|
||||
'user_id' => 'integer',
|
||||
'receive_id' => 'integer',
|
||||
'is_revoke' => 'integer'
|
||||
'is_revoke' => 'integer'
|
||||
];
|
||||
}
|
||||
|
|
|
@ -9,11 +9,11 @@ use App\Model\BaseModel;
|
|||
/**
|
||||
* 聊天记录(代码块消息)数据表模型
|
||||
*
|
||||
* @property int $id 代码块ID
|
||||
* @property int $record_id 聊天记录ID
|
||||
* @property int $user_id 用户ID
|
||||
* @property string $code_lang 代码语言
|
||||
* @property string $code 代码详情
|
||||
* @property int $id 代码块ID
|
||||
* @property int $record_id 聊天记录ID
|
||||
* @property int $user_id 用户ID
|
||||
* @property string $code_lang 代码语言
|
||||
* @property string $code 代码详情
|
||||
* @property string $created_at 创建时间
|
||||
*
|
||||
* @package App\Model\Chat
|
||||
|
@ -46,9 +46,9 @@ class ChatRecordsCode extends BaseModel
|
|||
* @var array
|
||||
*/
|
||||
protected $casts = [
|
||||
'id' => 'integer',
|
||||
'record_id' => 'integer',
|
||||
'user_id' => 'integer',
|
||||
'id' => 'integer',
|
||||
'record_id' => 'integer',
|
||||
'user_id' => 'integer',
|
||||
'created_at' => 'datetime'
|
||||
];
|
||||
}
|
||||
|
|
|
@ -9,9 +9,9 @@ use App\Model\BaseModel;
|
|||
/**
|
||||
* 聊天记录(已删除消息)数据表模型
|
||||
*
|
||||
* @property int $id 代码块ID
|
||||
* @property int $record_id 聊天记录ID
|
||||
* @property int $user_id 用户ID
|
||||
* @property int $id 代码块ID
|
||||
* @property int $record_id 聊天记录ID
|
||||
* @property int $user_id 用户ID
|
||||
* @property string $created_at 删除时间
|
||||
*
|
||||
* @package App\Model\Chat
|
||||
|
@ -38,9 +38,9 @@ class ChatRecordsDelete extends BaseModel
|
|||
* @var array
|
||||
*/
|
||||
protected $casts = [
|
||||
'id' => 'integer',
|
||||
'record_id' => 'integer',
|
||||
'user_id' => 'integer',
|
||||
'id' => 'integer',
|
||||
'record_id' => 'integer',
|
||||
'user_id' => 'integer',
|
||||
'created_at' => 'datetime'
|
||||
];
|
||||
}
|
||||
|
|
|
@ -9,18 +9,18 @@ use App\Model\BaseModel;
|
|||
/**
|
||||
* 聊天记录(文件消息)数据表模型
|
||||
*
|
||||
* @property int $id 文件消息ID
|
||||
* @property int $record_id 聊天记录ID
|
||||
* @property int $user_id 用户ID
|
||||
* @property int $file_source 文件上传来源
|
||||
* @property int $file_type 文件类型
|
||||
* @property int $save_type 文件保存类型
|
||||
* @property int $id 文件消息ID
|
||||
* @property int $record_id 聊天记录ID
|
||||
* @property int $user_id 用户ID
|
||||
* @property int $file_source 文件上传来源
|
||||
* @property int $file_type 文件类型
|
||||
* @property int $save_type 文件保存类型
|
||||
* @property string $original_name 文件原始名称
|
||||
* @property string $file_suffix 文件后缀名
|
||||
* @property int $file_size 文件大小
|
||||
* @property string $save_dir 文件保存路径
|
||||
* @property int $is_delete 是否已删除
|
||||
* @property string $created_at 上传时间
|
||||
* @property string $file_suffix 文件后缀名
|
||||
* @property int $file_size 文件大小
|
||||
* @property string $save_dir 文件保存路径
|
||||
* @property int $is_delete 是否已删除
|
||||
* @property string $created_at 上传时间
|
||||
*
|
||||
* @package App\Model\Chat
|
||||
*/
|
||||
|
@ -51,21 +51,21 @@ class ChatRecordsFile extends BaseModel
|
|||
'is_delete',
|
||||
'created_at'
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* The attributes that should be cast to native types.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $casts = [
|
||||
'id' => 'integer',
|
||||
'record_id' => 'integer',
|
||||
'user_id' => 'integer',
|
||||
'id' => 'integer',
|
||||
'record_id' => 'integer',
|
||||
'user_id' => 'integer',
|
||||
'file_source' => 'integer',
|
||||
'file_type' => 'integer',
|
||||
'save_type' => 'integer',
|
||||
'file_size' => 'integer',
|
||||
'is_delete' => 'integer',
|
||||
'created_at' => 'datetime'
|
||||
'file_type' => 'integer',
|
||||
'save_type' => 'integer',
|
||||
'file_size' => 'integer',
|
||||
'is_delete' => 'integer',
|
||||
'created_at' => 'datetime'
|
||||
];
|
||||
}
|
||||
|
|
|
@ -9,12 +9,12 @@ use App\Model\BaseModel;
|
|||
/**
|
||||
* 聊天记录(转发消息)数据表模型
|
||||
*
|
||||
* @property int $id 转发ID
|
||||
* @property int $record_id 聊天记录ID
|
||||
* @property int $user_id 用户ID
|
||||
* @property int $id 转发ID
|
||||
* @property int $record_id 聊天记录ID
|
||||
* @property int $user_id 用户ID
|
||||
* @property string $records_id 聊天记录ID,多个用英文','拼接
|
||||
* @property string $text 缓存信息
|
||||
* @property int $created_at 转发时间
|
||||
* @property string $text 缓存信息
|
||||
* @property int $created_at 转发时间
|
||||
*
|
||||
* @package App\Model\Chat
|
||||
*/
|
||||
|
@ -33,7 +33,7 @@ class ChatRecordsForward extends BaseModel
|
|||
* @var array
|
||||
*/
|
||||
protected $fillable = [
|
||||
'record_id', 'user_id', 'records_id','text','created_at'
|
||||
'record_id', 'user_id', 'records_id', 'text', 'created_at'
|
||||
];
|
||||
|
||||
/**
|
||||
|
@ -42,8 +42,8 @@ class ChatRecordsForward extends BaseModel
|
|||
* @var array
|
||||
*/
|
||||
protected $casts = [
|
||||
'id' => 'integer',
|
||||
'id' => 'integer',
|
||||
'record_id' => 'integer',
|
||||
'user_id' => 'integer',
|
||||
'user_id' => 'integer',
|
||||
];
|
||||
}
|
||||
|
|
|
@ -9,11 +9,11 @@ use App\Model\BaseModel;
|
|||
/**
|
||||
* 聊天记录(入群/退群消息)数据表模型
|
||||
*
|
||||
* @property int $id 入群或退群通知ID
|
||||
* @property int $record_id 消息记录ID
|
||||
* @property int $type 通知类型[1:入群通知;2:自动退群;3:管理员踢群]
|
||||
* @property int $operate_user_id 操作人的用户ID[邀请人OR管理员ID]
|
||||
* @property string $user_ids 用户ID(多个用 , 分割)
|
||||
* @property int $id 入群或退群通知ID
|
||||
* @property int $record_id 消息记录ID
|
||||
* @property int $type 通知类型[1:入群通知;2:自动退群;3:管理员踢群]
|
||||
* @property int $operate_user_id 操作人的用户ID[邀请人OR管理员ID]
|
||||
* @property string $user_ids 用户ID(多个用 , 分割)
|
||||
*
|
||||
* @package App\Model\Chat
|
||||
*/
|
||||
|
@ -44,9 +44,9 @@ class ChatRecordsInvite extends BaseModel
|
|||
* @var array
|
||||
*/
|
||||
protected $casts = [
|
||||
'id' => 'integer',
|
||||
'record_id' => 'integer',
|
||||
'type' => 'integer',
|
||||
'id' => 'integer',
|
||||
'record_id' => 'integer',
|
||||
'type' => 'integer',
|
||||
'operate_user_id' => 'integer'
|
||||
];
|
||||
}
|
||||
|
|
|
@ -7,9 +7,9 @@ namespace App\Model;
|
|||
/**
|
||||
* 表情包分组数据表模型
|
||||
*
|
||||
* @property int $id 分组ID
|
||||
* @property string $name 分组名称
|
||||
* @property string $url 默认表情
|
||||
* @property int $id 分组ID
|
||||
* @property string $name 分组名称
|
||||
* @property string $url 默认表情
|
||||
* @property string $created_at 创建时间
|
||||
*
|
||||
* @package App\Model
|
||||
|
@ -36,7 +36,7 @@ class Emoticon extends BaseModel
|
|||
* @var array
|
||||
*/
|
||||
protected $casts = [
|
||||
'id' => 'integer',
|
||||
'id' => 'integer',
|
||||
'created_at' => 'datetime'
|
||||
];
|
||||
}
|
||||
|
|
|
@ -7,14 +7,14 @@ namespace App\Model;
|
|||
/**
|
||||
* 表情包数据表模型
|
||||
*
|
||||
* @property int $id 表情包ID
|
||||
* @property int $emoticon_id 分组ID
|
||||
* @property int $user_id 用户ID
|
||||
* @property string $describe 表情描述
|
||||
* @property string $url 表情链接
|
||||
* @property int $id 表情包ID
|
||||
* @property int $emoticon_id 分组ID
|
||||
* @property int $user_id 用户ID
|
||||
* @property string $describe 表情描述
|
||||
* @property string $url 表情链接
|
||||
* @property string $file_suffix 文件前缀
|
||||
* @property int $file_size 表情包文件大小
|
||||
* @property string $created_at 创建时间
|
||||
* @property int $file_size 表情包文件大小
|
||||
* @property string $created_at 创建时间
|
||||
*
|
||||
* @package App\Model
|
||||
*/
|
||||
|
@ -48,10 +48,10 @@ class EmoticonDetail extends BaseModel
|
|||
* @var array
|
||||
*/
|
||||
protected $casts = [
|
||||
'id' => 'integer',
|
||||
'id' => 'integer',
|
||||
'emoticon_id' => 'integer',
|
||||
'user_id' => 'integer',
|
||||
'file_size' => 'integer',
|
||||
'created_at' => 'integer'
|
||||
'user_id' => 'integer',
|
||||
'file_size' => 'integer',
|
||||
'created_at' => 'integer'
|
||||
];
|
||||
}
|
||||
|
|
|
@ -7,18 +7,18 @@ namespace App\Model;
|
|||
/**
|
||||
* 文件拆分上传数据表模型
|
||||
*
|
||||
* @property int $id 临时文件ID
|
||||
* @property int $file_type 上传类型[1:合并文件;2:拆分文件]
|
||||
* @property int $user_id 上传的用户ID
|
||||
* @property string $hash_name 临时文件hash名
|
||||
* @property int $id 临时文件ID
|
||||
* @property int $file_type 上传类型[1:合并文件;2:拆分文件]
|
||||
* @property int $user_id 上传的用户ID
|
||||
* @property string $hash_name 临时文件hash名
|
||||
* @property string $original_name 原文件名
|
||||
* @property int $split_index 当前索引块
|
||||
* @property int $split_num 总上传索引块
|
||||
* @property string $save_dir 文件的临时保存路径
|
||||
* @property string $file_ext 文件后缀名
|
||||
* @property int $file_size 临时文件大小
|
||||
* @property int $is_delete 文件是否已被删除[1:是;0:否;]
|
||||
* @property int $upload_at 文件上传时间
|
||||
* @property int $split_index 当前索引块
|
||||
* @property int $split_num 总上传索引块
|
||||
* @property string $save_dir 文件的临时保存路径
|
||||
* @property string $file_ext 文件后缀名
|
||||
* @property int $file_size 临时文件大小
|
||||
* @property int $is_delete 文件是否已被删除[1:是;0:否;]
|
||||
* @property int $upload_at 文件上传时间
|
||||
*
|
||||
* @package App\Model
|
||||
*/
|
||||
|
@ -56,13 +56,13 @@ class FileSplitUpload extends BaseModel
|
|||
* @var array
|
||||
*/
|
||||
protected $casts = [
|
||||
'id' => 'integer',
|
||||
'file_type' => 'integer',
|
||||
'user_id' => 'integer',
|
||||
'id' => 'integer',
|
||||
'file_type' => 'integer',
|
||||
'user_id' => 'integer',
|
||||
'split_index' => 'integer',
|
||||
'split_num' => 'integer',
|
||||
'file_size' => 'integer',
|
||||
'is_delete' => 'integer',
|
||||
'upload_at' => 'integer'
|
||||
'split_num' => 'integer',
|
||||
'file_size' => 'integer',
|
||||
'is_delete' => 'integer',
|
||||
'upload_at' => 'integer'
|
||||
];
|
||||
}
|
||||
|
|
|
@ -8,17 +8,17 @@ use App\Model\BaseModel;
|
|||
/**
|
||||
* 聊天群组数据表模型
|
||||
*
|
||||
* @property integer $id 群ID
|
||||
* @property integer $creator_id 群主ID
|
||||
* @property string $group_name 群名称
|
||||
* @property string $profile 群简介
|
||||
* @property integer $avatar 群头像
|
||||
* @property integer $max_num 最大群成员数量
|
||||
* @property integer $is_overt 是否公开可见[0:否;1:是;]
|
||||
* @property integer $is_mute 是否全员禁言 [0:否;1:是;],提示:不包含群主或管理员
|
||||
* @property integer $is_dismiss 是否已解散[0:否;1:是;]
|
||||
* @property string $created_at 创建时间
|
||||
* @property string $dismissed_at 解散时间
|
||||
* @property integer $id 群ID
|
||||
* @property integer $creator_id 群主ID
|
||||
* @property string $group_name 群名称
|
||||
* @property string $profile 群简介
|
||||
* @property integer $avatar 群头像
|
||||
* @property integer $max_num 最大群成员数量
|
||||
* @property integer $is_overt 是否公开可见[0:否;1:是;]
|
||||
* @property integer $is_mute 是否全员禁言 [0:否;1:是;],提示:不包含群主或管理员
|
||||
* @property integer $is_dismiss 是否已解散[0:否;1:是;]
|
||||
* @property string $created_at 创建时间
|
||||
* @property string $dismissed_at 解散时间
|
||||
*
|
||||
* @package App\Model\Group
|
||||
*/
|
||||
|
@ -77,9 +77,10 @@ class Group extends BaseModel
|
|||
/**
|
||||
* 判断用户是否是管理员
|
||||
*
|
||||
* @param int $user_id 用户ID
|
||||
* @param int $group_id 群ID
|
||||
* @param int|array $leader 管理员类型[0:普通成员;1:管理员;2:群主;]
|
||||
* @param int $user_id 用户ID
|
||||
* @param int $group_id 群ID
|
||||
* @param int|array $leader 管理员类型[0:普通成员;1:管理员;2:群主;]
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function isManager(int $user_id, int $group_id, $leader = 2)
|
||||
|
@ -91,6 +92,7 @@ class Group extends BaseModel
|
|||
* 判断群组是否已解散
|
||||
*
|
||||
* @param int $group_id 群ID
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function isDismiss(int $group_id)
|
||||
|
@ -102,7 +104,8 @@ class Group extends BaseModel
|
|||
* 判断用户是否是群成员
|
||||
*
|
||||
* @param int $group_id 群ID
|
||||
* @param int $user_id 用户ID
|
||||
* @param int $user_id 用户ID
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function isMember(int $group_id, int $user_id)
|
||||
|
|
|
@ -8,15 +8,15 @@ use App\Model\BaseModel;
|
|||
/**
|
||||
* 聊天群组[成员]数据表模型
|
||||
*
|
||||
* @property integer $id 群成员ID
|
||||
* @property integer $group_id 群组ID
|
||||
* @property integer $user_id 用户ID
|
||||
* @property integer $leader 成员属性[0:普通成员;1:管理员;2:群主;]
|
||||
* @property integer $is_mute 是否禁言[0:否;1:是;]
|
||||
* @property integer $is_quit 是否退群[0:否;1:是;]
|
||||
* @property string $user_card 群名片
|
||||
* @property string $created_at 入群时间
|
||||
* @property string $deleted_at 退群时间
|
||||
* @property integer $id 群成员ID
|
||||
* @property integer $group_id 群组ID
|
||||
* @property integer $user_id 用户ID
|
||||
* @property integer $leader 成员属性[0:普通成员;1:管理员;2:群主;]
|
||||
* @property integer $is_mute 是否禁言[0:否;1:是;]
|
||||
* @property integer $is_quit 是否退群[0:否;1:是;]
|
||||
* @property string $user_card 群名片
|
||||
* @property string $created_at 入群时间
|
||||
* @property string $deleted_at 退群时间
|
||||
*
|
||||
* @package App\Model\Group
|
||||
*/
|
||||
|
@ -64,6 +64,7 @@ class GroupMember extends BaseModel
|
|||
* 获取聊天群成员ID
|
||||
*
|
||||
* @param int $group_id 群聊ID
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getGroupMemberIds(int $group_id)
|
||||
|
@ -74,8 +75,9 @@ class GroupMember extends BaseModel
|
|||
/**
|
||||
* 获取用户的群名片
|
||||
*
|
||||
* @param int $user_id 用户ID
|
||||
* @param int $user_id 用户ID
|
||||
* @param int $group_id 群ID
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function visitCard(int $user_id, int $group_id)
|
||||
|
@ -87,6 +89,7 @@ class GroupMember extends BaseModel
|
|||
* 获取用户的所有群ID
|
||||
*
|
||||
* @param int $user_id 用户ID
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getUserGroupIds(int $user_id)
|
||||
|
|
|
@ -8,18 +8,18 @@ use App\Model\BaseModel;
|
|||
/**
|
||||
* 聊天群组[公告消息]数据表模型
|
||||
*
|
||||
* @property integer $id 群公告ID
|
||||
* @property integer $group_id 群组ID
|
||||
* @property integer $creator_id 创建者用户ID
|
||||
* @property string $title 公告标题
|
||||
* @property string $content 公告内容
|
||||
* @property integer $is_top 是否置顶[0:否;1:是;]
|
||||
* @property integer $is_delete 是否删除[0:否;1:是;]
|
||||
* @property integer $is_confirm 是否需群成员确认公告[0:否;1:是;]
|
||||
* @property array $confirm_users 已确认成员
|
||||
* @property string $created_at 创建时间
|
||||
* @property string $updated_at 更新时间
|
||||
* @property string $deleted_at 删除时间
|
||||
* @property integer $id 群公告ID
|
||||
* @property integer $group_id 群组ID
|
||||
* @property integer $creator_id 创建者用户ID
|
||||
* @property string $title 公告标题
|
||||
* @property string $content 公告内容
|
||||
* @property integer $is_top 是否置顶[0:否;1:是;]
|
||||
* @property integer $is_delete 是否删除[0:否;1:是;]
|
||||
* @property integer $is_confirm 是否需群成员确认公告[0:否;1:是;]
|
||||
* @property array $confirm_users 已确认成员
|
||||
* @property string $created_at 创建时间
|
||||
* @property string $updated_at 更新时间
|
||||
* @property string $deleted_at 删除时间
|
||||
*
|
||||
* @package App\Model\Group
|
||||
*/
|
||||
|
|
|
@ -7,12 +7,12 @@ namespace App\Model;
|
|||
/**
|
||||
* Class User
|
||||
*
|
||||
* @property integer $id 用户ID
|
||||
* @property string $nickname 用户昵称
|
||||
* @property string $mobile 登录手机号
|
||||
* @property string $password 登录密码
|
||||
* @property string $avatar 头像
|
||||
* @property integer $gender 性别
|
||||
* @property integer $id 用户ID
|
||||
* @property string $nickname 用户昵称
|
||||
* @property string $mobile 登录手机号
|
||||
* @property string $password 登录密码
|
||||
* @property string $avatar 头像
|
||||
* @property integer $gender 性别
|
||||
* @property integer $created_at 注册时间
|
||||
*
|
||||
* @package App\Model
|
||||
|
|
|
@ -7,16 +7,16 @@ namespace App\Model;
|
|||
/**
|
||||
* 聊天列表组数据表模型
|
||||
*
|
||||
* @property int $id 聊天列表ID
|
||||
* @property int $type 聊天类型[1:好友;2:群聊;]
|
||||
* @property int $uid 用户ID
|
||||
* @property int $friend_id 好友ID
|
||||
* @property int $group_id 群组ID
|
||||
* @property int $status 列表状态
|
||||
* @property int $is_top 是否置顶
|
||||
* @property int $not_disturb 是否消息免打扰
|
||||
* @property string $created_at 创建时间
|
||||
* @property string $updated_at 更新时间
|
||||
* @property int $id 聊天列表ID
|
||||
* @property int $type 聊天类型[1:好友;2:群聊;]
|
||||
* @property int $uid 用户ID
|
||||
* @property int $friend_id 好友ID
|
||||
* @property int $group_id 群组ID
|
||||
* @property int $status 列表状态
|
||||
* @property int $is_top 是否置顶
|
||||
* @property int $not_disturb 是否消息免打扰
|
||||
* @property string $created_at 创建时间
|
||||
* @property string $updated_at 更新时间
|
||||
*
|
||||
* @package App\Model
|
||||
*/
|
||||
|
@ -52,48 +52,49 @@ class UsersChatList extends BaseModel
|
|||
* @var array
|
||||
*/
|
||||
protected $casts = [
|
||||
'id' => 'integer',
|
||||
'type' => 'integer',
|
||||
'uid' => 'integer',
|
||||
'friend_id' => 'integer',
|
||||
'group_id' => 'integer',
|
||||
'status' => 'integer',
|
||||
'is_top' => 'integer',
|
||||
'id' => 'integer',
|
||||
'type' => 'integer',
|
||||
'uid' => 'integer',
|
||||
'friend_id' => 'integer',
|
||||
'group_id' => 'integer',
|
||||
'status' => 'integer',
|
||||
'is_top' => 'integer',
|
||||
'not_disturb' => 'integer',
|
||||
'created_at' => 'datetime',
|
||||
'updated_at' => 'datetime'
|
||||
'created_at' => 'datetime',
|
||||
'updated_at' => 'datetime'
|
||||
];
|
||||
|
||||
/**
|
||||
* 创建聊天列表记录
|
||||
*
|
||||
* @param int $user_id 用户ID
|
||||
* @param int $user_id 用户ID
|
||||
* @param int $receive_id 接收者ID
|
||||
* @param int $type 创建类型 1:私聊 2:群聊
|
||||
* @param int $type 创建类型 1:私聊 2:群聊
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function addItem(int $user_id, int $receive_id, int $type)
|
||||
{
|
||||
$result = self::where('uid', $user_id)->where('type', $type)->where($type == 1 ? 'friend_id' : 'group_id', $receive_id)->first();
|
||||
if ($result) {
|
||||
$result->status = 1;
|
||||
$result->status = 1;
|
||||
$result->updated_at = date('Y-m-d H:i:s');
|
||||
$result->save();
|
||||
|
||||
return [
|
||||
'id' => $result->id,
|
||||
'type' => $result->type,
|
||||
'id' => $result->id,
|
||||
'type' => $result->type,
|
||||
'friend_id' => $result->friend_id,
|
||||
'group_id' => $result->group_id,
|
||||
'group_id' => $result->group_id,
|
||||
];
|
||||
}
|
||||
|
||||
if (!$result = self::create([
|
||||
'type' => $type,
|
||||
'uid' => $user_id,
|
||||
'status' => 1,
|
||||
'friend_id' => $type == 1 ? $receive_id : 0,
|
||||
'group_id' => $type == 2 ? $receive_id : 0,
|
||||
'type' => $type,
|
||||
'uid' => $user_id,
|
||||
'status' => 1,
|
||||
'friend_id' => $type == 1 ? $receive_id : 0,
|
||||
'group_id' => $type == 2 ? $receive_id : 0,
|
||||
'created_at' => date('Y-m-d H:i:s'),
|
||||
'updated_at' => date('Y-m-d H:i:s'),
|
||||
])) {
|
||||
|
@ -101,25 +102,26 @@ class UsersChatList extends BaseModel
|
|||
}
|
||||
|
||||
return [
|
||||
'id' => $result->id,
|
||||
'type' => $result->type,
|
||||
'id' => $result->id,
|
||||
'type' => $result->type,
|
||||
'friend_id' => $result->friend_id,
|
||||
'group_id' => $result->group_id,
|
||||
'group_id' => $result->group_id,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 聊天对话列表置顶操作
|
||||
*
|
||||
* @param int $user_id 用户ID
|
||||
* @param int $list_id 对话列表ID
|
||||
* @param bool $is_top 是否置顶(true:是 false:否)
|
||||
* @param int $user_id 用户ID
|
||||
* @param int $list_id 对话列表ID
|
||||
* @param bool $is_top 是否置顶(true:是 false:否)
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function topItem(int $user_id, int $list_id, $is_top = true)
|
||||
{
|
||||
return (bool)self::where('id', $list_id)->where('uid', $user_id)->update([
|
||||
'is_top' => $is_top ? 1 : 0,
|
||||
'is_top' => $is_top ? 1 : 0,
|
||||
'updated_at' => date('Y-m-d H:i:s')
|
||||
]);
|
||||
}
|
||||
|
@ -128,8 +130,9 @@ class UsersChatList extends BaseModel
|
|||
* 删除聊天列表
|
||||
*
|
||||
* @param int $user_id 用户ID
|
||||
* @param int $id 聊天列表ID、好友ID或群聊ID
|
||||
* @param int $type ID类型 (1:聊天列表ID 2:好友ID 3:群聊ID)
|
||||
* @param int $id 聊天列表ID、好友ID或群聊ID
|
||||
* @param int $type ID类型 (1:聊天列表ID 2:好友ID 3:群聊ID)
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function delItem(int $user_id, int $id, $type = 1)
|
||||
|
@ -147,10 +150,11 @@ class UsersChatList extends BaseModel
|
|||
/**
|
||||
* 设置消息免打扰
|
||||
*
|
||||
* @param int $user_id 用户ID
|
||||
* @param int $receive_id 接收者ID
|
||||
* @param int $type 接收者类型(1:好友 2:群组)
|
||||
* @param int $user_id 用户ID
|
||||
* @param int $receive_id 接收者ID
|
||||
* @param int $type 接收者类型(1:好友 2:群组)
|
||||
* @param int $not_disturb 是否免打扰
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public static function notDisturbItem(int $user_id, int $receive_id, int $type, int $not_disturb)
|
||||
|
|
|
@ -7,8 +7,8 @@ namespace App\Model;
|
|||
/**
|
||||
* 表情包收藏数据表模型
|
||||
*
|
||||
* @property int $id 收藏ID
|
||||
* @property int $user_id 用户ID
|
||||
* @property int $id 收藏ID
|
||||
* @property int $user_id 用户ID
|
||||
* @property string $emoticon_ids 表情包ID,多个用英文逗号拼接
|
||||
*
|
||||
* @package App\Model
|
||||
|
@ -38,13 +38,14 @@ class UsersEmoticon extends BaseModel
|
|||
* @var array
|
||||
*/
|
||||
protected $casts = [
|
||||
'id' => 'integer',
|
||||
'id' => 'integer',
|
||||
'user_id' => 'integer'
|
||||
];
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $value
|
||||
* @param string $value
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getEmoticonIdsAttribute($value)
|
||||
|
|
|
@ -9,15 +9,15 @@ use Hyperf\DbConnection\Db;
|
|||
/**
|
||||
* 表情包收藏数据表模型
|
||||
*
|
||||
* @property int $id
|
||||
* @property int $user1 用户1ID
|
||||
* @property int $user2 用户2ID
|
||||
* @property int $id
|
||||
* @property int $user1 用户1ID
|
||||
* @property int $user2 用户2ID
|
||||
* @property string $user1_remark 用户1好友备注
|
||||
* @property string $user2_remark 用户2好友备注
|
||||
* @property int $active 主动邀请方[1:user1;2:user2;]
|
||||
* @property int $status 好友状态[1:好友状态;0:已解除好友关系]
|
||||
* @property string $agree_time 成为好友时间
|
||||
* @property string $created_at 创建时间
|
||||
* @property int $active 主动邀请方[1:user1;2:user2;]
|
||||
* @property int $status 好友状态[1:好友状态;0:已解除好友关系]
|
||||
* @property string $agree_time 成为好友时间
|
||||
* @property string $created_at 创建时间
|
||||
*
|
||||
* @package App\Model
|
||||
*/
|
||||
|
@ -52,11 +52,11 @@ class UsersFriend extends BaseModel
|
|||
* @var array
|
||||
*/
|
||||
protected $casts = [
|
||||
'id' => 'integer',
|
||||
'user1' => 'integer',
|
||||
'user2' => 'integer',
|
||||
'active' => 'integer',
|
||||
'status' => 'integer',
|
||||
'id' => 'integer',
|
||||
'user1' => 'integer',
|
||||
'user2' => 'integer',
|
||||
'active' => 'integer',
|
||||
'status' => 'integer',
|
||||
'created_at' => 'datetime'
|
||||
];
|
||||
|
||||
|
@ -64,12 +64,13 @@ class UsersFriend extends BaseModel
|
|||
* 获取用户所有好友
|
||||
*
|
||||
* @param int $uid 用户ID
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function getUserFriends(int $uid)
|
||||
{
|
||||
$prefix = config('databases.default.prefix');
|
||||
$sql = <<<SQL
|
||||
$sql = <<<SQL
|
||||
SELECT users.id,users.nickname,users.avatar,users.motto,users.gender,tmp_table.friend_remark from {$prefix}users users
|
||||
INNER join
|
||||
(
|
||||
|
@ -91,9 +92,10 @@ SQL;
|
|||
/**
|
||||
* 判断用户之间是否存在好友关系
|
||||
*
|
||||
* @param int $user_id1 用户1
|
||||
* @param int $user_id2 用户2
|
||||
* @param bool $cache 是否读取缓存
|
||||
* @param int $user_id1 用户1
|
||||
* @param int $user_id2 用户2
|
||||
* @param bool $cache 是否读取缓存
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function isFriend(int $user_id1, int $user_id2, bool $cache = false)
|
||||
|
@ -120,12 +122,13 @@ SQL;
|
|||
* 获取指定用户的所有朋友的用户ID
|
||||
*
|
||||
* @param int $user_id 指定用户ID
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getFriendIds(int $user_id)
|
||||
{
|
||||
$prefix = config('databases.default.prefix');
|
||||
$sql = "SELECT user2 as uid from {$prefix}users_friends where user1 = {$user_id} and `status` = 1 UNION all SELECT user1 as uid from {$prefix}users_friends where user2 = {$user_id} and `status` = 1";
|
||||
$sql = "SELECT user2 as uid from {$prefix}users_friends where user1 = {$user_id} and `status` = 1 UNION all SELECT user1 as uid from {$prefix}users_friends where user2 = {$user_id} and `status` = 1";
|
||||
return array_map(function ($item) {
|
||||
return $item->uid;
|
||||
}, Db::select($sql));
|
||||
|
|
|
@ -7,11 +7,11 @@ namespace App\Model;
|
|||
/**
|
||||
* 好友添加申请数据表模型
|
||||
*
|
||||
* @property int $id 申请ID
|
||||
* @property int $user_id 用户ID
|
||||
* @property int $friend_id 朋友ID
|
||||
* @property int $status 申请状态
|
||||
* @property string $remarks 备注说明
|
||||
* @property int $id 申请ID
|
||||
* @property int $user_id 用户ID
|
||||
* @property int $friend_id 朋友ID
|
||||
* @property int $status 申请状态
|
||||
* @property string $remarks 备注说明
|
||||
* @property string $created_at 创建时间
|
||||
* @property string $updated_at 更新时间
|
||||
*
|
||||
|
@ -46,10 +46,10 @@ class UsersFriendsApply extends BaseModel
|
|||
* @var array
|
||||
*/
|
||||
protected $casts = [
|
||||
'id' => 'integer',
|
||||
'user_id' => 'integer',
|
||||
'friend_id' => 'integer',
|
||||
'status' => 'integer',
|
||||
'id' => 'integer',
|
||||
'user_id' => 'integer',
|
||||
'friend_id' => 'integer',
|
||||
'status' => 'integer',
|
||||
'created_at' => 'datetime',
|
||||
'updated_at' => 'datetime'
|
||||
];
|
||||
|
|
|
@ -24,6 +24,7 @@ class ArticleService extends BaseService
|
|||
* 获取用户文章分类列表
|
||||
*
|
||||
* @param int $user_id 用户ID
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getUserClass(int $user_id)
|
||||
|
@ -42,6 +43,7 @@ class ArticleService extends BaseService
|
|||
* 获取用户文章标签列表
|
||||
*
|
||||
* @param int $user_id 用户ID
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getUserTags(int $user_id)
|
||||
|
@ -57,10 +59,11 @@ class ArticleService extends BaseService
|
|||
/**
|
||||
* 获取用户文章列表
|
||||
*
|
||||
* @param int $user_id 用户ID
|
||||
* @param int $page 分页
|
||||
* @param int $page_size 分页大小
|
||||
* @param array $params 查询参数
|
||||
* @param int $user_id 用户ID
|
||||
* @param int $page 分页
|
||||
* @param int $page_size 分页大小
|
||||
* @param array $params 查询参数
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getUserArticleList(int $user_id, int $page, int $page_size, $params = [])
|
||||
|
@ -68,7 +71,7 @@ class ArticleService extends BaseService
|
|||
$filed = ['article.id', 'article.class_id', 'article.title', 'article.image', 'article.abstract', 'article.updated_at', 'article_class.class_name', 'article.status'];
|
||||
|
||||
$countSqlObj = Article::select();
|
||||
$rowsSqlObj = Article::select($filed)
|
||||
$rowsSqlObj = Article::select($filed)
|
||||
->leftJoin('article_class', 'article_class.id', '=', 'article.class_id');
|
||||
|
||||
$countSqlObj->where('article.user_id', $user_id);
|
||||
|
@ -94,7 +97,7 @@ class ArticleService extends BaseService
|
|||
}
|
||||
|
||||
$count = $countSqlObj->count();
|
||||
$rows = [];
|
||||
$rows = [];
|
||||
if ($count > 0) {
|
||||
if ($params['find_type'] == 1) {
|
||||
$rowsSqlObj->orderBy('updated_at', 'desc');
|
||||
|
@ -113,7 +116,8 @@ class ArticleService extends BaseService
|
|||
* 获取文章详情
|
||||
*
|
||||
* @param int $article_id 文章ID
|
||||
* @param int $user_id 用户ID
|
||||
* @param int $user_id 用户ID
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getArticleDetail(int $article_id, $user_id = 0)
|
||||
|
@ -135,25 +139,26 @@ class ArticleService extends BaseService
|
|||
}
|
||||
|
||||
return [
|
||||
'id' => $article_id,
|
||||
'class_id' => $info->class_id,
|
||||
'title' => $info->title,
|
||||
'md_content' => htmlspecialchars_decode($detail->md_content),
|
||||
'content' => htmlspecialchars_decode($detail->content),
|
||||
'id' => $article_id,
|
||||
'class_id' => $info->class_id,
|
||||
'title' => $info->title,
|
||||
'md_content' => htmlspecialchars_decode($detail->md_content),
|
||||
'content' => htmlspecialchars_decode($detail->content),
|
||||
'is_asterisk' => $info->is_asterisk,
|
||||
'status' => $info->status,
|
||||
'created_at' => $info->created_at,
|
||||
'updated_at' => $info->updated_at,
|
||||
'tags' => $tags,
|
||||
'files' => $this->findArticleAnnexAll($user_id, $article_id)
|
||||
'status' => $info->status,
|
||||
'created_at' => $info->created_at,
|
||||
'updated_at' => $info->updated_at,
|
||||
'tags' => $tags,
|
||||
'files' => $this->findArticleAnnexAll($user_id, $article_id)
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取笔记附件
|
||||
*
|
||||
* @param int $user_id 用户ID
|
||||
* @param int $user_id 用户ID
|
||||
* @param int $article_id 笔记ID
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function findArticleAnnexAll(int $user_id, int $article_id)
|
||||
|
@ -168,9 +173,10 @@ class ArticleService extends BaseService
|
|||
/**
|
||||
* 编辑笔记分类
|
||||
*
|
||||
* @param int $uid 用户ID
|
||||
* @param int|string $class_id 分类ID
|
||||
* @param string $class_name 分类名
|
||||
* @param int $uid 用户ID
|
||||
* @param int|string $class_id 分类ID
|
||||
* @param string $class_name 分类名
|
||||
*
|
||||
* @return bool|int
|
||||
*/
|
||||
public function editArticleClass(int $uid, $class_id, string $class_name)
|
||||
|
@ -183,7 +189,7 @@ class ArticleService extends BaseService
|
|||
return $class_id;
|
||||
}
|
||||
|
||||
$arr = [];
|
||||
$arr = [];
|
||||
$items = ArticleClass::where('user_id', $uid)->get(['id', 'sort']);
|
||||
foreach ($items as $key => $item) {
|
||||
$arr[] = ['id' => $item->id, 'sort' => $key + 2];
|
||||
|
@ -214,8 +220,9 @@ class ArticleService extends BaseService
|
|||
/**
|
||||
* 删除笔记分类
|
||||
*
|
||||
* @param int $uid 用户ID
|
||||
* @param int $uid 用户ID
|
||||
* @param int $class_id 分类ID
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function delArticleClass(int $uid, int $class_id)
|
||||
|
@ -235,9 +242,10 @@ class ArticleService extends BaseService
|
|||
/**
|
||||
* 文集分类排序
|
||||
*
|
||||
* @param int $user_id 用户ID
|
||||
* @param int $class_id 文集分类ID
|
||||
* @param int $user_id 用户ID
|
||||
* @param int $class_id 文集分类ID
|
||||
* @param int $sort_type 排序方式
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function articleClassSort(int $user_id, int $class_id, int $sort_type)
|
||||
|
@ -299,9 +307,10 @@ class ArticleService extends BaseService
|
|||
/**
|
||||
* 笔记分类合并
|
||||
*
|
||||
* @param int $user_id 用户ID
|
||||
* @param int $class_id 笔记分类ID
|
||||
* @param int $user_id 用户ID
|
||||
* @param int $class_id 笔记分类ID
|
||||
* @param int $to_class_id 笔记分类ID
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function mergeArticleClass(int $user_id, int $class_id, int $to_class_id)
|
||||
|
@ -319,9 +328,10 @@ class ArticleService extends BaseService
|
|||
/**
|
||||
* 编辑笔记标签
|
||||
*
|
||||
* @param int $uid 用户ID
|
||||
* @param int $tag_id 标签ID
|
||||
* @param int $uid 用户ID
|
||||
* @param int $tag_id 标签ID
|
||||
* @param string $tag_name 标签名
|
||||
*
|
||||
* @return bool|int
|
||||
*/
|
||||
public function editArticleTag(int $uid, int $tag_id, string $tag_name)
|
||||
|
@ -351,8 +361,9 @@ class ArticleService extends BaseService
|
|||
/**
|
||||
* 删除笔记标签
|
||||
*
|
||||
* @param int $uid 用户ID
|
||||
* @param int $uid 用户ID
|
||||
* @param int $tag_id 标签ID
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function delArticleTags(int $uid, int $tag_id)
|
||||
|
@ -372,9 +383,10 @@ class ArticleService extends BaseService
|
|||
/**
|
||||
* 编辑文章信息
|
||||
*
|
||||
* @param int $user_id 用户ID
|
||||
* @param int $article_id 文章ID
|
||||
* @param array $data 文章数据
|
||||
* @param int $user_id 用户ID
|
||||
* @param int $article_id 文章ID
|
||||
* @param array $data 文章数据
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function editArticle(int $user_id, int $article_id, $data = [])
|
||||
|
@ -387,16 +399,16 @@ class ArticleService extends BaseService
|
|||
Db::beginTransaction();
|
||||
try {
|
||||
Article::where('id', $article_id)->where('user_id', $user_id)->update([
|
||||
'class_id' => $data['class_id'],
|
||||
'title' => $data['title'],
|
||||
'abstract' => $data['abstract'],
|
||||
'image' => $data['image'] ? $data['image'][0] : '',
|
||||
'class_id' => $data['class_id'],
|
||||
'title' => $data['title'],
|
||||
'abstract' => $data['abstract'],
|
||||
'image' => $data['image'] ? $data['image'][0] : '',
|
||||
'updated_at' => date('Y-m-d H:i:s')
|
||||
]);
|
||||
|
||||
ArticleDetail::where('article_id', $article_id)->update([
|
||||
'md_content' => $data['md_content'],
|
||||
'content' => $data['content']
|
||||
'content' => $data['content']
|
||||
]);
|
||||
|
||||
Db::commit();
|
||||
|
@ -411,10 +423,10 @@ class ArticleService extends BaseService
|
|||
Db::beginTransaction();
|
||||
try {
|
||||
$res = Article::create([
|
||||
'user_id' => $user_id,
|
||||
'class_id' => $data['class_id'],
|
||||
'title' => $data['title'],
|
||||
'abstract' => $data['abstract'],
|
||||
'user_id' => $user_id,
|
||||
'class_id' => $data['class_id'],
|
||||
'title' => $data['title'],
|
||||
'abstract' => $data['abstract'],
|
||||
'created_at' => date('Y-m-d H:i:s'),
|
||||
'updated_at' => date('Y-m-d H:i:s')
|
||||
]);
|
||||
|
@ -422,7 +434,7 @@ class ArticleService extends BaseService
|
|||
ArticleDetail::create([
|
||||
'article_id' => $res->id,
|
||||
'md_content' => $data['md_content'],
|
||||
'content' => $data['content']
|
||||
'content' => $data['content']
|
||||
]);
|
||||
|
||||
Db::commit();
|
||||
|
@ -437,9 +449,10 @@ class ArticleService extends BaseService
|
|||
/**
|
||||
* 更新笔记状态
|
||||
*
|
||||
* @param int $user_id 用户ID
|
||||
* @param int $user_id 用户ID
|
||||
* @param int $article_id 笔记ID
|
||||
* @param int $status 笔记状态 1:正常 2:已删除
|
||||
* @param int $status 笔记状态 1:正常 2:已删除
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function updateArticleStatus(int $user_id, int $article_id, int $status)
|
||||
|
@ -455,9 +468,10 @@ class ArticleService extends BaseService
|
|||
/**
|
||||
* 笔记移动至指定分类
|
||||
*
|
||||
* @param int $user_id 用户ID
|
||||
* @param int $user_id 用户ID
|
||||
* @param int $article_id 笔记ID
|
||||
* @param int $class_id 笔记分类ID
|
||||
* @param int $class_id 笔记分类ID
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function moveArticle(int $user_id, int $article_id, int $class_id)
|
||||
|
@ -468,9 +482,10 @@ class ArticleService extends BaseService
|
|||
/**
|
||||
* 笔记标记星号
|
||||
*
|
||||
* @param int $user_id 用户ID
|
||||
* @param int $user_id 用户ID
|
||||
* @param int $article_id 笔记ID
|
||||
* @param int $type 1:标记星号 2:取消星号标记
|
||||
* @param int $type 1:标记星号 2:取消星号标记
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function setAsteriskArticle(int $user_id, int $article_id, int $type)
|
||||
|
@ -483,9 +498,10 @@ class ArticleService extends BaseService
|
|||
/**
|
||||
* 更新笔记关联标签
|
||||
*
|
||||
* @param int $uid 用户ID
|
||||
* @param int $article_id 笔记ID
|
||||
* @param array $tags 关联标签ID
|
||||
* @param int $uid 用户ID
|
||||
* @param int $article_id 笔记ID
|
||||
* @param array $tags 关联标签ID
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function updateArticleTag(int $uid, int $article_id, array $tags)
|
||||
|
@ -496,8 +512,9 @@ class ArticleService extends BaseService
|
|||
/**
|
||||
* 永久删除回收站中的笔记
|
||||
*
|
||||
* @param int $uid 用户ID
|
||||
* @param int $uid 用户ID
|
||||
* @param int $article_id 笔记ID
|
||||
*
|
||||
* @return bool|int|mixed|null
|
||||
* @throws Exception
|
||||
*/
|
||||
|
@ -544,9 +561,10 @@ class ArticleService extends BaseService
|
|||
/**
|
||||
* 更新笔记附件状态
|
||||
*
|
||||
* @param int $user_id 用户ID
|
||||
* @param int $user_id 用户ID
|
||||
* @param int $annex_id 附件ID
|
||||
* @param int $status 附件状态 1:正常 2:已删除
|
||||
* @param int $status 附件状态 1:正常 2:已删除
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function updateArticleAnnexStatus(int $user_id, int $annex_id, int $status)
|
||||
|
@ -563,6 +581,7 @@ class ArticleService extends BaseService
|
|||
* 回收站附件列表
|
||||
*
|
||||
* @param int $uid 用户ID
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function recoverAnnexList(int $uid)
|
||||
|
@ -582,14 +601,16 @@ class ArticleService extends BaseService
|
|||
/**
|
||||
* 永久删除笔记附件(从磁盘中永久删除)
|
||||
*
|
||||
* @param int $uid 用户ID
|
||||
* @param int $uid 用户ID
|
||||
* @param int $annex_id 笔记附件ID
|
||||
*
|
||||
* @return bool|int|mixed|null
|
||||
*/
|
||||
|
||||
/**
|
||||
* @param int $uid
|
||||
* @param int $annex_id
|
||||
*
|
||||
* @return bool|int|mixed|null
|
||||
* @throws Exception
|
||||
*/
|
||||
|
@ -611,9 +632,10 @@ class ArticleService extends BaseService
|
|||
/**
|
||||
* 添加笔记附件
|
||||
*
|
||||
* @param int $user_id 用户id
|
||||
* @param int $article_id 笔记ID
|
||||
* @param array $annex 笔记附件信息
|
||||
* @param int $user_id 用户id
|
||||
* @param int $article_id 笔记ID
|
||||
* @param array $annex 笔记附件信息
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function insertArticleAnnex(int $user_id, int $article_id, array $annex)
|
||||
|
@ -623,13 +645,13 @@ class ArticleService extends BaseService
|
|||
}
|
||||
|
||||
$result = ArticleAnnex::create([
|
||||
'user_id' => $user_id,
|
||||
'article_id' => $article_id,
|
||||
'file_suffix' => $annex['file_suffix'],
|
||||
'file_size' => $annex['file_size'],
|
||||
'save_dir' => $annex['save_dir'],
|
||||
'user_id' => $user_id,
|
||||
'article_id' => $article_id,
|
||||
'file_suffix' => $annex['file_suffix'],
|
||||
'file_size' => $annex['file_size'],
|
||||
'save_dir' => $annex['save_dir'],
|
||||
'original_name' => $annex['original_name'],
|
||||
'created_at' => date('Y-m-d H:i:s')
|
||||
'created_at' => date('Y-m-d H:i:s')
|
||||
]);
|
||||
|
||||
return $result ? $result->id : false;
|
||||
|
|
|
@ -33,12 +33,13 @@ class ContactsService extends BaseService
|
|||
* 获取联系人列表
|
||||
*
|
||||
* @param int $user_id 用户ID
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getContacts(int $user_id): array
|
||||
{
|
||||
$prefix = config('databases.default.prefix');
|
||||
$sql = <<<SQL
|
||||
$sql = <<<SQL
|
||||
SELECT users.id,users.nickname,users.avatar,users.motto,users.gender,tmp_table.friend_remark from {$prefix}users users
|
||||
INNER join
|
||||
(
|
||||
|
@ -60,9 +61,10 @@ SQL;
|
|||
/**
|
||||
* 添加联系人/申请
|
||||
*
|
||||
* @param int $user_id 用户ID
|
||||
* @param int $friend_id 好友ID
|
||||
* @param string $remarks 申请备注
|
||||
* @param int $user_id 用户ID
|
||||
* @param int $friend_id 好友ID
|
||||
* @param string $remarks 申请备注
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function addContact(int $user_id, int $friend_id, string $remarks): bool
|
||||
|
@ -76,16 +78,16 @@ SQL;
|
|||
->orderBy('id', 'desc')->first();
|
||||
|
||||
if ($result && $result->status == 0) {
|
||||
$result->remarks = $remarks;
|
||||
$result->remarks = $remarks;
|
||||
$result->updated_at = date('Y-m-d H:i:s');
|
||||
$result->save();
|
||||
return true;
|
||||
} else {
|
||||
$result = UsersFriendsApply::create([
|
||||
'user_id' => $user_id,
|
||||
'friend_id' => $friend_id,
|
||||
'status' => 0,
|
||||
'remarks' => $remarks,
|
||||
'user_id' => $user_id,
|
||||
'friend_id' => $friend_id,
|
||||
'status' => 0,
|
||||
'remarks' => $remarks,
|
||||
'created_at' => date('Y-m-d H:i:s'),
|
||||
'updated_at' => date('Y-m-d H:i:s')
|
||||
]);
|
||||
|
@ -97,8 +99,9 @@ SQL;
|
|||
/**
|
||||
* 删除联系人
|
||||
*
|
||||
* @param int $user_id 用户ID
|
||||
* @param int $user_id 用户ID
|
||||
* @param int $friend_id 好友ID
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function deleteContact(int $user_id, int $friend_id): bool
|
||||
|
@ -120,9 +123,10 @@ SQL;
|
|||
/**
|
||||
* 同意添加联系人 / 联系人申请
|
||||
*
|
||||
* @param int $user_id 用户ID
|
||||
* @param int $apply_id 联系人申请ID
|
||||
* @param string $remarks 联系人备注名称
|
||||
* @param int $user_id 用户ID
|
||||
* @param int $apply_id 联系人申请ID
|
||||
* @param string $remarks 联系人备注名称
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function acceptInvitation(int $user_id, int $apply_id, string $remarks = ''): bool
|
||||
|
@ -159,14 +163,14 @@ SQL;
|
|||
$friend_nickname = User::where('id', $info->friend_id)->value('nickname');
|
||||
|
||||
UsersFriend::create([
|
||||
'user1' => $user1,
|
||||
'user2' => $user2,
|
||||
'user1' => $user1,
|
||||
'user2' => $user2,
|
||||
'user1_remark' => $user1 == $user_id ? $remarks : $friend_nickname,
|
||||
'user2_remark' => $user2 == $user_id ? $remarks : $friend_nickname,
|
||||
'active' => $user1 == $user_id ? 2 : 1,
|
||||
'status' => 1,
|
||||
'agree_time' => date('Y-m-d H:i:s'),
|
||||
'created_at' => date('Y-m-d H:i:s')
|
||||
'active' => $user1 == $user_id ? 2 : 1,
|
||||
'status' => 1,
|
||||
'agree_time' => date('Y-m-d H:i:s'),
|
||||
'created_at' => date('Y-m-d H:i:s')
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -182,9 +186,10 @@ SQL;
|
|||
/**
|
||||
* 拒绝添加联系人 / 联系人申请
|
||||
*
|
||||
* @param int $user_id 用户ID
|
||||
* @param int $apply_id 联系人申请ID
|
||||
* @param string $remarks 拒绝申请备注信息
|
||||
* @param int $user_id 用户ID
|
||||
* @param int $apply_id 联系人申请ID
|
||||
* @param string $remarks 拒绝申请备注信息
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function declineInvitation(int $user_id, int $apply_id, string $remarks = ''): bool
|
||||
|
@ -194,8 +199,8 @@ SQL;
|
|||
['user_id', '=', $user_id],
|
||||
['status', '=', 2],
|
||||
])->update([
|
||||
'status' => 2,
|
||||
'remarks' => $remarks,
|
||||
'status' => 2,
|
||||
'remarks' => $remarks,
|
||||
'updated_at' => date('Y-m-d H:i:s')
|
||||
]);
|
||||
|
||||
|
@ -205,9 +210,10 @@ SQL;
|
|||
/**
|
||||
* 编辑联系人备注
|
||||
*
|
||||
* @param int $user_id 用户ID
|
||||
* @param int $friend_id 朋友ID
|
||||
* @param string $remarks 好友备注名称
|
||||
* @param int $user_id 用户ID
|
||||
* @param int $friend_id 朋友ID
|
||||
* @param string $remarks 好友备注名称
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function editContactRemark(int $user_id, int $friend_id, string $remarks): bool
|
||||
|
@ -227,6 +233,7 @@ SQL;
|
|||
* 搜索联系人
|
||||
*
|
||||
* @param string $mobile 用户手机号/登录账号
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function findContact(string $mobile): array
|
||||
|
@ -239,9 +246,10 @@ SQL;
|
|||
/**
|
||||
* 获取联系人申请记录
|
||||
*
|
||||
* @param int $user_id 用户ID
|
||||
* @param int $page 当前分页
|
||||
* @param int $user_id 用户ID
|
||||
* @param int $page 当前分页
|
||||
* @param int $page_size 分页大小
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getContactApplyRecords(int $user_id, $page = 1, $page_size = 30): array
|
||||
|
@ -262,7 +270,7 @@ SQL;
|
|||
$rowsSqlObj->where('users_friends_apply.friend_id', $user_id);
|
||||
|
||||
$count = $rowsSqlObj->count();
|
||||
$rows = [];
|
||||
$rows = [];
|
||||
if ($count > 0) {
|
||||
$rows = $rowsSqlObj->orderBy('users_friends_apply.id', 'desc')->forPage($page, $page_size)->get()->toArray();
|
||||
}
|
||||
|
@ -273,8 +281,9 @@ SQL;
|
|||
/**
|
||||
* 删除联系人申请记录
|
||||
*
|
||||
* @param int $user_id 用户ID
|
||||
* @param int $user_id 用户ID
|
||||
* @param int $apply_id 联系人好友申请ID
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function delContactApplyRecord(int $user_id, int $apply_id): bool
|
||||
|
|
|
@ -12,6 +12,7 @@ use App\Model\UsersEmoticon;
|
|||
* 表情服务层
|
||||
*
|
||||
* Class EmoticonService
|
||||
*
|
||||
* @package App\Services
|
||||
*/
|
||||
class EmoticonService extends BaseService
|
||||
|
@ -19,8 +20,9 @@ class EmoticonService extends BaseService
|
|||
/**
|
||||
* 安装系统表情包
|
||||
*
|
||||
* @param int $user_id 用户ID
|
||||
* @param int $user_id 用户ID
|
||||
* @param int $emoticon_id 表情包ID
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function installSysEmoticon(int $user_id, int $emoticon_id)
|
||||
|
@ -44,8 +46,9 @@ class EmoticonService extends BaseService
|
|||
/**
|
||||
* 移除已安装的系统表情包
|
||||
*
|
||||
* @param int $user_id 用户ID
|
||||
* @param int $user_id 用户ID
|
||||
* @param int $emoticon_id 表情包ID
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function removeSysEmoticon(int $user_id, int $emoticon_id)
|
||||
|
@ -75,6 +78,7 @@ class EmoticonService extends BaseService
|
|||
* 获取用户安装的表情ID
|
||||
*
|
||||
* @param int $user_id 用户ID
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getInstallIds(int $user_id)
|
||||
|
@ -86,8 +90,9 @@ class EmoticonService extends BaseService
|
|||
/**
|
||||
* 收藏聊天图片
|
||||
*
|
||||
* @param int $user_id 用户ID
|
||||
* @param int $user_id 用户ID
|
||||
* @param int $record_id 聊天消息ID
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function collect(int $user_id, int $record_id)
|
||||
|
@ -128,11 +133,11 @@ class EmoticonService extends BaseService
|
|||
}
|
||||
|
||||
$res = EmoticonDetail::create([
|
||||
'user_id' => $user_id,
|
||||
'url' => $fileInfo->save_dir,
|
||||
'user_id' => $user_id,
|
||||
'url' => $fileInfo->save_dir,
|
||||
'file_suffix' => $fileInfo->file_suffix,
|
||||
'file_size' => $fileInfo->file_size,
|
||||
'created_at' => time()
|
||||
'file_size' => $fileInfo->file_size,
|
||||
'created_at' => time()
|
||||
]);
|
||||
|
||||
return $res ? [true, ['media_id' => $res->id, 'src' => get_media_url($res->url)]] : [false, []];
|
||||
|
@ -141,8 +146,9 @@ class EmoticonService extends BaseService
|
|||
/**
|
||||
* 移除收藏的表情包
|
||||
*
|
||||
* @param int $user_id 用户ID
|
||||
* @param array $ids 表情包详情ID
|
||||
* @param int $user_id 用户ID
|
||||
* @param array $ids 表情包详情ID
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public function deleteCollect(int $user_id, array $ids)
|
||||
|
@ -154,6 +160,7 @@ class EmoticonService extends BaseService
|
|||
* 获取表情包列表
|
||||
*
|
||||
* @param array $where
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getDetailsAll(array $where = [])
|
||||
|
|
|
@ -23,6 +23,7 @@ class GroupService extends BaseService
|
|||
* 获取用户所在的群聊
|
||||
*
|
||||
* @param int $user_id 用户ID
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getGroups(int $user_id): array
|
||||
|
@ -56,9 +57,10 @@ class GroupService extends BaseService
|
|||
/**
|
||||
* 创建群组
|
||||
*
|
||||
* @param int $user_id 用户ID
|
||||
* @param int $user_id 用户ID
|
||||
* @param array $group_info 群聊名称
|
||||
* @param array $friend_ids 好友的用户ID
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function create(int $user_id, array $group_info, $friend_ids = [])
|
||||
|
@ -143,7 +145,8 @@ class GroupService extends BaseService
|
|||
* 解散群组(群主权限)
|
||||
*
|
||||
* @param int $group_id 群ID
|
||||
* @param int $user_id 用户ID
|
||||
* @param int $user_id 用户ID
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function dismiss(int $group_id, int $user_id)
|
||||
|
@ -171,9 +174,10 @@ class GroupService extends BaseService
|
|||
/**
|
||||
* 邀请加入群组
|
||||
*
|
||||
* @param int $user_id 用户ID
|
||||
* @param int $group_id 聊天群ID
|
||||
* @param int $user_id 用户ID
|
||||
* @param int $group_id 聊天群ID
|
||||
* @param array $friend_ids 被邀请的用户ID
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function invite(int $user_id, int $group_id, $friend_ids = [])
|
||||
|
@ -276,8 +280,9 @@ class GroupService extends BaseService
|
|||
/**
|
||||
* 退出群组(仅普通管理员及群成员)
|
||||
*
|
||||
* @param int $user_id 用户ID
|
||||
* @param int $user_id 用户ID
|
||||
* @param int $group_id 群组ID
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function quit(int $user_id, int $group_id)
|
||||
|
@ -329,9 +334,10 @@ class GroupService extends BaseService
|
|||
/**
|
||||
* 踢出群组(管理员特殊权限)
|
||||
*
|
||||
* @param int $group_id 群ID
|
||||
* @param int $user_id 操作用户ID
|
||||
* @param int $group_id 群ID
|
||||
* @param int $user_id 操作用户ID
|
||||
* @param array $member_ids 群成员ID
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function removeMember(int $group_id, int $user_id, array $member_ids)
|
||||
|
|
|
@ -7,6 +7,7 @@ use PHPMailer\PHPMailer\Exception;
|
|||
|
||||
/**
|
||||
* Class MailerService
|
||||
*
|
||||
* @package App\Service
|
||||
*/
|
||||
class MailerService
|
||||
|
@ -21,9 +22,10 @@ class MailerService
|
|||
/**
|
||||
* 发送邮件
|
||||
*
|
||||
* @param string $email 邮箱
|
||||
* @param string $subject 标题
|
||||
* @param string $email 邮箱
|
||||
* @param string $subject 标题
|
||||
* @param string $template 对应邮件模板
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function send($email, $subject, $template)
|
||||
|
@ -38,9 +40,10 @@ class MailerService
|
|||
/**
|
||||
* 发送邮件
|
||||
*
|
||||
* @param string $email 邮箱
|
||||
* @param string $subject 标题
|
||||
* @param string $email 邮箱
|
||||
* @param string $subject 标题
|
||||
* @param string $template 对应邮件模板
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function realSend($email, $subject, $template)
|
||||
|
@ -57,7 +60,8 @@ class MailerService
|
|||
*
|
||||
* @param string $address 收件人
|
||||
* @param string $subject 邮件标题
|
||||
* @param string $view 邮件内容
|
||||
* @param string $view 邮件内容
|
||||
*
|
||||
* @return bool
|
||||
* @throws Exception
|
||||
*/
|
||||
|
@ -66,10 +70,10 @@ class MailerService
|
|||
$config = config('mail');
|
||||
$mail = new PHPMailer();
|
||||
$mail->CharSet = 'UTF-8';
|
||||
$mail->IsSMTP(); // 设定使用SMTP服务
|
||||
$mail->SMTPDebug = 0; // 关闭SMTP调试功能
|
||||
$mail->SMTPAuth = true; // 启用 SMTP 验证功能
|
||||
$mail->SMTPSecure = 'ssl'; // 使用安全协议
|
||||
$mail->IsSMTP(); // 设定使用SMTP服务
|
||||
$mail->SMTPDebug = 0; // 关闭SMTP调试功能
|
||||
$mail->SMTPAuth = true; // 启用 SMTP 验证功能
|
||||
$mail->SMTPSecure = 'ssl'; // 使用安全协议
|
||||
$mail->Host = $config['host'];
|
||||
$mail->Port = $config['port'];
|
||||
$mail->Username = $config['username'];
|
||||
|
|
|
@ -38,8 +38,9 @@ class MessageHandleService
|
|||
* 对话消息
|
||||
*
|
||||
* @param Response|Server $server
|
||||
* @param Frame $frame
|
||||
* @param array|string $data 解析后数据
|
||||
* @param Frame $frame
|
||||
* @param array|string $data 解析后数据
|
||||
*
|
||||
* @return bool|void
|
||||
*/
|
||||
public function onTalk($server, Frame $frame, $data)
|
||||
|
@ -68,11 +69,11 @@ class MessageHandleService
|
|||
}
|
||||
|
||||
$result = ChatRecord::create([
|
||||
'source' => $data['source_type'],
|
||||
'msg_type' => 1,
|
||||
'user_id' => $data['send_user'],
|
||||
'source' => $data['source_type'],
|
||||
'msg_type' => 1,
|
||||
'user_id' => $data['send_user'],
|
||||
'receive_id' => $data['receive_user'],
|
||||
'content' => htmlspecialchars($data['text_message']),
|
||||
'content' => htmlspecialchars($data['text_message']),
|
||||
'created_at' => date('Y-m-d H:i:s'),
|
||||
]);
|
||||
|
||||
|
@ -86,7 +87,7 @@ class MessageHandleService
|
|||
|
||||
// 缓存最后一条消息
|
||||
LastMsgCache::set([
|
||||
'text' => mb_substr($result->content, 0, 30),
|
||||
'text' => mb_substr($result->content, 0, 30),
|
||||
'created_at' => $result->created_at
|
||||
], (int)$data['receive_user'],
|
||||
$data['source_type'] == 1 ? (int)$data['send_user'] : 0
|
||||
|
@ -94,9 +95,9 @@ class MessageHandleService
|
|||
|
||||
$this->producer->produce(
|
||||
new ChatMessageProducer('event_talk', [
|
||||
'sender' => intval($data['send_user']), //发送者ID
|
||||
'receive' => intval($data['receive_user']), //接收者ID
|
||||
'source' => intval($data['source_type']), //接收者类型 1:好友;2:群组
|
||||
'sender' => intval($data['send_user']), //发送者ID
|
||||
'receive' => intval($data['receive_user']), //接收者ID
|
||||
'source' => intval($data['source_type']), //接收者类型 1:好友;2:群组
|
||||
'record_id' => $result->id
|
||||
])
|
||||
);
|
||||
|
@ -106,15 +107,16 @@ class MessageHandleService
|
|||
* 键盘输入消息
|
||||
*
|
||||
* @param Response|Server $server
|
||||
* @param Frame $frame
|
||||
* @param array|string $data 解析后数据
|
||||
* @param Frame $frame
|
||||
* @param array|string $data 解析后数据
|
||||
*
|
||||
* @return bool|void
|
||||
*/
|
||||
public function onKeyboard($server, Frame $frame, $data)
|
||||
{
|
||||
$this->producer->produce(
|
||||
new ChatMessageProducer('event_keyboard', [
|
||||
'send_user' => intval($data['send_user']), //发送者ID
|
||||
'send_user' => intval($data['send_user']), //发送者ID
|
||||
'receive_user' => intval($data['receive_user']), //接收者ID
|
||||
])
|
||||
);
|
||||
|
|
|
@ -6,6 +6,7 @@ namespace App\Service;
|
|||
* 短信发送服务
|
||||
*
|
||||
* Class SmsCodeService
|
||||
*
|
||||
* @package App\Services
|
||||
*/
|
||||
class SmsCodeService
|
||||
|
@ -32,8 +33,9 @@ class SmsCodeService
|
|||
/**
|
||||
* 获取缓存key
|
||||
*
|
||||
* @param string $type 短信用途
|
||||
* @param string $type 短信用途
|
||||
* @param string $mobile 手机号
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function getKey(string $type, string $mobile)
|
||||
|
@ -44,9 +46,10 @@ class SmsCodeService
|
|||
/**
|
||||
* 检测验证码是否正确
|
||||
*
|
||||
* @param string $type 发送类型
|
||||
* @param string $type 发送类型
|
||||
* @param string $mobile 手机号
|
||||
* @param string $code 验证码
|
||||
* @param string $code 验证码
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function check(string $type, string $mobile, string $code)
|
||||
|
@ -59,15 +62,16 @@ class SmsCodeService
|
|||
/**
|
||||
* 发送验证码
|
||||
*
|
||||
* @param string $usage 验证码用途
|
||||
* @param string $usage 验证码用途
|
||||
* @param string $mobile 手机号
|
||||
*
|
||||
* @return array|bool
|
||||
*/
|
||||
public function send(string $usage, string $mobile)
|
||||
{
|
||||
if (!$this->isUsages($usage)) {
|
||||
return [false, [
|
||||
'msg' => "[{$usage}]:此类短信验证码不支持发送",
|
||||
'msg' => "[{$usage}]:此类短信验证码不支持发送",
|
||||
'data' => []
|
||||
]];
|
||||
}
|
||||
|
@ -90,7 +94,7 @@ class SmsCodeService
|
|||
// ... 调取短信接口,建议异步任务执行 (暂无短信接口,省略处理)
|
||||
|
||||
return [true, [
|
||||
'msg' => 'success',
|
||||
'msg' => 'success',
|
||||
'data' => ['type' => $usage, 'code' => $sms_code]
|
||||
]];
|
||||
}
|
||||
|
@ -99,6 +103,7 @@ class SmsCodeService
|
|||
* 获取缓存的验证码
|
||||
*
|
||||
* @param string $key
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getCode(string $key)
|
||||
|
@ -109,9 +114,10 @@ class SmsCodeService
|
|||
/**
|
||||
* 设置验证码缓存
|
||||
*
|
||||
* @param string $key 缓存key
|
||||
* @param string $sms_code 验证码
|
||||
* @param float|int $exp 过期时间(默认15分钟)
|
||||
* @param string $key 缓存key
|
||||
* @param string $sms_code 验证码
|
||||
* @param float|int $exp 过期时间(默认15分钟)
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function setCode(string $key, string $sms_code, $exp = 60 * 15)
|
||||
|
@ -122,8 +128,9 @@ class SmsCodeService
|
|||
/**
|
||||
* 删除验证码缓存
|
||||
*
|
||||
* @param string $usage 验证码用途
|
||||
* @param string $usage 验证码用途
|
||||
* @param string $mobile 手机号
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function delCode(string $usage, string $mobile)
|
||||
|
@ -134,8 +141,9 @@ class SmsCodeService
|
|||
/**
|
||||
* 短信发送过滤验证
|
||||
*
|
||||
* @param string $usage 验证码用途
|
||||
* @param string $usage 验证码用途
|
||||
* @param string $mobile 手机号
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function filter(string $usage, string $mobile)
|
||||
|
@ -143,13 +151,13 @@ class SmsCodeService
|
|||
// ... 省略处理
|
||||
if (false) {
|
||||
return [false, [
|
||||
'msg' => '过滤原因...',
|
||||
'msg' => '过滤原因...',
|
||||
'data' => []
|
||||
]];
|
||||
}
|
||||
|
||||
return [true, [
|
||||
'msg' => 'ok',
|
||||
'msg' => 'ok',
|
||||
'data' => []
|
||||
]];
|
||||
}
|
||||
|
@ -158,6 +166,7 @@ class SmsCodeService
|
|||
* 判断验证码用途渠道是否注册
|
||||
*
|
||||
* @param string $usage
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isUsages(string $usage)
|
||||
|
|
|
@ -5,6 +5,7 @@ namespace App\Service;
|
|||
/**
|
||||
* 短信服务
|
||||
* Class SmsService
|
||||
*
|
||||
* @package App\Service
|
||||
*/
|
||||
class SmsService
|
||||
|
|
|
@ -39,9 +39,10 @@ class SocketClientService
|
|||
/**
|
||||
* 客户端fd与用户ID绑定关系
|
||||
*
|
||||
* @param int $fd 客户端fd
|
||||
* @param int $user_id 用户ID
|
||||
* @param string $run_id 服务运行ID(默认当前服务ID)
|
||||
* @param int $fd 客户端fd
|
||||
* @param int $user_id 用户ID
|
||||
* @param string $run_id 服务运行ID(默认当前服务ID)
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function bindRelation(int $fd, int $user_id, $run_id = SERVER_RUN_ID)
|
||||
|
@ -55,7 +56,7 @@ class SocketClientService
|
|||
/**
|
||||
* 解除指定的客户端fd与用户绑定关系
|
||||
*
|
||||
* @param int $fd 客户端ID
|
||||
* @param int $fd 客户端ID
|
||||
* @param string $run_id 服务运行ID(默认当前服务ID)
|
||||
*/
|
||||
public function removeRelation(int $fd, $run_id = SERVER_RUN_ID)
|
||||
|
@ -69,8 +70,9 @@ class SocketClientService
|
|||
/**
|
||||
* 检测用户当前是否在线(指定运行服务器)
|
||||
*
|
||||
* @param int $user_id 用户ID
|
||||
* @param string $run_id 服务运行ID(默认当前服务ID)
|
||||
* @param int $user_id 用户ID
|
||||
* @param string $run_id 服务运行ID(默认当前服务ID)
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isOnline(int $user_id, $run_id = SERVER_RUN_ID): bool
|
||||
|
@ -81,8 +83,9 @@ class SocketClientService
|
|||
/**
|
||||
* 检测用户当前是否在线(查询所有在线服务器)
|
||||
*
|
||||
* @param int $user_id 用户ID
|
||||
* @param int $user_id 用户ID
|
||||
* @param array $run_ids 服务运行ID
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isOnlineAll(int $user_id, array $run_ids = [])
|
||||
|
@ -99,8 +102,9 @@ class SocketClientService
|
|||
/**
|
||||
* 查询客户端fd对应的用户ID
|
||||
*
|
||||
* @param int $fd 客户端ID
|
||||
* @param int $fd 客户端ID
|
||||
* @param string $run_id 服务运行ID(默认当前服务ID)
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function findFdUserId(int $fd, $run_id = SERVER_RUN_ID)
|
||||
|
@ -111,8 +115,9 @@ class SocketClientService
|
|||
/**
|
||||
* 查询用户的客户端fd集合(用户可能存在多端登录)
|
||||
*
|
||||
* @param int $user_id 用户ID
|
||||
* @param string $run_id 服务运行ID(默认当前服务ID)
|
||||
* @param int $user_id 用户ID
|
||||
* @param string $run_id 服务运行ID(默认当前服务ID)
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function findUserFds(int $user_id, $run_id = SERVER_RUN_ID)
|
||||
|
@ -127,6 +132,7 @@ class SocketClientService
|
|||
* 获取服务ID列表
|
||||
*
|
||||
* @param int $type 获取类型[1:正在运行;2:已超时;3:所有]
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getServerRunIdAll(int $type = 1)
|
||||
|
|
|
@ -6,6 +6,7 @@ namespace App\Service;
|
|||
* 聊天室房间服务
|
||||
*
|
||||
* Class SocketRoomService
|
||||
*
|
||||
* @package App\Service
|
||||
*/
|
||||
class SocketRoomService
|
||||
|
@ -16,6 +17,7 @@ class SocketRoomService
|
|||
* 获取房间名
|
||||
*
|
||||
* @param string|integer $room 房间名
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getRoomName($room)
|
||||
|
@ -27,6 +29,7 @@ class SocketRoomService
|
|||
* 获取房间成员
|
||||
*
|
||||
* @param string $room 房间名
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getRoomMembers(string $room)
|
||||
|
@ -37,8 +40,9 @@ class SocketRoomService
|
|||
/**
|
||||
* 成员加入房间
|
||||
*
|
||||
* @param int $usr_id 用户ID
|
||||
* @param string|array $room 房间名
|
||||
* @param int $usr_id 用户ID
|
||||
* @param string|array $room 房间名
|
||||
*
|
||||
* @return bool|int
|
||||
*/
|
||||
public function addRoomMember(int $usr_id, $room)
|
||||
|
@ -49,8 +53,9 @@ class SocketRoomService
|
|||
/**
|
||||
* 成员退出房间
|
||||
*
|
||||
* @param string|array $room 房间名
|
||||
* @param string|array $room 房间名
|
||||
* @param string|array $members 用户ID
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function delRoomMember($room, $members)
|
||||
|
@ -62,6 +67,7 @@ class SocketRoomService
|
|||
* 删除房间
|
||||
*
|
||||
* @param string|int $room 房间名
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function delRoom($room)
|
||||
|
|
|
@ -10,6 +10,7 @@ use Hyperf\HttpMessage\Upload\UploadedFile;
|
|||
* 文件拆分上传服务
|
||||
*
|
||||
* Class SplitUploadService
|
||||
*
|
||||
* @package App\Service
|
||||
*/
|
||||
class SplitUploadService
|
||||
|
@ -22,7 +23,7 @@ class SplitUploadService
|
|||
/**
|
||||
* 创建文件拆分相关信息
|
||||
*
|
||||
* @param int $user_id 用户ID
|
||||
* @param int $user_id 用户ID
|
||||
* @param string $fileName 上传的文件名
|
||||
* @param string $fileSize 上传文件大小
|
||||
*
|
||||
|
@ -33,17 +34,17 @@ class SplitUploadService
|
|||
$hash_name = implode('-', [uniqid(), rand(10000000, 99999999), Str::random(6)]);
|
||||
$split_num = intval(ceil($fileSize / self::SPLIT_SIZE));
|
||||
|
||||
$data = [];
|
||||
$data['file_type'] = 1;
|
||||
$data['user_id'] = $user_id;
|
||||
$data = [];
|
||||
$data['file_type'] = 1;
|
||||
$data['user_id'] = $user_id;
|
||||
$data['original_name'] = $fileName;
|
||||
$data['hash_name'] = $hash_name;
|
||||
$data['file_ext'] = pathinfo($fileName, PATHINFO_EXTENSION);
|
||||
$data['file_size'] = $fileSize;
|
||||
$data['upload_at'] = time();
|
||||
$data['hash_name'] = $hash_name;
|
||||
$data['file_ext'] = pathinfo($fileName, PATHINFO_EXTENSION);
|
||||
$data['file_size'] = $fileSize;
|
||||
$data['upload_at'] = time();
|
||||
|
||||
//文件拆分数量
|
||||
$data['split_num'] = $split_num;
|
||||
$data['split_num'] = $split_num;
|
||||
$data['split_index'] = $split_num;
|
||||
|
||||
return FileSplitUpload::create($data) ? array_merge($data, ['split_size' => self::SPLIT_SIZE]) : false;
|
||||
|
@ -52,11 +53,11 @@ class SplitUploadService
|
|||
/**
|
||||
* 保存拆分上传的文件
|
||||
*
|
||||
* @param int $user_id 用户ID
|
||||
* @param UploadedFile $file 文件信息
|
||||
* @param string $hashName 上传临时问价hash名
|
||||
* @param int $split_index 当前拆分文件索引
|
||||
* @param int $fileSize 文件大小
|
||||
* @param int $user_id 用户ID
|
||||
* @param UploadedFile $file 文件信息
|
||||
* @param string $hashName 上传临时问价hash名
|
||||
* @param int $split_index 当前拆分文件索引
|
||||
* @param int $fileSize 文件大小
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
|
@ -71,7 +72,7 @@ class SplitUploadService
|
|||
}
|
||||
|
||||
// 保存文件名及保存文件相对目录
|
||||
$fileName = "{$hashName}_{$split_index}_{$fileInfo->file_ext}.tmp";
|
||||
$fileName = "{$hashName}_{$split_index}_{$fileInfo->file_ext}.tmp";
|
||||
$uploadService = make(UploadService::class);
|
||||
|
||||
$uploadService->makeDirectory($uploadService->driver("tmp/{$hashName}"));
|
||||
|
@ -83,18 +84,18 @@ class SplitUploadService
|
|||
|
||||
$info = FileSplitUpload::where('user_id', $user_id)->where('hash_name', $hashName)->where('split_index', $split_index)->first();
|
||||
if (!$info) {
|
||||
return FileSplitUpload::create([
|
||||
'user_id' => $user_id,
|
||||
'file_type' => 2,
|
||||
'hash_name' => $hashName,
|
||||
return (bool)FileSplitUpload::create([
|
||||
'user_id' => $user_id,
|
||||
'file_type' => 2,
|
||||
'hash_name' => $hashName,
|
||||
'original_name' => $fileInfo->original_name,
|
||||
'split_index' => $split_index,
|
||||
'split_num' => $fileInfo->split_num,
|
||||
'save_dir' => sprintf('%s/%s', "tmp/{$hashName}", $fileName),
|
||||
'file_ext' => $fileInfo->file_ext,
|
||||
'file_size' => $fileSize,
|
||||
'upload_at' => time(),
|
||||
]) ? true : false;
|
||||
'split_index' => $split_index,
|
||||
'split_num' => $fileInfo->split_num,
|
||||
'save_dir' => sprintf('%s/%s', "tmp/{$hashName}", $fileName),
|
||||
'file_ext' => $fileInfo->file_ext,
|
||||
'file_size' => $fileSize,
|
||||
'upload_at' => time(),
|
||||
]);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -103,7 +104,7 @@ class SplitUploadService
|
|||
/**
|
||||
* 文件合并
|
||||
*
|
||||
* @param int $user_id 用户ID
|
||||
* @param int $user_id 用户ID
|
||||
* @param string $hash_name 上传临时问价hash名
|
||||
*
|
||||
* @return array|bool
|
||||
|
@ -134,7 +135,7 @@ class SplitUploadService
|
|||
return false;
|
||||
}
|
||||
|
||||
$fileMerge = "tmp/{$hash_name}/{$fileInfo->original_name}.tmp";
|
||||
$fileMerge = "tmp/{$hash_name}/{$fileInfo->original_name}.tmp";
|
||||
$uploadService = make(UploadService::class);
|
||||
|
||||
// 文件合并
|
||||
|
@ -149,10 +150,10 @@ class SplitUploadService
|
|||
->update(['save_dir' => $fileMerge]);
|
||||
|
||||
return [
|
||||
'path' => $fileMerge,
|
||||
'path' => $fileMerge,
|
||||
'tmp_file_name' => "{$fileInfo->original_name}.tmp",
|
||||
'original_name' => $fileInfo->original_name,
|
||||
'file_size' => $fileInfo->file_size
|
||||
'file_size' => $fileInfo->file_size
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@ class TalkService extends BaseService
|
|||
* 获取用户的聊天列表
|
||||
*
|
||||
* @param int $user_id 用户ID
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function talks(int $user_id)
|
||||
|
@ -56,7 +57,7 @@ class TalkService extends BaseService
|
|||
$data['friend_id'] = $item['friend_id'];
|
||||
$data['group_id'] = $item['group_id'];
|
||||
$data['name'] = '';//对方昵称/群名称
|
||||
$data['unread_num'] = 0;//未读消息数量
|
||||
$data['unread_num'] = 0; //未读消息数量
|
||||
$data['avatar'] = '';//默认头像
|
||||
$data['remark_name'] = '';//好友备注
|
||||
$data['msg_text'] = '......';
|
||||
|
@ -105,17 +106,17 @@ class TalkService extends BaseService
|
|||
* 同步未读的消息到数据库中
|
||||
*
|
||||
* @param int $user_id 用户ID
|
||||
* @param $data
|
||||
* @param $data
|
||||
*/
|
||||
public function updateUnreadTalkList(int $user_id, $data)
|
||||
{
|
||||
foreach ($data as $friend_id => $num) {
|
||||
UsersChatList::updateOrCreate([
|
||||
'uid' => $user_id,
|
||||
'uid' => $user_id,
|
||||
'friend_id' => intval($friend_id),
|
||||
'type' => 1
|
||||
'type' => 1
|
||||
], [
|
||||
'status' => 1,
|
||||
'status' => 1,
|
||||
'created_at' => date('Y-m-d H:i:s'),
|
||||
'updated_at' => date('Y-m-d H:i:s')
|
||||
]);
|
||||
|
@ -126,6 +127,7 @@ class TalkService extends BaseService
|
|||
* 处理聊天记录信息
|
||||
*
|
||||
* @param array $rows 聊天记录
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function handleChatRecords(array $rows)
|
||||
|
@ -186,12 +188,12 @@ class TalkService extends BaseService
|
|||
case 3://3:入群消息/退群消息
|
||||
if (isset($invites[$row['id']])) {
|
||||
$rows[$k]['invite'] = [
|
||||
'type' => $invites[$row['id']]['type'],
|
||||
'type' => $invites[$row['id']]['type'],
|
||||
'operate_user' => [
|
||||
'id' => $invites[$row['id']]['operate_user_id'],
|
||||
'id' => $invites[$row['id']]['operate_user_id'],
|
||||
'nickname' => User::where('id', $invites[$row['id']]['operate_user_id'])->value('nickname')
|
||||
],
|
||||
'users' => []
|
||||
'users' => []
|
||||
];
|
||||
|
||||
if ($rows[$k]['invite']['type'] == 1 || $rows[$k]['invite']['type'] == 3) {
|
||||
|
@ -204,7 +206,7 @@ class TalkService extends BaseService
|
|||
case 4://4:会话记录消息
|
||||
if (isset($forwards[$row['id']])) {
|
||||
$rows[$k]['forward'] = [
|
||||
'num' => substr_count($forwards[$row['id']]['records_id'], ',') + 1,
|
||||
'num' => substr_count($forwards[$row['id']]['records_id'], ',') + 1,
|
||||
'list' => json_decode($forwards[$row['id']]['text'], true) ?? []
|
||||
];
|
||||
}
|
||||
|
@ -226,12 +228,13 @@ class TalkService extends BaseService
|
|||
/**
|
||||
* 查询对话页面的历史聊天记录
|
||||
*
|
||||
* @param int $user_id 用户ID
|
||||
* @param int $receive_id 接收者ID(好友ID或群ID)
|
||||
* @param int $source 消息来源 1:好友消息 2:群聊消息
|
||||
* @param int $record_id 上一次查询的聊天记录ID
|
||||
* @param int $limit 查询数据长度
|
||||
* @param array $msg_type 消息类型
|
||||
* @param int $user_id 用户ID
|
||||
* @param int $receive_id 接收者ID(好友ID或群ID)
|
||||
* @param int $source 消息来源 1:好友消息 2:群聊消息
|
||||
* @param int $record_id 上一次查询的聊天记录ID
|
||||
* @param int $limit 查询数据长度
|
||||
* @param array $msg_type 消息类型
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getChatRecords(int $user_id, int $receive_id, int $source, int $record_id, $limit = 30, $msg_type = [])
|
||||
|
@ -290,8 +293,9 @@ class TalkService extends BaseService
|
|||
/**
|
||||
* 获取转发会话记录信息
|
||||
*
|
||||
* @param int $user_id 用户ID
|
||||
* @param int $user_id 用户ID
|
||||
* @param int $record_id 聊天记录ID
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getForwardRecords(int $user_id, int $record_id)
|
||||
|
@ -332,10 +336,11 @@ class TalkService extends BaseService
|
|||
/**
|
||||
* 批量删除聊天消息
|
||||
*
|
||||
* @param int $user_id 用户ID
|
||||
* @param int $source 消息来源 1:好友消息 2:群聊消息
|
||||
* @param int $receive_id 好友ID或者群聊ID
|
||||
* @param int $user_id 用户ID
|
||||
* @param int $source 消息来源 1:好友消息 2:群聊消息
|
||||
* @param int $receive_id 好友ID或者群聊ID
|
||||
* @param array $record_ids 聊天记录ID
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function removeRecords(int $user_id, int $source, int $receive_id, array $record_ids)
|
||||
|
@ -360,8 +365,8 @@ class TalkService extends BaseService
|
|||
|
||||
$data = array_map(function ($record_id) use ($user_id) {
|
||||
return [
|
||||
'record_id' => $record_id,
|
||||
'user_id' => $user_id,
|
||||
'record_id' => $record_id,
|
||||
'user_id' => $user_id,
|
||||
'created_at' => date('Y-m-d H:i:s'),
|
||||
];
|
||||
}, $ids->toArray());
|
||||
|
@ -372,8 +377,9 @@ class TalkService extends BaseService
|
|||
/**
|
||||
* 撤回单条聊天消息
|
||||
*
|
||||
* @param int $user_id 用户ID
|
||||
* @param int $user_id 用户ID
|
||||
* @param int $record_id 聊天记录ID
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function revokeRecord(int $user_id, int $record_id)
|
||||
|
@ -405,9 +411,10 @@ class TalkService extends BaseService
|
|||
/**
|
||||
* 转发消息(单条转发)
|
||||
*
|
||||
* @param int $user_id 转发的用户ID
|
||||
* @param int $record_id 转发消息的记录ID
|
||||
* @param int $user_id 转发的用户ID
|
||||
* @param int $record_id 转发消息的记录ID
|
||||
* @param array $receive_ids 接受者数组 例如:[['source' => 1,'id' => 3045],['source' => 1,'id' => 3046],['source' => 1,'id' => 1658]] 二维数组
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function forwardRecords(int $user_id, int $record_id, array $receive_ids)
|
||||
|
@ -441,11 +448,11 @@ class TalkService extends BaseService
|
|||
try {
|
||||
foreach ($receive_ids as $item) {
|
||||
$res = ChatRecord::create([
|
||||
'source' => $item['source'],
|
||||
'msg_type' => $result->msg_type,
|
||||
'user_id' => $user_id,
|
||||
'source' => $item['source'],
|
||||
'msg_type' => $result->msg_type,
|
||||
'user_id' => $user_id,
|
||||
'receive_id' => $item['id'],
|
||||
'content' => $result->content,
|
||||
'content' => $result->content,
|
||||
'created_at' => date('Y-m-d H:i:s')
|
||||
]);
|
||||
|
||||
|
@ -457,25 +464,25 @@ class TalkService extends BaseService
|
|||
|
||||
if ($result->msg_type == 2) {
|
||||
if (!ChatRecordsFile::create([
|
||||
'record_id' => $res->id,
|
||||
'user_id' => $fileInfo->user_id,
|
||||
'file_source' => $fileInfo->file_source,
|
||||
'file_type' => $fileInfo->file_type,
|
||||
'save_type' => $fileInfo->save_type,
|
||||
'record_id' => $res->id,
|
||||
'user_id' => $fileInfo->user_id,
|
||||
'file_source' => $fileInfo->file_source,
|
||||
'file_type' => $fileInfo->file_type,
|
||||
'save_type' => $fileInfo->save_type,
|
||||
'original_name' => $fileInfo->original_name,
|
||||
'file_suffix' => $fileInfo->file_suffix,
|
||||
'file_size' => $fileInfo->file_size,
|
||||
'save_dir' => $fileInfo->save_dir,
|
||||
'created_at' => date('Y-m-d H:i:s')
|
||||
'file_suffix' => $fileInfo->file_suffix,
|
||||
'file_size' => $fileInfo->file_size,
|
||||
'save_dir' => $fileInfo->save_dir,
|
||||
'created_at' => date('Y-m-d H:i:s')
|
||||
])) {
|
||||
throw new Exception('插入文件消息记录失败');
|
||||
}
|
||||
} else if ($result->msg_type == 5) {
|
||||
if (!ChatRecordsCode::create([
|
||||
'record_id' => $res->id,
|
||||
'user_id' => $user_id,
|
||||
'code_lang' => $codeBlock->code_lang,
|
||||
'code' => $codeBlock->code,
|
||||
'record_id' => $res->id,
|
||||
'user_id' => $user_id,
|
||||
'code_lang' => $codeBlock->code_lang,
|
||||
'code' => $codeBlock->code,
|
||||
'created_at' => date('Y-m-d H:i:s')
|
||||
])) {
|
||||
throw new Exception('插入代码消息记录失败');
|
||||
|
@ -495,9 +502,9 @@ class TalkService extends BaseService
|
|||
/**
|
||||
* 转发消息(多条合并转发)
|
||||
*
|
||||
* @param int $user_id 转发的用户ID
|
||||
* @param int $receive_id 当前转发消息的所属者(好友ID或者群聊ID)
|
||||
* @param int $source 消息来源 1:好友消息 2:群聊消息
|
||||
* @param int $user_id 转发的用户ID
|
||||
* @param int $receive_id 当前转发消息的所属者(好友ID或者群聊ID)
|
||||
* @param int $source 消息来源 1:好友消息 2:群聊消息
|
||||
* @param array $records_ids 转发消息的记录ID
|
||||
* @param array $receive_ids 接受者数组 例如:[['source' => 1,'id' => 3045],['source' => 1,'id' => 3046],['source' => 1,'id' => 1658]] 二维数组
|
||||
*
|
||||
|
@ -552,19 +559,19 @@ class TalkService extends BaseService
|
|||
case 1:
|
||||
$jsonText[] = [
|
||||
'nickname' => $row->nickname,
|
||||
'text' => mb_substr(str_replace(PHP_EOL, "", $row->content), 0, 30)
|
||||
'text' => mb_substr(str_replace(PHP_EOL, "", $row->content), 0, 30)
|
||||
];
|
||||
break;
|
||||
case 2:
|
||||
$jsonText[] = [
|
||||
'nickname' => $row->nickname,
|
||||
'text' => '【文件消息】'
|
||||
'text' => '【文件消息】'
|
||||
];
|
||||
break;
|
||||
case 3:
|
||||
$jsonText[] = [
|
||||
'nickname' => $row->nickname,
|
||||
'text' => '【代码消息】'
|
||||
'text' => '【代码消息】'
|
||||
];
|
||||
break;
|
||||
}
|
||||
|
@ -575,9 +582,9 @@ class TalkService extends BaseService
|
|||
try {
|
||||
foreach ($receive_ids as $item) {
|
||||
$res = ChatRecord::create([
|
||||
'source' => $item['source'],
|
||||
'msg_type' => 4,
|
||||
'user_id' => $user_id,
|
||||
'source' => $item['source'],
|
||||
'msg_type' => 4,
|
||||
'user_id' => $user_id,
|
||||
'receive_id' => $item['id'],
|
||||
'created_at' => date('Y-m-d H:i:s')
|
||||
]);
|
||||
|
@ -587,16 +594,16 @@ class TalkService extends BaseService
|
|||
}
|
||||
|
||||
$insRecordIds[] = [
|
||||
'record_id' => $res->id,
|
||||
'record_id' => $res->id,
|
||||
'receive_id' => $item['id'],
|
||||
'source' => $item['source']
|
||||
'source' => $item['source']
|
||||
];
|
||||
|
||||
if (!ChatRecordsForward::create([
|
||||
'record_id' => $res->id,
|
||||
'user_id' => $user_id,
|
||||
'record_id' => $res->id,
|
||||
'user_id' => $user_id,
|
||||
'records_id' => implode(',', $records_ids),
|
||||
'text' => json_encode($jsonText),
|
||||
'text' => json_encode($jsonText),
|
||||
'created_at' => date('Y-m-d H:i:s'),
|
||||
])) {
|
||||
throw new Exception('插入转发消息失败');
|
||||
|
@ -615,12 +622,13 @@ class TalkService extends BaseService
|
|||
/**
|
||||
* 关键词搜索聊天记录
|
||||
*
|
||||
* @param int $user_id 用户ID
|
||||
* @param int $receive_id 接收者ID(用户ID或群聊接收ID)
|
||||
* @param int $source 聊天来源(1:私信 2:群聊)
|
||||
* @param int $page 当前查询分页
|
||||
* @param int $page_size 分页大小
|
||||
* @param array $params 查询参数
|
||||
* @param int $user_id 用户ID
|
||||
* @param int $receive_id 接收者ID(用户ID或群聊接收ID)
|
||||
* @param int $source 聊天来源(1:私信 2:群聊)
|
||||
* @param int $page 当前查询分页
|
||||
* @param int $page_size 分页大小
|
||||
* @param array $params 查询参数
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function searchRecords(int $user_id, int $receive_id, int $source, int $page, int $page_size, array $params)
|
||||
|
@ -677,6 +685,7 @@ class TalkService extends BaseService
|
|||
*
|
||||
* @param $message
|
||||
* @param $fileInfo
|
||||
*
|
||||
* @return bool|int
|
||||
*/
|
||||
public function createImgMessage($message, $fileInfo)
|
||||
|
@ -710,6 +719,7 @@ class TalkService extends BaseService
|
|||
*
|
||||
* @param array $message
|
||||
* @param array $codeBlock
|
||||
*
|
||||
* @return bool|int
|
||||
*/
|
||||
public function createCodeMessage(array $message, array $codeBlock)
|
||||
|
@ -742,6 +752,7 @@ class TalkService extends BaseService
|
|||
*
|
||||
* @param array $message
|
||||
* @param array $emoticon
|
||||
*
|
||||
* @return bool|int
|
||||
*/
|
||||
public function createEmoticonMessage(array $message, array $emoticon)
|
||||
|
@ -774,6 +785,7 @@ class TalkService extends BaseService
|
|||
*
|
||||
* @param array $message
|
||||
* @param array $emoticon
|
||||
*
|
||||
* @return bool|int
|
||||
*/
|
||||
public function createFileMessage(array $message, array $emoticon)
|
||||
|
|
|
@ -8,6 +8,7 @@ use Hyperf\HttpMessage\Upload\UploadedFile;
|
|||
* 文件上传服务
|
||||
*
|
||||
* Class UploadService
|
||||
*
|
||||
* @package App\Service
|
||||
*/
|
||||
class UploadService extends BaseService
|
||||
|
@ -31,8 +32,8 @@ class UploadService extends BaseService
|
|||
* 上传媒体图片
|
||||
*
|
||||
* @param UploadedFile $file
|
||||
* @param string $dir 文件夹路径
|
||||
* @param string $filename 文件名称
|
||||
* @param string $dir 文件夹路径
|
||||
* @param string $filename 文件名称
|
||||
*
|
||||
* @return bool|string
|
||||
*/
|
||||
|
|
|
@ -14,8 +14,9 @@ class UserService extends BaseService
|
|||
/**
|
||||
* 获取用户信息
|
||||
*
|
||||
* @param int $user_id 用户ID
|
||||
* @param array $field 查询字段
|
||||
* @param int $user_id 用户ID
|
||||
* @param array $field 查询字段
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function findById(int $user_id, $field = ['*'])
|
||||
|
@ -26,8 +27,9 @@ class UserService extends BaseService
|
|||
/**
|
||||
* 登录逻辑
|
||||
*
|
||||
* @param string $mobile 手机号
|
||||
* @param string $mobile 手机号
|
||||
* @param string $password 登录密码
|
||||
*
|
||||
* @return array|bool
|
||||
*/
|
||||
public function login(string $mobile, string $password)
|
||||
|
@ -47,23 +49,24 @@ class UserService extends BaseService
|
|||
* 账号注册逻辑
|
||||
*
|
||||
* @param array $data 用户数据
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function register(array $data)
|
||||
{
|
||||
Db::beginTransaction();
|
||||
try {
|
||||
$data['password'] = Hash::make($data['password']);
|
||||
$data['password'] = Hash::make($data['password']);
|
||||
$data['created_at'] = date('Y-m-d H:i:s');
|
||||
|
||||
$result = User::create($data);
|
||||
|
||||
// 创建用户的默认笔记分类
|
||||
ArticleClass::create([
|
||||
'user_id' => $result->id,
|
||||
'user_id' => $result->id,
|
||||
'class_name' => '我的笔记',
|
||||
'is_default' => 1,
|
||||
'sort' => 1,
|
||||
'sort' => 1,
|
||||
'created_at' => time()
|
||||
]);
|
||||
|
||||
|
@ -79,8 +82,9 @@ class UserService extends BaseService
|
|||
/**
|
||||
* 账号重置密码
|
||||
*
|
||||
* @param string $mobile 用户手机好
|
||||
* @param string $mobile 用户手机好
|
||||
* @param string $password 新密码
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function resetPassword(string $mobile, string $password)
|
||||
|
@ -91,8 +95,9 @@ class UserService extends BaseService
|
|||
/**
|
||||
* 修改绑定的手机号
|
||||
*
|
||||
* @param int $user_id 用户ID
|
||||
* @param string $mobile 换绑手机号
|
||||
* @param int $user_id 用户ID
|
||||
* @param string $mobile 换绑手机号
|
||||
*
|
||||
* @return array|bool
|
||||
*/
|
||||
public function changeMobile(int $user_id, string $mobile)
|
||||
|
@ -108,25 +113,26 @@ class UserService extends BaseService
|
|||
/**
|
||||
* 通过手机号查找用户
|
||||
*
|
||||
* @param int $friend_id 用户ID
|
||||
* @param int $friend_id 用户ID
|
||||
* @param int $me_user_id 当前登录用户的ID
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getUserCard(int $friend_id,int $me_user_id)
|
||||
public function getUserCard(int $friend_id, int $me_user_id)
|
||||
{
|
||||
$info = User::select(['id', 'mobile', 'nickname', 'avatar', 'gender', 'motto'])->where('id', $friend_id)->first();
|
||||
if(!$info) return [];
|
||||
if (!$info) return [];
|
||||
|
||||
$info = $info->toArray();
|
||||
$info['friend_status'] = 0;//朋友关系状态 0:本人 1:陌生人 2:朋友
|
||||
$info = $info->toArray();
|
||||
$info['friend_status'] = 0;//朋友关系状态 0:本人 1:陌生人 2:朋友
|
||||
$info['nickname_remark'] = '';
|
||||
$info['friend_apply'] = 0;
|
||||
$info['friend_apply'] = 0;
|
||||
|
||||
// 判断查询信息是否是自己
|
||||
if ($friend_id != $me_user_id) {
|
||||
$friendInfo = UsersFriend::
|
||||
where('user1', '=', $friend_id > $me_user_id ? $me_user_id :$friend_id)
|
||||
->where('user2', '=', $friend_id < $me_user_id ? $me_user_id :$friend_id)
|
||||
where('user1', '=', $friend_id > $me_user_id ? $me_user_id : $friend_id)
|
||||
->where('user2', '=', $friend_id < $me_user_id ? $me_user_id : $friend_id)
|
||||
->where('status', 1)
|
||||
->first(['id', 'user1', 'user2', 'active', 'user1_remark', 'user2_remark']);
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@ use PHPMailer\PHPMailer\Exception;
|
|||
|
||||
/**
|
||||
* Class Mail
|
||||
*
|
||||
* @package App\Support
|
||||
*/
|
||||
class Mail
|
||||
|
@ -14,17 +15,18 @@ class Mail
|
|||
/**
|
||||
* 发送邮件验证码
|
||||
*
|
||||
* @param string $email 邮箱地址
|
||||
* @param string $email 邮箱地址
|
||||
* @param string $sms_code 验证码
|
||||
* @param string $title 邮件标题
|
||||
* @param string $title 邮件标题
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function sendEmailCode(string $email, string $sms_code, string $title)
|
||||
{
|
||||
$view = $this->view(config('view.engine'), 'emails.verify-code', [
|
||||
'service_name' => "邮箱绑定",
|
||||
'sms_code' => $sms_code,
|
||||
'domain' => config('domain.web_url')
|
||||
'sms_code' => $sms_code,
|
||||
'domain' => config('domain.web_url')
|
||||
]);
|
||||
|
||||
try {
|
||||
|
@ -38,23 +40,24 @@ class Mail
|
|||
* @param string $address
|
||||
* @param string $subject
|
||||
* @param string $view
|
||||
*
|
||||
* @return bool
|
||||
* @throws \PHPMailer\PHPMailer\Exception
|
||||
*/
|
||||
private function mail(string $address, string $subject, string $view): bool
|
||||
{
|
||||
$config = config('mail');
|
||||
$mail = new PHPMailer(); //PHPMailer对象
|
||||
$mail->CharSet = 'UTF-8'; //设定邮件编码,默认ISO-8859-1,如果发中文此项必须设置,否则乱码
|
||||
$mail->IsSMTP(); // 设定使用SMTP服务
|
||||
$mail->SMTPDebug = 0; // 关闭SMTP调试功能
|
||||
$mail->SMTPAuth = true; // 启用 SMTP 验证功能
|
||||
$mail->SMTPSecure = 'ssl'; // 使用安全协议
|
||||
$mail->Host = $config['host']; // SMTP 服务器
|
||||
$mail->Port = $config['port']; // SMTP服务器的端口号
|
||||
$mail->Username = $config['username']; // SMTP; // SMTP服务器用户名
|
||||
$mail->Password = $config['password']; // SMTP服务器密码
|
||||
$mail->SetFrom($config['from'], $config['name']); // 邮箱,昵称
|
||||
$config = config('mail');
|
||||
$mail = new PHPMailer(); //PHPMailer对象
|
||||
$mail->CharSet = 'UTF-8'; //设定邮件编码,默认ISO-8859-1,如果发中文此项必须设置,否则乱码
|
||||
$mail->IsSMTP(); // 设定使用SMTP服务
|
||||
$mail->SMTPDebug = 0; // 关闭SMTP调试功能
|
||||
$mail->SMTPAuth = true; // 启用 SMTP 验证功能
|
||||
$mail->SMTPSecure = 'ssl'; // 使用安全协议
|
||||
$mail->Host = $config['host']; // SMTP 服务器
|
||||
$mail->Port = $config['port']; // SMTP服务器的端口号
|
||||
$mail->Username = $config['username']; // SMTP; // SMTP服务器用户名
|
||||
$mail->Password = $config['password']; // SMTP服务器密码
|
||||
$mail->SetFrom($config['from'], $config['name']); // 邮箱,昵称
|
||||
$mail->Subject = $subject;
|
||||
$mail->MsgHTML($view);
|
||||
$mail->AddAddress($address); // 收件人
|
||||
|
@ -63,8 +66,9 @@ class Mail
|
|||
|
||||
/**
|
||||
* @param string $engine
|
||||
* @param $template
|
||||
* @param array $params
|
||||
* @param $template
|
||||
* @param array $params
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function view(string $engine, $template, $params = []): string
|
||||
|
|
|
@ -5,6 +5,7 @@ namespace App\Support;
|
|||
/**
|
||||
* 邮件视图模板
|
||||
* Class MailerViewTemplate
|
||||
*
|
||||
* @package App\Support
|
||||
*/
|
||||
class MailerTemplate
|
||||
|
@ -12,9 +13,10 @@ class MailerTemplate
|
|||
/**
|
||||
* 获取模板信息
|
||||
*
|
||||
* @param string $engine 模板引擎
|
||||
* @param string $engine 模板引擎
|
||||
* @param string $template 模板名称
|
||||
* @param array $params 模板参数
|
||||
* @param array $params 模板参数
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function view(string $engine, string $template, $params = []): string
|
||||
|
@ -26,7 +28,8 @@ class MailerTemplate
|
|||
* 邮件验证码模板
|
||||
*
|
||||
* @param string $sms_code 验证码
|
||||
* @param array $params 模板参数
|
||||
* @param array $params 模板参数
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function emailCode(string $sms_code, array $params = [])
|
||||
|
|
|
@ -4,6 +4,7 @@ namespace App\Support;
|
|||
|
||||
/**
|
||||
* Class RedisLock
|
||||
*
|
||||
* @package App\Support
|
||||
*/
|
||||
class RedisLock
|
||||
|
@ -29,15 +30,16 @@ class RedisLock
|
|||
* -- 1、如果 $timeout 参数为 0,则立即返回锁。
|
||||
* -- 2、建议 timeout 设置为 0,避免 redis 因为阻塞导致性能下降。请根据实际需求进行设置。
|
||||
*
|
||||
* @param string $key 缓存KEY
|
||||
* @param string|int $requestId 客户端请求唯一ID
|
||||
* @param integer $lockSecond 锁定时间 单位(秒)
|
||||
* @param integer $timeout 取锁超时时间。单位(秒)。等于0,如果当前锁被占用,则立即返回失败。如果大于0,则反复尝试获取锁直到达到该超时时间。
|
||||
* @param integer|float $sleep 取锁间隔时间 单位(秒)。当锁为占用状态时。每隔多久尝试去取锁。默认 0.1 秒一次取锁。
|
||||
* @param string $key 缓存KEY
|
||||
* @param string|int $requestId 客户端请求唯一ID
|
||||
* @param integer $lockSecond 锁定时间 单位(秒)
|
||||
* @param integer $timeout 取锁超时时间。单位(秒)。等于0,如果当前锁被占用,则立即返回失败。如果大于0,则反复尝试获取锁直到达到该超时时间。
|
||||
* @param integer|float $sleep 取锁间隔时间 单位(秒)。当锁为占用状态时。每隔多久尝试去取锁。默认 0.1 秒一次取锁。
|
||||
*
|
||||
* @return bool
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function lock(string $key,$requestId, $lockSecond = 20, $timeout = 0, $sleep = 0.1)
|
||||
public static function lock(string $key, $requestId, $lockSecond = 20, $timeout = 0, $sleep = 0.1)
|
||||
{
|
||||
if (empty($key)) {
|
||||
throw new \Exception('获取锁的KEY值没有设置');
|
||||
|
@ -65,11 +67,12 @@ class RedisLock
|
|||
/**
|
||||
* 释放锁
|
||||
*
|
||||
* @param string $key 被加锁的KEY
|
||||
* @param string $key 被加锁的KEY
|
||||
* @param string|int $requestId 客户端请求唯一ID
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function release(string $key,$requestId)
|
||||
public static function release(string $key, $requestId)
|
||||
{
|
||||
if (strlen($key) === 0) {
|
||||
return false;
|
||||
|
@ -90,6 +93,7 @@ LAU;
|
|||
* 获取锁 Key
|
||||
*
|
||||
* @param string $key 需要加锁的KEY
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getLockKey(string $key)
|
||||
|
|
|
@ -17,6 +17,7 @@ class Response
|
|||
|
||||
/**
|
||||
* @param $data
|
||||
*
|
||||
* @return PsrResponseInterface
|
||||
*/
|
||||
public function json($data)
|
||||
|
@ -27,8 +28,9 @@ class Response
|
|||
/**
|
||||
* 处理成功信息返回
|
||||
*
|
||||
* @param array $data 响应数据
|
||||
* @param array $data 响应数据
|
||||
* @param string $message 响应提示
|
||||
*
|
||||
* @return PsrResponseInterface
|
||||
*/
|
||||
public function success(array $data = [], $message = 'success')
|
||||
|
@ -40,9 +42,9 @@ class Response
|
|||
/**
|
||||
* 处理失败信息返回
|
||||
*
|
||||
* @param array $data 响应数据
|
||||
* @param array $data 响应数据
|
||||
* @param string $message 响应提示
|
||||
* @param int $code 错误码
|
||||
* @param int $code 错误码
|
||||
*
|
||||
* @return PsrResponseInterface
|
||||
*/
|
||||
|
@ -53,13 +55,14 @@ class Response
|
|||
|
||||
/**
|
||||
* @param string $message
|
||||
* @param int $code
|
||||
* @param int $code
|
||||
*
|
||||
* @return PsrResponseInterface
|
||||
*/
|
||||
public function error($message = '', $code = ResponseCode::SERVER_ERROR)
|
||||
{
|
||||
return $this->response->withStatus(500)->json([
|
||||
'code' => $code,
|
||||
'code' => $code,
|
||||
'message' => $message,
|
||||
]);
|
||||
}
|
||||
|
|
|
@ -6,15 +6,16 @@ namespace App\Support;
|
|||
class SendEmailCode
|
||||
{
|
||||
const FORGET_PASSWORD = 'forget_password';
|
||||
const CHANGE_MOBILE = 'change_mobile';
|
||||
const CHANGE_MOBILE = 'change_mobile';
|
||||
const CHANGE_REGISTER = 'user_register';
|
||||
const CHANGE_EMAIL = 'change_email';
|
||||
const CHANGE_EMAIL = 'change_email';
|
||||
|
||||
/**
|
||||
* 获取缓存key
|
||||
*
|
||||
* @param string $type
|
||||
* @param string $mobile
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function getKey(string $type, string $mobile)
|
||||
|
@ -25,9 +26,10 @@ class SendEmailCode
|
|||
/**
|
||||
* 检测验证码是否正确
|
||||
*
|
||||
* @param string $type 发送类型
|
||||
* @param string $type 发送类型
|
||||
* @param string $email 手机号
|
||||
* @param string $code 验证码
|
||||
* @param string $code 验证码
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function check(string $type, string $email, string $code)
|
||||
|
@ -43,9 +45,10 @@ class SendEmailCode
|
|||
/**
|
||||
* 发送邮件验证码
|
||||
*
|
||||
* @param string $type 类型
|
||||
* @param string $type 类型
|
||||
* @param string $title 邮件标题
|
||||
* @param string $email 邮箱地址
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function send(string $type, string $title, string $email)
|
||||
|
@ -67,6 +70,7 @@ class SendEmailCode
|
|||
* 获取缓存的验证码
|
||||
*
|
||||
* @param string $key
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getCode(string $key)
|
||||
|
@ -77,9 +81,10 @@ class SendEmailCode
|
|||
/**
|
||||
* 设置验证码缓存
|
||||
*
|
||||
* @param string $key 缓存key
|
||||
* @param string $sms_code 验证码
|
||||
* @param float|int $exp 过期时间
|
||||
* @param string $key 缓存key
|
||||
* @param string $sms_code 验证码
|
||||
* @param float|int $exp 过期时间
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function setCode(string $key, string $sms_code, $exp = 60 * 15)
|
||||
|
@ -90,8 +95,9 @@ class SendEmailCode
|
|||
/**
|
||||
* 删除验证码缓存
|
||||
*
|
||||
* @param string $type 类型
|
||||
* @param string $type 类型
|
||||
* @param string $email 邮箱地址
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function delCode(string $type, string $email)
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
|
||||
namespace App\Support;
|
||||
|
||||
class SocketIOParser extends Packet
|
||||
|
@ -7,16 +8,16 @@ class SocketIOParser extends Packet
|
|||
* Encode output payload for websocket push.
|
||||
*
|
||||
* @param string $event
|
||||
* @param mixed $data
|
||||
* @param mixed $data
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function encode(string $event, $data)
|
||||
{
|
||||
$packet = Packet::MESSAGE . Packet::EVENT;
|
||||
$packet = Packet::MESSAGE . Packet::EVENT;
|
||||
$shouldEncode = is_array($data) || is_object($data);
|
||||
$data = $shouldEncode ? json_encode($data) : $data;
|
||||
$format = $shouldEncode ? '["%s",%s]' : '["%s","%s"]';
|
||||
$data = $shouldEncode ? json_encode($data) : $data;
|
||||
$format = $shouldEncode ? '["%s",%s]' : '["%s","%s"]';
|
||||
|
||||
return $packet . sprintf($format, $event, $data);
|
||||
}
|
||||
|
@ -34,7 +35,7 @@ class SocketIOParser extends Packet
|
|||
|
||||
return [
|
||||
'event' => $payload['event'] ?? null,
|
||||
'data' => $payload['data'] ?? null,
|
||||
'data' => $payload['data'] ?? null,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ trait PagingTrait
|
|||
/**
|
||||
* 计算分页总数
|
||||
*
|
||||
* @param int $total 总记录数
|
||||
* @param int $total 总记录数
|
||||
* @param int $page_size 分页大小
|
||||
*
|
||||
* @return int 分页总数
|
||||
|
@ -25,22 +25,22 @@ trait PagingTrait
|
|||
/**
|
||||
* 获取分页数据
|
||||
*
|
||||
* @param array $rows 列表数据
|
||||
* @param int $total 数据总记录数
|
||||
* @param int $page 当前分页
|
||||
* @param int $page_size 分页大小
|
||||
* @param array $params 额外参数
|
||||
* @param array $rows 列表数据
|
||||
* @param int $total 数据总记录数
|
||||
* @param int $page 当前分页
|
||||
* @param int $page_size 分页大小
|
||||
* @param array $params 额外参数
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getPagingRows(array $rows, int $total, int $page, int $page_size, array $params = [])
|
||||
{
|
||||
return array_merge([
|
||||
'rows' => $rows,
|
||||
'page' => $page,
|
||||
'page_size' => $page_size,
|
||||
'rows' => $rows,
|
||||
'page' => $page,
|
||||
'page_size' => $page_size,
|
||||
'page_total' => ($page_size == 0) ? 1 : $this->getPagingTotal($total, $page_size),
|
||||
'total' => $total,
|
||||
'total' => $total,
|
||||
], $params);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,17 +15,17 @@ use Hyperf\Contract\StdoutLoggerInterface;
|
|||
use Psr\Log\LogLevel;
|
||||
|
||||
return [
|
||||
'app_name' => env('APP_NAME', 'skeleton'),
|
||||
'app_env' => env('APP_ENV', 'dev'),
|
||||
'app_name' => env('APP_NAME', 'skeleton'),
|
||||
'app_env' => env('APP_ENV', 'dev'),
|
||||
'scan_cacheable' => env('SCAN_CACHEABLE', false),
|
||||
|
||||
'ip_address' => env('IP_ADDRESS', ''),
|
||||
|
||||
// 运行模式(预留)
|
||||
'run_mode' => 'cluster',
|
||||
'run_mode' => 'cluster',
|
||||
|
||||
// 域名相关配置
|
||||
'domain' => [
|
||||
'domain' => [
|
||||
'web_url' => env('WEB_URL', ''),//Web 端首页地址
|
||||
'img_url' => env('IMG_URL', ''),//设置文件图片访问的域名
|
||||
],
|
||||
|
|
Loading…
Reference in New Issue