初始化
parent
64fdcfbe98
commit
b5e52a959a
|
@ -2,24 +2,24 @@
|
||||||
|
|
||||||
namespace App\Constants;
|
namespace App\Constants;
|
||||||
|
|
||||||
use Hyperf\Constants\AbstractConstants;
|
|
||||||
use Hyperf\Constants\Annotation\Constants;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Constants
|
* HTTP 响应状态码枚举
|
||||||
|
*
|
||||||
|
* Class ResponseCode
|
||||||
|
* @package App\Constants
|
||||||
*/
|
*/
|
||||||
class ResponseCode extends AbstractConstants
|
class ResponseCode
|
||||||
{
|
{
|
||||||
const SUCCESS = 200; // 接口处理成功
|
const SUCCESS = 200; // 接口处理成功
|
||||||
const FAIL = 305; // 接口处理失败
|
const FAIL = 305; // 接口处理失败
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Message("Server Error!")
|
* Server Error!
|
||||||
*/
|
*/
|
||||||
const SERVER_ERROR = 500;
|
const SERVER_ERROR = 500;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Message("请求数据验证失败!")
|
* 请求数据验证失败!
|
||||||
*/
|
*/
|
||||||
const VALIDATION_ERROR = 301;
|
const VALIDATION_ERROR = 301;
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,4 +39,18 @@ class SocketConstants
|
||||||
* WebSocket 消息消费队列交换机名称
|
* WebSocket 消息消费队列交换机名称
|
||||||
*/
|
*/
|
||||||
const CONSUMER_MESSAGE_EXCHANGE = 'im.message.fanout';
|
const CONSUMER_MESSAGE_EXCHANGE = 'im.message.fanout';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public static function getMap(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
self::EVENT_TALK => '对话消息通知',
|
||||||
|
self::EVENT_KEYBOARD => '键盘输入事件通知',
|
||||||
|
self::EVENT_ONLINE_STATUS => '用户在线状态通知',
|
||||||
|
self::EVENT_REVOKE_TALK => '聊天消息撤销通知',
|
||||||
|
self::EVENT_FRIEND_APPLY => '好友申请消息通知'
|
||||||
|
];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
<?php
|
<?php
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace App\Controller\Api\V1;
|
namespace App\Controller\Api\V1;
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
namespace App\Controller\Api\V1;
|
namespace App\Controller\Api\V1;
|
||||||
|
|
||||||
use App\Constants\SocketConstants;
|
|
||||||
use Hyperf\Di\Annotation\Inject;
|
use Hyperf\Di\Annotation\Inject;
|
||||||
use Hyperf\HttpServer\Annotation\Controller;
|
use Hyperf\HttpServer\Annotation\Controller;
|
||||||
use Hyperf\HttpServer\Annotation\RequestMapping;
|
use Hyperf\HttpServer\Annotation\RequestMapping;
|
||||||
|
@ -17,6 +16,7 @@ use App\Model\Group\UsersGroupNotice;
|
||||||
use App\Amqp\Producer\ChatMessageProducer;
|
use App\Amqp\Producer\ChatMessageProducer;
|
||||||
use App\Service\SocketRoomService;
|
use App\Service\SocketRoomService;
|
||||||
use App\Service\GroupService;
|
use App\Service\GroupService;
|
||||||
|
use App\Constants\SocketConstants;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class GroupController
|
* Class GroupController
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
namespace App\Controller\Api\V1;
|
namespace App\Controller\Api\V1;
|
||||||
|
|
||||||
use App\Constants\SocketConstants;
|
|
||||||
use Hyperf\Di\Annotation\Inject;
|
use Hyperf\Di\Annotation\Inject;
|
||||||
use Hyperf\HttpServer\Annotation\Controller;
|
use Hyperf\HttpServer\Annotation\Controller;
|
||||||
use Hyperf\HttpServer\Annotation\RequestMapping;
|
use Hyperf\HttpServer\Annotation\RequestMapping;
|
||||||
|
@ -22,6 +21,7 @@ use App\Service\UploadService;
|
||||||
use App\Amqp\Producer\ChatMessageProducer;
|
use App\Amqp\Producer\ChatMessageProducer;
|
||||||
use App\Cache\LastMsgCache;
|
use App\Cache\LastMsgCache;
|
||||||
use App\Cache\UnreadTalkCache;
|
use App\Cache\UnreadTalkCache;
|
||||||
|
use App\Constants\SocketConstants;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class TalkController
|
* Class TalkController
|
||||||
|
|
|
@ -0,0 +1,50 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Helper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 字符串助手类
|
||||||
|
*
|
||||||
|
* Class StringHelper
|
||||||
|
* @package App\Helper
|
||||||
|
*/
|
||||||
|
class StringHelper
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* 将字符串转换成二进制
|
||||||
|
*
|
||||||
|
* @param string $str
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public static function str2Bin(string $str): string
|
||||||
|
{
|
||||||
|
//列出每个字符
|
||||||
|
$arr = preg_split('/(?<!^)(?!$)/u', $str);
|
||||||
|
//unpack字符
|
||||||
|
foreach ($arr as &$v) {
|
||||||
|
$temp = unpack('H*', $v);
|
||||||
|
$v = base_convert($temp[1], 16, 2);
|
||||||
|
unset($temp);
|
||||||
|
}
|
||||||
|
|
||||||
|
return join(' ', $arr);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将二进制转换成字符串
|
||||||
|
*
|
||||||
|
* @param string $str
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public static function bin2Str(string $str): string
|
||||||
|
{
|
||||||
|
$arr = explode(' ', $str);
|
||||||
|
foreach ($arr as &$v) {
|
||||||
|
$v = pack('H' . strlen(base_convert($v, 2, 16)), base_convert($v, 2, 16));
|
||||||
|
}
|
||||||
|
|
||||||
|
return join('', $arr);
|
||||||
|
}
|
||||||
|
}
|
|
@ -37,5 +37,10 @@ class ChatRecordsDelete extends BaseModel
|
||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
protected $casts = ['id' => 'integer', 'record_id' => 'integer', 'user_id' => 'integer', 'created_at' => 'datetime'];
|
protected $casts = [
|
||||||
|
'id' => 'integer',
|
||||||
|
'record_id' => 'integer',
|
||||||
|
'user_id' => 'integer',
|
||||||
|
'created_at' => 'datetime'
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,7 +50,6 @@ class FileSplitUpload extends BaseModel
|
||||||
'upload_at'
|
'upload_at'
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The attributes that should be cast to native types.
|
* The attributes that should be cast to native types.
|
||||||
*
|
*
|
||||||
|
|
|
@ -69,7 +69,8 @@ class UsersGroup extends BaseModel
|
||||||
* @param int $group_id 群ID
|
* @param int $group_id 群ID
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public static function isManager(int $user_id,int $group_id){
|
public static function isManager(int $user_id, int $group_id)
|
||||||
|
{
|
||||||
return self::where('id', $group_id)->where('user_id', $user_id)->exists();
|
return self::where('id', $group_id)->where('user_id', $user_id)->exists();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -82,6 +83,6 @@ class UsersGroup extends BaseModel
|
||||||
*/
|
*/
|
||||||
public static function isMember(int $group_id, int $user_id)
|
public static function isMember(int $group_id, int $user_id)
|
||||||
{
|
{
|
||||||
return UsersGroupMember::where('group_id', $group_id)->where('user_id', $user_id)->where('status', 0)->exists() ? true : false;
|
return UsersGroupMember::where('group_id', $group_id)->where('user_id', $user_id)->where('status', 0)->exists();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -118,7 +118,10 @@ class UsersChatList extends BaseModel
|
||||||
*/
|
*/
|
||||||
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(['is_top' => $is_top ? 1 : 0, 'updated_at' => date('Y-m-d H:i:s')]);
|
return (bool)self::where('id', $list_id)->where('uid', $user_id)->update([
|
||||||
|
'is_top' => $is_top ? 1 : 0,
|
||||||
|
'updated_at' => date('Y-m-d H:i:s')
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -131,12 +134,13 @@ class UsersChatList extends BaseModel
|
||||||
*/
|
*/
|
||||||
public static function delItem(int $user_id, int $id, $type = 1)
|
public static function delItem(int $user_id, int $id, $type = 1)
|
||||||
{
|
{
|
||||||
|
$data = ['status' => 0, 'updated_at' => date('Y-m-d H:i:s')];
|
||||||
if ($type == 1) {
|
if ($type == 1) {
|
||||||
return (bool)self::where('id', $id)->where('uid', $user_id)->update(['status' => 0, 'updated_at' => date('Y-m-d H:i:s')]);
|
return (bool)self::where('id', $id)->where('uid', $user_id)->update($data);
|
||||||
} else if ($type == 2) {
|
} else if ($type == 2) {
|
||||||
return (bool)self::where('uid', $user_id)->where('friend_id', $id)->update(['status' => 0, 'updated_at' => date('Y-m-d H:i:s')]);
|
return (bool)self::where('uid', $user_id)->where('friend_id', $id)->update($data);
|
||||||
} else {
|
} else {
|
||||||
return (bool)self::where('uid', $user_id)->where('group_id', $id)->update(['status' => 0, 'updated_at' => date('Y-m-d H:i:s')]);
|
return (bool)self::where('uid', $user_id)->where('group_id', $id)->update($data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -76,7 +76,7 @@ class UsersFriend extends BaseModel
|
||||||
SELECT id as rid,user2 as uid,user1_remark as friend_remark from {$prefix}users_friends where user1 = {$uid} and `status` = 1
|
SELECT id as rid,user2 as uid,user1_remark as friend_remark from {$prefix}users_friends where user1 = {$uid} and `status` = 1
|
||||||
UNION all
|
UNION all
|
||||||
SELECT id as rid,user1 as uid,user2_remark as friend_remark from {$prefix}users_friends where user2 = {$uid} and `status` = 1
|
SELECT id as rid,user1 as uid,user2_remark as friend_remark from {$prefix}users_friends where user2 = {$uid} and `status` = 1
|
||||||
) tmp_table on tmp_table.uid = users.id order by tmp_table.rid desc
|
) tmp_table on tmp_table.uid = users.id
|
||||||
SQL;
|
SQL;
|
||||||
|
|
||||||
$rows = Db::select($sql);
|
$rows = Db::select($sql);
|
||||||
|
|
|
@ -38,7 +38,7 @@ function redis()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* server 实例 基于 swoole server
|
* Server 实例 基于 Swoole Server
|
||||||
*
|
*
|
||||||
* @return \Swoole\Coroutine\Server|\Swoole\Server
|
* @return \Swoole\Coroutine\Server|\Swoole\Server
|
||||||
*/
|
*/
|
||||||
|
@ -48,7 +48,9 @@ function server()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* websocket frame 实例
|
* WebSocket frame 实例
|
||||||
|
*
|
||||||
|
* @return mixed|Frame
|
||||||
*/
|
*/
|
||||||
function frame()
|
function frame()
|
||||||
{
|
{
|
||||||
|
@ -56,7 +58,9 @@ function frame()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* websocket 实例
|
* WebSocketServer 实例
|
||||||
|
*
|
||||||
|
* @return mixed|WebSocketServer
|
||||||
*/
|
*/
|
||||||
function websocket()
|
function websocket()
|
||||||
{
|
{
|
||||||
|
@ -65,6 +69,8 @@ function websocket()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 缓存实例 简单的缓存
|
* 缓存实例 简单的缓存
|
||||||
|
*
|
||||||
|
* @return mixed|\Psr\SimpleCache\CacheInterface
|
||||||
*/
|
*/
|
||||||
function cache()
|
function cache()
|
||||||
{
|
{
|
||||||
|
@ -73,6 +79,8 @@ function cache()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 控制台日志
|
* 控制台日志
|
||||||
|
*
|
||||||
|
* @return StdoutLoggerInterface|mixed
|
||||||
*/
|
*/
|
||||||
function stdout_log()
|
function stdout_log()
|
||||||
{
|
{
|
||||||
|
|
|
@ -4,6 +4,7 @@ use Hyperf\Database\Schema\Schema;
|
||||||
use Hyperf\Database\Schema\Blueprint;
|
use Hyperf\Database\Schema\Blueprint;
|
||||||
use Hyperf\Database\Migrations\Migration;
|
use Hyperf\Database\Migrations\Migration;
|
||||||
use Hyperf\DbConnection\Db;
|
use Hyperf\DbConnection\Db;
|
||||||
|
|
||||||
class CreateUsersFriendsTable extends Migration
|
class CreateUsersFriendsTable extends Migration
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
|
@ -27,6 +28,7 @@ class CreateUsersFriendsTable extends Migration
|
||||||
$table->engine = 'InnoDB';
|
$table->engine = 'InnoDB';
|
||||||
|
|
||||||
$table->index(['user1', 'user2'], 'idx_user1_user2');
|
$table->index(['user1', 'user2'], 'idx_user1_user2');
|
||||||
|
$table->index(['user2', 'user1'], 'idx_user2_user1');
|
||||||
});
|
});
|
||||||
|
|
||||||
$prefix = config('databases.default.prefix');
|
$prefix = config('databases.default.prefix');
|
||||||
|
|
Loading…
Reference in New Issue