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