From b5e52a959acb5539e06096afd1ccaceff7a3f7f8 Mon Sep 17 00:00:00 2001 From: gzydong <837215079@qq.com> Date: Thu, 3 Dec 2020 16:22:55 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=9D=E5=A7=8B=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Constants/ResponseCode.php | 14 +++--- app/Constants/SocketConstants.php | 14 ++++++ app/Controller/Api/V1/ArticleController.php | 1 - app/Controller/Api/V1/GroupController.php | 2 +- app/Controller/Api/V1/TalkController.php | 2 +- app/Helper/StringHelper.php | 50 +++++++++++++++++++ app/Model/Chat/ChatRecordsDelete.php | 7 ++- app/Model/FileSplitUpload.php | 1 - app/Model/Group/UsersGroup.php | 5 +- app/Model/UsersChatList.php | 12 +++-- app/Model/UsersFriend.php | 2 +- app/helper.php | 14 ++++-- ...1_04_153553_create_users_friends_table.php | 2 + 13 files changed, 104 insertions(+), 22 deletions(-) create mode 100644 app/Helper/StringHelper.php diff --git a/app/Constants/ResponseCode.php b/app/Constants/ResponseCode.php index 8f1e02b..317a6b4 100644 --- a/app/Constants/ResponseCode.php +++ b/app/Constants/ResponseCode.php @@ -2,24 +2,24 @@ 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 FAIL = 305; // 接口处理失败 /** - * @Message("Server Error!") + * Server Error! */ const SERVER_ERROR = 500; /** - * @Message("请求数据验证失败!") + * 请求数据验证失败! */ const VALIDATION_ERROR = 301; } diff --git a/app/Constants/SocketConstants.php b/app/Constants/SocketConstants.php index 091a1c8..c526170 100644 --- a/app/Constants/SocketConstants.php +++ b/app/Constants/SocketConstants.php @@ -39,4 +39,18 @@ class SocketConstants * WebSocket 消息消费队列交换机名称 */ 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 => '好友申请消息通知' + ]; + } } diff --git a/app/Controller/Api/V1/ArticleController.php b/app/Controller/Api/V1/ArticleController.php index 6b4d24e..a0e54ee 100644 --- a/app/Controller/Api/V1/ArticleController.php +++ b/app/Controller/Api/V1/ArticleController.php @@ -1,5 +1,4 @@ 'integer', 'record_id' => 'integer', 'user_id' => 'integer', 'created_at' => 'datetime']; + protected $casts = [ + 'id' => 'integer', + 'record_id' => 'integer', + 'user_id' => 'integer', + 'created_at' => 'datetime' + ]; } diff --git a/app/Model/FileSplitUpload.php b/app/Model/FileSplitUpload.php index 4966dd7..13d0af2 100644 --- a/app/Model/FileSplitUpload.php +++ b/app/Model/FileSplitUpload.php @@ -50,7 +50,6 @@ class FileSplitUpload extends BaseModel 'upload_at' ]; - /** * The attributes that should be cast to native types. * diff --git a/app/Model/Group/UsersGroup.php b/app/Model/Group/UsersGroup.php index 7008ea1..ed48a83 100644 --- a/app/Model/Group/UsersGroup.php +++ b/app/Model/Group/UsersGroup.php @@ -69,7 +69,8 @@ class UsersGroup extends BaseModel * @param int $group_id 群ID * @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(); } @@ -82,6 +83,6 @@ class UsersGroup extends BaseModel */ 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(); } } diff --git a/app/Model/UsersChatList.php b/app/Model/UsersChatList.php index 4f5ff4e..eb81605 100644 --- a/app/Model/UsersChatList.php +++ b/app/Model/UsersChatList.php @@ -118,7 +118,10 @@ class UsersChatList extends BaseModel */ 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) { + $data = ['status' => 0, 'updated_at' => date('Y-m-d H:i:s')]; 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) { - 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 { - 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); } } diff --git a/app/Model/UsersFriend.php b/app/Model/UsersFriend.php index 1d92bf4..4d7a0b1 100644 --- a/app/Model/UsersFriend.php +++ b/app/Model/UsersFriend.php @@ -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 UNION all 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; $rows = Db::select($sql); diff --git a/app/helper.php b/app/helper.php index 83df55e..6a2eaa0 100644 --- a/app/helper.php +++ b/app/helper.php @@ -38,7 +38,7 @@ function redis() } /** - * server 实例 基于 swoole server + * Server 实例 基于 Swoole Server * * @return \Swoole\Coroutine\Server|\Swoole\Server */ @@ -48,7 +48,9 @@ function server() } /** - * websocket frame 实例 + * WebSocket frame 实例 + * + * @return mixed|Frame */ function frame() { @@ -56,7 +58,9 @@ function frame() } /** - * websocket 实例 + * WebSocketServer 实例 + * + * @return mixed|WebSocketServer */ function websocket() { @@ -65,6 +69,8 @@ function websocket() /** * 缓存实例 简单的缓存 + * + * @return mixed|\Psr\SimpleCache\CacheInterface */ function cache() { @@ -73,6 +79,8 @@ function cache() /** * 控制台日志 + * + * @return StdoutLoggerInterface|mixed */ function stdout_log() { diff --git a/migrations/2020_11_04_153553_create_users_friends_table.php b/migrations/2020_11_04_153553_create_users_friends_table.php index a1f6396..ac0dacd 100644 --- a/migrations/2020_11_04_153553_create_users_friends_table.php +++ b/migrations/2020_11_04_153553_create_users_friends_table.php @@ -4,6 +4,7 @@ use Hyperf\Database\Schema\Schema; use Hyperf\Database\Schema\Blueprint; use Hyperf\Database\Migrations\Migration; use Hyperf\DbConnection\Db; + class CreateUsersFriendsTable extends Migration { /** @@ -27,6 +28,7 @@ class CreateUsersFriendsTable extends Migration $table->engine = 'InnoDB'; $table->index(['user1', 'user2'], 'idx_user1_user2'); + $table->index(['user2', 'user1'], 'idx_user2_user1'); }); $prefix = config('databases.default.prefix');