优化代码格式

main
gzydong 2021-09-11 12:41:28 +08:00
parent aeeb3e3ce2
commit c7a3e8bb30
41 changed files with 191 additions and 327 deletions

View File

@ -1,4 +1,6 @@
<?php <?php
declare(strict_types=1);
/** /**
* This is my open source code, please do not use it for commercial applications. * This is my open source code, please do not use it for commercial applications.
* For the full copyright and license information, * For the full copyright and license information,

View File

@ -1,5 +1,6 @@
<?php <?php
declare(strict_types=1); declare(strict_types=1);
/** /**
* This is my open source code, please do not use it for commercial applications. * This is my open source code, please do not use it for commercial applications.
* For the full copyright and license information, * For the full copyright and license information,

View File

@ -1,6 +1,15 @@
<?php <?php
declare(strict_types=1); declare(strict_types=1);
/**
* This is my open source code, please do not use it for commercial applications.
* For the full copyright and license information,
* please view the LICENSE file that was distributed with this source code
*
* @author Yuandong<837215079@qq.com>
* @link https://github.com/gzydong/hyperf-chat
*/
namespace App\Command; namespace App\Command;
use Hyperf\Command\Command as HyperfCommand; use Hyperf\Command\Command as HyperfCommand;

View File

@ -1,5 +1,6 @@
<?php <?php
declare(strict_types=1); declare(strict_types=1);
/** /**
* This is my open source code, please do not use it for commercial applications. * This is my open source code, please do not use it for commercial applications.
* For the full copyright and license information, * For the full copyright and license information,

View File

@ -1,4 +1,5 @@
<?php <?php
declare(strict_types=1);
namespace App\Constants; namespace App\Constants;

View File

@ -1,4 +1,5 @@
<?php <?php
declare(strict_types=1);
namespace App\Constants; namespace App\Constants;

View File

@ -1,4 +1,5 @@
<?php <?php
declare(strict_types=1);
namespace App\Constants; namespace App\Constants;

View File

@ -1,9 +1,8 @@
<?php <?php
declare(strict_types=1);
namespace App\Constants; namespace App\Constants;
/** /**
* 定义系统机器人ID * 定义系统机器人ID
* *

View File

@ -1,4 +1,5 @@
<?php <?php
declare(strict_types=1);
namespace App\Constants; namespace App\Constants;

View File

@ -1,4 +1,5 @@
<?php <?php
declare(strict_types=1);
namespace App\Constants; namespace App\Constants;

View File

@ -1,5 +1,6 @@
<?php <?php
declare(strict_types=1); declare(strict_types=1);
/** /**
* This is my open source code, please do not use it for commercial applications. * This is my open source code, please do not use it for commercial applications.
* For the full copyright and license information, * For the full copyright and license information,
@ -39,12 +40,6 @@ abstract class AbstractController
*/ */
protected $response; protected $response;
/**
* @Inject
* @var ValidatorFactoryInterface
*/
protected $validationFactory;
/** /**
* 自定义控制器验证器 * 自定义控制器验证器
* *
@ -52,7 +47,7 @@ abstract class AbstractController
*/ */
protected function validate(...$arg) protected function validate(...$arg)
{ {
$validator = $this->validationFactory->make(...$arg); $validator = di()->get(ValidatorFactoryInterface::class)->make(...$arg);
if ($validator->fails()) { if ($validator->fails()) {
throw new ValidateException($validator->errors()->first(), ResponseCode::VALIDATION_ERROR); throw new ValidateException($validator->errors()->first(), ResponseCode::VALIDATION_ERROR);
} }

View File

@ -1,12 +1,4 @@
<?php <?php
/**
* This is my open source code, please do not use it for commercial applications.
* For the full copyright and license information,
* please view the LICENSE file that was distributed with this source code
*
* @author Yuandong<837215079@qq.com>
* @link https://github.com/gzydong/hyperf-chat
*/
namespace App\Controller\Api\V1; namespace App\Controller\Api\V1;
@ -39,11 +31,10 @@ class ArticleController extends CController
/** /**
* 获取笔记分类列表 * 获取笔记分类列表
* @RequestMapping(path="classifys", methods="get")
* *
* @return ResponseInterface * @RequestMapping(path="classifys", methods="get")
*/ */
public function getArticleClass() public function getArticleClass(): ResponseInterface
{ {
$rows = $this->articleService->getUserClass($this->uid()); $rows = $this->articleService->getUserClass($this->uid());
foreach ($rows as &$row) { foreach ($rows as &$row) {
@ -55,11 +46,10 @@ class ArticleController extends CController
/** /**
* 获取笔记标签列表 * 获取笔记标签列表
* @RequestMapping(path="tags", methods="get")
* *
* @return ResponseInterface * @RequestMapping(path="tags", methods="get")
*/ */
public function getArticleTags() public function getArticleTags(): ResponseInterface
{ {
return $this->response->success([ return $this->response->success([
'tags' => $this->articleService->getUserTags($this->uid()) 'tags' => $this->articleService->getUserTags($this->uid())
@ -68,11 +58,10 @@ class ArticleController extends CController
/** /**
* 获取笔记列表 * 获取笔记列表
* @RequestMapping(path="search", methods="get")
* *
* @return ResponseInterface * @RequestMapping(path="search", methods="get")
*/ */
public function getArticleList() public function getArticleList(): ResponseInterface
{ {
$params1 = $this->request->inputs(['keyword', 'find_type', 'cid', 'page']); $params1 = $this->request->inputs(['keyword', 'find_type', 'cid', 'page']);
$this->validate($params1, [ $this->validate($params1, [
@ -102,11 +91,10 @@ class ArticleController extends CController
/** /**
* 获取笔记详情 * 获取笔记详情
* @RequestMapping(path="detail", methods="get")
* *
* @return ResponseInterface * @RequestMapping(path="detail", methods="get")
*/ */
public function getArticleDetail() public function getArticleDetail(): ResponseInterface
{ {
$params = $this->request->inputs(['article_id']); $params = $this->request->inputs(['article_id']);
$this->validate($params, [ $this->validate($params, [
@ -120,11 +108,10 @@ class ArticleController extends CController
/** /**
* 添加或编辑笔记分类 * 添加或编辑笔记分类
* @RequestMapping(path="classify/editor", methods="post")
* *
* @return ResponseInterface * @RequestMapping(path="classify/editor", methods="post")
*/ */
public function editArticleClass() public function editArticleClass(): ResponseInterface
{ {
$params = $this->request->inputs(['class_id', 'class_name']); $params = $this->request->inputs(['class_id', 'class_name']);
$this->validate($params, [ $this->validate($params, [
@ -142,12 +129,12 @@ class ArticleController extends CController
/** /**
* 删除笔记分类 * 删除笔记分类
* @RequestMapping(path="classify/delete", methods="post")
* *
* @RequestMapping(path="classify/delete", methods="post")
* @return ResponseInterface * @return ResponseInterface
* @throws \Exception * @throws \Exception
*/ */
public function delArticleClass() public function delArticleClass(): ResponseInterface
{ {
$params = $this->request->inputs(['class_id']); $params = $this->request->inputs(['class_id']);
$this->validate($params, [ $this->validate($params, [
@ -163,12 +150,12 @@ class ArticleController extends CController
/** /**
* 笔记分类列表排序接口 * 笔记分类列表排序接口
* @RequestMapping(path="classify/sort", methods="post")
* *
* @RequestMapping(path="classify/sort", methods="post")
* @return ResponseInterface * @return ResponseInterface
* @throws \Exception * @throws \Exception
*/ */
public function articleClassSort() public function articleClassSort(): ResponseInterface
{ {
$params = $this->request->inputs(['class_id', 'sort_type']); $params = $this->request->inputs(['class_id', 'sort_type']);
$this->validate($params, [ $this->validate($params, [
@ -194,11 +181,10 @@ class ArticleController extends CController
/** /**
* 笔记分类合并接口 * 笔记分类合并接口
* @RequestMapping(path="classify/merge", methods="post")
* *
* @return ResponseInterface * @RequestMapping(path="classify/merge", methods="post")
*/ */
public function mergeArticleClass() public function mergeArticleClass(): ResponseInterface
{ {
$params = $this->request->inputs(['class_id', 'toid']); $params = $this->request->inputs(['class_id', 'toid']);
$this->validate($params, [ $this->validate($params, [
@ -215,11 +201,10 @@ class ArticleController extends CController
/** /**
* 添加或编辑笔记标签 * 添加或编辑笔记标签
* @RequestMapping(path="tag/editor", methods="post")
* *
* @return ResponseInterface * @RequestMapping(path="tag/editor", methods="post")
*/ */
public function editArticleTags() public function editArticleTags(): ResponseInterface
{ {
$params = $this->request->inputs(['tag_id', 'tag_name']); $params = $this->request->inputs(['tag_id', 'tag_name']);
$this->validate($params, [ $this->validate($params, [
@ -236,11 +221,10 @@ class ArticleController extends CController
/** /**
* 删除笔记标签 * 删除笔记标签
* @RequestMapping(path="del-article-tag", methods="post")
* *
* @return ResponseInterface * @RequestMapping(path="del-article-tag", methods="post")
*/ */
public function delArticleTags() public function delArticleTags(): ResponseInterface
{ {
$params = $this->request->inputs(['tag_id']); $params = $this->request->inputs(['tag_id']);
$this->validate($params, [ $this->validate($params, [
@ -256,11 +240,10 @@ class ArticleController extends CController
/** /**
* 添加或编辑笔记 * 添加或编辑笔记
* @RequestMapping(path="editor", methods="post")
* *
* @return ResponseInterface * @RequestMapping(path="editor", methods="post")
*/ */
public function editArticle() public function editArticle(): ResponseInterface
{ {
$params = $this->request->all(); $params = $this->request->all();
$this->validate($params, [ $this->validate($params, [
@ -287,11 +270,10 @@ class ArticleController extends CController
/** /**
* 删除笔记 * 删除笔记
* @RequestMapping(path="delete", methods="post")
* *
* @return ResponseInterface * @RequestMapping(path="delete", methods="post")
*/ */
public function deleteArticle() public function deleteArticle(): ResponseInterface
{ {
$params = $this->request->inputs(['article_id']); $params = $this->request->inputs(['article_id']);
$this->validate($params, [ $this->validate($params, [
@ -307,11 +289,10 @@ class ArticleController extends CController
/** /**
* 恢复删除笔记 * 恢复删除笔记
* @RequestMapping(path="recover", methods="post")
* *
* @return ResponseInterface * @RequestMapping(path="recover", methods="post")
*/ */
public function recoverArticle() public function recoverArticle(): ResponseInterface
{ {
$params = $this->request->inputs(['article_id']); $params = $this->request->inputs(['article_id']);
$this->validate($params, [ $this->validate($params, [
@ -327,12 +308,12 @@ class ArticleController extends CController
/** /**
* 笔记图片上传接口 * 笔记图片上传接口
* @RequestMapping(path="upload-image", methods="post")
* *
* @RequestMapping(path="upload-image", methods="post")
* @param Filesystem $filesystem * @param Filesystem $filesystem
* @return ResponseInterface * @return ResponseInterface
*/ */
public function uploadArticleImage(Filesystem $filesystem) public function uploadArticleImage(Filesystem $filesystem): ResponseInterface
{ {
$file = $this->request->file('image'); $file = $this->request->file('image');
if (!$file || !$file->isValid()) { if (!$file || !$file->isValid()) {
@ -358,11 +339,10 @@ class ArticleController extends CController
/** /**
* 移动笔记至指定分类 * 移动笔记至指定分类
* @RequestMapping(path="move", methods="post")
* *
* @return ResponseInterface * @RequestMapping(path="move", methods="post")
*/ */
public function moveArticle() public function moveArticle(): ResponseInterface
{ {
$params = $this->request->inputs(['article_id', 'class_id']); $params = $this->request->inputs(['article_id', 'class_id']);
$this->validate($params, [ $this->validate($params, [
@ -383,11 +363,10 @@ class ArticleController extends CController
/** /**
* 笔记标记星号接口 * 笔记标记星号接口
* @RequestMapping(path="asterisk", methods="post")
* *
* @return ResponseInterface * @RequestMapping(path="asterisk", methods="post")
*/ */
public function setAsterisk() public function setAsterisk(): ResponseInterface
{ {
$params = $this->request->inputs(['article_id', 'type']); $params = $this->request->inputs(['article_id', 'type']);
$this->validate($params, [ $this->validate($params, [
@ -408,11 +387,10 @@ class ArticleController extends CController
/** /**
* 更新笔记关联标签ID * 更新笔记关联标签ID
* @RequestMapping(path="update-tag", methods="post")
* *
* @return ResponseInterface * @RequestMapping(path="update-tag", methods="post")
*/ */
public function updateArticleTag() public function updateArticleTag(): ResponseInterface
{ {
$params = $this->request->inputs(['article_id', 'tags']); $params = $this->request->inputs(['article_id', 'tags']);
$this->validate($params, [ $this->validate($params, [
@ -429,12 +407,12 @@ class ArticleController extends CController
/** /**
* 永久删除笔记文章 * 永久删除笔记文章
* @RequestMapping(path="forever-delete", methods="post")
* *
* @RequestMapping(path="forever-delete", methods="post")
* @return ResponseInterface * @return ResponseInterface
* @throws \Exception * @throws \Exception
*/ */
public function foreverDelArticle() public function foreverDelArticle(): ResponseInterface
{ {
$params = $this->request->inputs(['article_id']); $params = $this->request->inputs(['article_id']);
$this->validate($params, [ $this->validate($params, [
@ -450,11 +428,12 @@ class ArticleController extends CController
/** /**
* 上传笔记附件 * 上传笔记附件
* @RequestMapping(path="annex/upload", methods="post")
* *
* @RequestMapping(path="annex/upload", methods="post")
* @param Filesystem $filesystem
* @return ResponseInterface * @return ResponseInterface
*/ */
public function uploadArticleAnnex(Filesystem $filesystem) public function uploadArticleAnnex(Filesystem $filesystem): ResponseInterface
{ {
$params = $this->request->inputs(['article_id']); $params = $this->request->inputs(['article_id']);
$this->validate($params, [ $this->validate($params, [
@ -492,11 +471,10 @@ class ArticleController extends CController
/** /**
* 删除笔记附件 * 删除笔记附件
* @RequestMapping(path="annex/delete", methods="post")
* *
* @return ResponseInterface * @RequestMapping(path="annex/delete", methods="post")
*/ */
public function deleteArticleAnnex() public function deleteArticleAnnex(): ResponseInterface
{ {
$params = $this->request->inputs(['annex_id']); $params = $this->request->inputs(['annex_id']);
$this->validate($params, [ $this->validate($params, [
@ -512,11 +490,10 @@ class ArticleController extends CController
/** /**
* 恢复笔记附件 * 恢复笔记附件
* @RequestMapping(path="annex/recover", methods="post")
* *
* @return ResponseInterface * @RequestMapping(path="annex/recover", methods="post")
*/ */
public function recoverArticleAnnex() public function recoverArticleAnnex(): ResponseInterface
{ {
$params = $this->request->inputs(['annex_id']); $params = $this->request->inputs(['annex_id']);
$this->validate($params, [ $this->validate($params, [
@ -532,11 +509,10 @@ class ArticleController extends CController
/** /**
* 获取附件回收站列表 * 获取附件回收站列表
* @RequestMapping(path="annex/recover-list", methods="get")
* *
* @return ResponseInterface * @RequestMapping(path="annex/recover-list", methods="get")
*/ */
public function recoverAnnexList() public function recoverAnnexList(): ResponseInterface
{ {
$rows = $this->articleService->recoverAnnexList($this->uid()); $rows = $this->articleService->recoverAnnexList($this->uid());
if ($rows) { if ($rows) {
@ -556,12 +532,12 @@ class ArticleController extends CController
/** /**
* 永久删除笔记附件(从已删除附件中永久删除) * 永久删除笔记附件(从已删除附件中永久删除)
* @RequestMapping(path="annex/forever-delete", methods="post")
* *
* @RequestMapping(path="annex/forever-delete", methods="post")
* @return ResponseInterface * @return ResponseInterface
* @throws \Exception * @throws \Exception
*/ */
public function foreverDelAnnex() public function foreverDelAnnex(): ResponseInterface
{ {
$params = $this->request->inputs(['annex_id']); $params = $this->request->inputs(['annex_id']);
$this->validate($params, [ $this->validate($params, [

View File

@ -1,15 +1,6 @@
<?php <?php
declare(strict_types=1); declare(strict_types=1);
/**
* This is my open source code, please do not use it for commercial applications.
* For the full copyright and license information,
* please view the LICENSE file that was distributed with this source code
*
* @author Yuandong<837215079@qq.com>
* @link https://github.com/gzydong/hyperf-chat
*/
namespace App\Controller\Api\V1; namespace App\Controller\Api\V1;
use App\Event\LoginEvent; use App\Event\LoginEvent;
@ -161,6 +152,7 @@ class AuthController extends CController
/** /**
* 授权刷新接口 * 授权刷新接口
*
* @RequestMapping(path="refresh", methods="post") * @RequestMapping(path="refresh", methods="post")
*/ */
public function refresh(): ResponseInterface public function refresh(): ResponseInterface

View File

@ -30,6 +30,8 @@ class ContactsApplyController extends CController
private $service; private $service;
/** /**
* 添加联系人申请接口
*
* @RequestMapping(path="create", methods="post") * @RequestMapping(path="create", methods="post")
* @param UserService $userService * @param UserService $userService
* @return ResponseInterface * @return ResponseInterface

View File

@ -1,12 +1,4 @@
<?php <?php
/**
* This is my open source code, please do not use it for commercial applications.
* For the full copyright and license information,
* please view the LICENSE file that was distributed with this source code
*
* @author Yuandong<837215079@qq.com>
* @link https://github.com/gzydong/hyperf-chat
*/
namespace App\Controller\Api\V1; namespace App\Controller\Api\V1;
@ -42,11 +34,10 @@ class ContactsController extends CController
/** /**
* 获取用户联系人列表 * 获取用户联系人列表
* @RequestMapping(path="list", methods="get")
* *
* @return ResponseInterface * @RequestMapping(path="list", methods="get")
*/ */
public function getContacts(UserService $service) public function getContacts(UserService $service): ResponseInterface
{ {
$rows = $service->getUserFriends($this->uid()); $rows = $service->getUserFriends($this->uid());
if ($rows) { if ($rows) {
@ -61,11 +52,10 @@ class ContactsController extends CController
/** /**
* 删除联系人 * 删除联系人
* @RequestMapping(path="delete", methods="post")
* *
* @return ResponseInterface * @RequestMapping(path="delete", methods="post")
*/ */
public function deleteContact() public function deleteContact(): ResponseInterface
{ {
$params = $this->request->inputs(['friend_id']); $params = $this->request->inputs(['friend_id']);
$this->validate($params, [ $this->validate($params, [
@ -86,11 +76,10 @@ class ContactsController extends CController
/** /**
* 获取联系人申请未读数 * 获取联系人申请未读数
* @RequestMapping(path="apply-unread-num", methods="get")
* *
* @return ResponseInterface * @RequestMapping(path="apply-unread-num", methods="get")
*/ */
public function getContactApplyUnreadNum() public function getContactApplyUnreadNum(): ResponseInterface
{ {
return $this->response->success([ return $this->response->success([
'unread_num' => (int)FriendApply::getInstance()->get(strval($this->uid())) 'unread_num' => (int)FriendApply::getInstance()->get(strval($this->uid()))
@ -99,11 +88,10 @@ class ContactsController extends CController
/** /**
* 搜索联系人 * 搜索联系人
* @RequestMapping(path="search", methods="get")
* *
* @return ResponseInterface * @RequestMapping(path="search", methods="get")
*/ */
public function searchContacts() public function searchContacts(): ResponseInterface
{ {
$params = $this->request->inputs(['mobile']); $params = $this->request->inputs(['mobile']);
$this->validate($params, [ $this->validate($params, [
@ -116,11 +104,10 @@ class ContactsController extends CController
/** /**
* 编辑联系人备注 * 编辑联系人备注
* @RequestMapping(path="edit-remark", methods="post")
* *
* @return ResponseInterface * @RequestMapping(path="edit-remark", methods="post")
*/ */
public function editContactRemark() public function editContactRemark(): ResponseInterface
{ {
$params = $this->request->inputs(['friend_id', 'remarks']); $params = $this->request->inputs(['friend_id', 'remarks']);
$this->validate($params, [ $this->validate($params, [
@ -129,7 +116,7 @@ class ContactsController extends CController
]); ]);
$user_id = $this->uid(); $user_id = $this->uid();
$isTrue = $this->service->editRemark($user_id, intval($params['friend_id']), $params['remarks']); $isTrue = $this->service->editRemark($user_id, intval($params['friend_id']), $params['remarks']);
if (!$isTrue) { if (!$isTrue) {
return $this->response->fail('备注修改失败!'); return $this->response->fail('备注修改失败!');
} }

View File

@ -1,12 +1,4 @@
<?php <?php
/**
* This is my open source code, please do not use it for commercial applications.
* For the full copyright and license information,
* please view the LICENSE file that was distributed with this source code
*
* @author Yuandong<837215079@qq.com>
* @link https://github.com/gzydong/hyperf-chat
*/
namespace App\Controller\Api\V1; namespace App\Controller\Api\V1;

View File

@ -1,12 +1,4 @@
<?php <?php
/**
* This is my open source code, please do not use it for commercial applications.
* For the full copyright and license information,
* please view the LICENSE file that was distributed with this source code
*
* @author Yuandong<837215079@qq.com>
* @link https://github.com/gzydong/hyperf-chat
*/
namespace App\Controller\Api\V1; namespace App\Controller\Api\V1;
@ -39,11 +31,10 @@ class EmoticonController extends CController
/** /**
* 获取用户表情包列表 * 获取用户表情包列表
* @RequestMapping(path="list", methods="get")
* *
* @return ResponseInterface * @RequestMapping(path="list", methods="get")
*/ */
public function list() public function list(): ResponseInterface
{ {
$emoticonList = []; $emoticonList = [];
$user_id = $this->uid(); $user_id = $this->uid();
@ -74,11 +65,10 @@ class EmoticonController extends CController
/** /**
* 获取系统表情包 * 获取系统表情包
* @RequestMapping(path="system", methods="get")
* *
* @return ResponseInterface * @RequestMapping(path="system", methods="get")
*/ */
public function system() public function system(): ResponseInterface
{ {
$items = Emoticon::get(['id', 'name', 'icon'])->toArray(); $items = Emoticon::get(['id', 'name', 'icon'])->toArray();
if ($items) { if ($items) {
@ -94,11 +84,10 @@ class EmoticonController extends CController
/** /**
* 安装或移除系统表情包 * 安装或移除系统表情包
* @RequestMapping(path="set-user-emoticon", methods="post")
* *
* @return ResponseInterface * @RequestMapping(path="set-user-emoticon", methods="post")
*/ */
public function setUserEmoticon() public function setUserEmoticon(): ResponseInterface
{ {
$params = $this->request->all(); $params = $this->request->all();
$this->validate($params, [ $this->validate($params, [
@ -142,12 +131,12 @@ class EmoticonController extends CController
/** /**
* 自定义上传表情包 * 自定义上传表情包
* @RequestMapping(path="upload", methods="post")
* *
* @RequestMapping(path="upload", methods="post")
* @param Filesystem $filesystem * @param Filesystem $filesystem
* @return ResponseInterface * @return ResponseInterface
*/ */
public function upload(Filesystem $filesystem) public function upload(Filesystem $filesystem): ResponseInterface
{ {
$file = $this->request->file('emoticon'); $file = $this->request->file('emoticon');
if (!$file->isValid()) { if (!$file->isValid()) {
@ -192,12 +181,10 @@ class EmoticonController extends CController
/** /**
* 移除收藏的表情包 * 移除收藏的表情包
* @RequestMapping(path="del-collect-emoticon", methods="post")
* *
* @return ResponseInterface * @RequestMapping(path="del-collect-emoticon", methods="post")
* @throws \Exception
*/ */
public function delCollectEmoticon() public function delCollectEmoticon(): ResponseInterface
{ {
$params = $this->request->inputs(['ids']); $params = $this->request->inputs(['ids']);
$this->validate($params, [ $this->validate($params, [

View File

@ -1,12 +1,4 @@
<?php <?php
/**
* This is my open source code, please do not use it for commercial applications.
* For the full copyright and license information,
* please view the LICENSE file that was distributed with this source code
*
* @author Yuandong<837215079@qq.com>
* @link https://github.com/gzydong/hyperf-chat
*/
namespace App\Controller\Api\V1; namespace App\Controller\Api\V1;
@ -51,10 +43,8 @@ class GroupController extends CController
/** /**
* 创建群组 * 创建群组
* @RequestMapping(path="create", methods="post") * @RequestMapping(path="create", methods="post")
*
* @return ResponseInterface
*/ */
public function create() public function create(): ResponseInterface
{ {
$params = $this->request->inputs(['group_name', 'uids']); $params = $this->request->inputs(['group_name', 'uids']);
$this->validate($params, [ $this->validate($params, [
@ -78,10 +68,8 @@ class GroupController extends CController
/** /**
* 解散群组接口 * 解散群组接口
* @RequestMapping(path="dismiss", methods="post") * @RequestMapping(path="dismiss", methods="post")
*
* @return ResponseInterface
*/ */
public function dismiss() public function dismiss(): ResponseInterface
{ {
$params = $this->request->inputs(['group_id']); $params = $this->request->inputs(['group_id']);
$this->validate($params, [ $this->validate($params, [
@ -99,10 +87,8 @@ class GroupController extends CController
/** /**
* 邀请好友加入群组接口 * 邀请好友加入群组接口
* @RequestMapping(path="invite", methods="post") * @RequestMapping(path="invite", methods="post")
*
* @return ResponseInterface
*/ */
public function invite() public function invite(): ResponseInterface
{ {
$params = $this->request->inputs(['group_id', 'uids']); $params = $this->request->inputs(['group_id', 'uids']);
$this->validate($params, [ $this->validate($params, [
@ -121,10 +107,8 @@ class GroupController extends CController
/** /**
* 退出群组接口 * 退出群组接口
* @RequestMapping(path="secede", methods="post") * @RequestMapping(path="secede", methods="post")
*
* @return ResponseInterface
*/ */
public function secede() public function secede(): ResponseInterface
{ {
$params = $this->request->inputs(['group_id']); $params = $this->request->inputs(['group_id']);
$this->validate($params, [ $this->validate($params, [
@ -141,10 +125,8 @@ class GroupController extends CController
/** /**
* 编辑群组信息 * 编辑群组信息
* @RequestMapping(path="edit", methods="post") * @RequestMapping(path="edit", methods="post")
*
* @return ResponseInterface
*/ */
public function editDetail() public function editDetail(): ResponseInterface
{ {
$params = $this->request->inputs(['group_id', 'group_name', 'profile', 'avatar']); $params = $this->request->inputs(['group_id', 'group_name', 'profile', 'avatar']);
$this->validate($params, [ $this->validate($params, [
@ -162,10 +144,8 @@ class GroupController extends CController
/** /**
* 移除指定成员(管理员权限) * 移除指定成员(管理员权限)
* @RequestMapping(path="remove-members", methods="post") * @RequestMapping(path="remove-members", methods="post")
*
* @return ResponseInterface
*/ */
public function removeMembers() public function removeMembers(): ResponseInterface
{ {
$params = $this->request->inputs(['group_id', 'members_ids']); $params = $this->request->inputs(['group_id', 'members_ids']);
$this->validate($params, [ $this->validate($params, [
@ -191,10 +171,8 @@ class GroupController extends CController
/** /**
* 获取群信息接口 * 获取群信息接口
* @RequestMapping(path="detail", methods="get") * @RequestMapping(path="detail", methods="get")
*
* @return ResponseInterface
*/ */
public function detail(TalkListService $service) public function detail(TalkListService $service): ResponseInterface
{ {
$group_id = $this->request->input('group_id', 0); $group_id = $this->request->input('group_id', 0);
$user_id = $this->uid(); $user_id = $this->uid();
@ -231,10 +209,8 @@ class GroupController extends CController
/** /**
* 设置群名片 * 设置群名片
* @RequestMapping(path="set-group-card", methods="post") * @RequestMapping(path="set-group-card", methods="post")
*
* @return ResponseInterface
*/ */
public function editGroupCard() public function editGroupCard(): ResponseInterface
{ {
$params = $this->request->inputs(['group_id', 'visit_card']); $params = $this->request->inputs(['group_id', 'visit_card']);
$this->validate($params, [ $this->validate($params, [
@ -252,10 +228,8 @@ class GroupController extends CController
/** /**
* 获取可邀请加入群组的好友列表 * 获取可邀请加入群组的好友列表
* @RequestMapping(path="invite-friends", methods="get") * @RequestMapping(path="invite-friends", methods="get")
*
* @return ResponseInterface
*/ */
public function getInviteFriends(UserService $service) public function getInviteFriends(UserService $service): ResponseInterface
{ {
$group_id = $this->request->input('group_id', 0); $group_id = $this->request->input('group_id', 0);
$friends = $service->getUserFriends($this->uid()); $friends = $service->getUserFriends($this->uid());
@ -275,10 +249,8 @@ class GroupController extends CController
/** /**
* 获取群组列表 * 获取群组列表
* @RequestMapping(path="list", methods="get") * @RequestMapping(path="list", methods="get")
*
* @return ResponseInterface
*/ */
public function getGroups() public function getGroups(): ResponseInterface
{ {
return $this->response->success( return $this->response->success(
$this->groupService->getUserGroups($this->uid()) $this->groupService->getUserGroups($this->uid())
@ -288,10 +260,8 @@ class GroupController extends CController
/** /**
* 获取群组成员列表 * 获取群组成员列表
* @RequestMapping(path="members", methods="get") * @RequestMapping(path="members", methods="get")
*
* @return ResponseInterface
*/ */
public function getGroupMembers() public function getGroupMembers(): ResponseInterface
{ {
$user_id = $this->uid(); $user_id = $this->uid();
$group_id = $this->request->input('group_id', 0); $group_id = $this->request->input('group_id', 0);
@ -323,10 +293,8 @@ class GroupController extends CController
/** /**
* 获取群组公告列表 * 获取群组公告列表
* @RequestMapping(path="notices", methods="get") * @RequestMapping(path="notices", methods="get")
*
* @return ResponseInterface
*/ */
public function getGroupNotice(GroupNoticeService $service) public function getGroupNotice(GroupNoticeService $service): ResponseInterface
{ {
$user_id = $this->uid(); $user_id = $this->uid();
$group_id = $this->request->input('group_id', 0); $group_id = $this->request->input('group_id', 0);
@ -342,12 +310,13 @@ class GroupController extends CController
/** /**
* 创建/编辑群公告 * 创建/编辑群公告
* @RequestMapping(path="edit-notice", methods="post") * @RequestMapping(path="edit-notice", methods="post")
*
* @return ResponseInterface
*/ */
public function editNotice(GroupNoticeService $service) public function editNotice(GroupNoticeService $service): ResponseInterface
{ {
$params = $this->request->inputs(['group_id', 'notice_id', 'title', 'content', 'is_top', 'is_confirm']); $params = $this->request->inputs([
'group_id', 'notice_id', 'title', 'content', 'is_top', 'is_confirm'
]);
$this->validate($params, [ $this->validate($params, [
'notice_id' => 'required|integer', 'notice_id' => 'required|integer',
'group_id' => 'required|integer', 'group_id' => 'required|integer',
@ -381,10 +350,8 @@ class GroupController extends CController
/** /**
* 删除群公告(软删除) * 删除群公告(软删除)
* @RequestMapping(path="delete-notice", methods="post") * @RequestMapping(path="delete-notice", methods="post")
*
* @return ResponseInterface
*/ */
public function deleteNotice(GroupNoticeService $service) public function deleteNotice(GroupNoticeService $service): ResponseInterface
{ {
$params = $this->request->inputs(['group_id', 'notice_id']); $params = $this->request->inputs(['group_id', 'notice_id']);
$this->validate($params, [ $this->validate($params, [

View File

@ -1,12 +1,4 @@
<?php <?php
/**
* This is my open source code, please do not use it for commercial applications.
* For the full copyright and license information,
* please view the LICENSE file that was distributed with this source code
*
* @author Yuandong<837215079@qq.com>
* @link https://github.com/gzydong/hyperf-chat
*/
namespace App\Controller\Api\V1; namespace App\Controller\Api\V1;
@ -57,7 +49,7 @@ class TalkController extends CController
* *
* @return ResponseInterface * @return ResponseInterface
*/ */
public function list() public function list(): ResponseInterface
{ {
$user_id = $this->uid(); $user_id = $this->uid();
@ -74,10 +66,8 @@ class TalkController extends CController
/** /**
* 新增对话列表 * 新增对话列表
* @RequestMapping(path="create", methods="post") * @RequestMapping(path="create", methods="post")
*
* @return ResponseInterface
*/ */
public function create(UserFriendService $service) public function create(UserFriendService $service): ResponseInterface
{ {
$params = $this->request->inputs(['talk_type', 'receiver_id']); $params = $this->request->inputs(['talk_type', 'receiver_id']);
$this->validate($params, [ $this->validate($params, [
@ -135,10 +125,8 @@ class TalkController extends CController
/** /**
* 删除对话列表 * 删除对话列表
* @RequestMapping(path="delete", methods="post") * @RequestMapping(path="delete", methods="post")
*
* @return ResponseInterface
*/ */
public function delete() public function delete(): ResponseInterface
{ {
$params = $this->request->inputs(['list_id']); $params = $this->request->inputs(['list_id']);
$this->validate($params, [ $this->validate($params, [
@ -153,10 +141,8 @@ class TalkController extends CController
/** /**
* 对话列表置顶 * 对话列表置顶
* @RequestMapping(path="topping", methods="post") * @RequestMapping(path="topping", methods="post")
*
* @return ResponseInterface
*/ */
public function topping() public function topping(): ResponseInterface
{ {
$params = $this->request->inputs(['list_id', 'type']); $params = $this->request->inputs(['list_id', 'type']);
$this->validate($params, [ $this->validate($params, [
@ -172,10 +158,8 @@ class TalkController extends CController
/** /**
* 设置消息免打扰状态 * 设置消息免打扰状态
* @RequestMapping(path="disturb", methods="post") * @RequestMapping(path="disturb", methods="post")
*
* @return ResponseInterface
*/ */
public function disturb() public function disturb(): ResponseInterface
{ {
$params = $this->request->inputs(['talk_type', 'receiver_id', 'is_disturb']); $params = $this->request->inputs(['talk_type', 'receiver_id', 'is_disturb']);
$this->validate($params, [ $this->validate($params, [
@ -192,10 +176,8 @@ class TalkController extends CController
/** /**
* 更新对话列表未读数 * 更新对话列表未读数
* @RequestMapping(path="update-unread-num", methods="post") * @RequestMapping(path="update-unread-num", methods="post")
*
* @return ResponseInterface
*/ */
public function updateUnreadNum() public function updateUnreadNum(): ResponseInterface
{ {
$params = $this->request->inputs(['talk_type', 'receiver_id']); $params = $this->request->inputs(['talk_type', 'receiver_id']);
$this->validate($params, [ $this->validate($params, [
@ -214,10 +196,8 @@ class TalkController extends CController
/** /**
* 获取对话面板中的聊天记录 * 获取对话面板中的聊天记录
* @RequestMapping(path="records", methods="get") * @RequestMapping(path="records", methods="get")
*
* @return ResponseInterface
*/ */
public function getChatRecords() public function getChatRecords(): ResponseInterface
{ {
$params = $this->request->inputs(['talk_type', 'receiver_id', 'record_id']); $params = $this->request->inputs(['talk_type', 'receiver_id', 'record_id']);
$this->validate($params, [ $this->validate($params, [
@ -251,10 +231,8 @@ class TalkController extends CController
/** /**
* 获取转发记录详情 * 获取转发记录详情
* @RequestMapping(path="get-forward-records", methods="get") * @RequestMapping(path="get-forward-records", methods="get")
*
* @return ResponseInterface
*/ */
public function getForwardRecords() public function getForwardRecords(): ResponseInterface
{ {
$params = $this->request->inputs(['record_id']); $params = $this->request->inputs(['record_id']);
$this->validate($params, [ $this->validate($params, [
@ -269,10 +247,8 @@ class TalkController extends CController
/** /**
* 查询聊天记录 * 查询聊天记录
* @RequestMapping(path="find-chat-records", methods="get") * @RequestMapping(path="find-chat-records", methods="get")
*
* @return ResponseInterface
*/ */
public function findChatRecords() public function findChatRecords(): ResponseInterface
{ {
$params = $this->request->inputs(['talk_type', 'receiver_id', 'record_id', 'msg_type']); $params = $this->request->inputs(['talk_type', 'receiver_id', 'record_id', 'msg_type']);
$this->validate($params, [ $this->validate($params, [

View File

@ -20,6 +20,7 @@ use Hyperf\HttpServer\Annotation\RequestMapping;
use Hyperf\HttpServer\Annotation\Middleware; use Hyperf\HttpServer\Annotation\Middleware;
use App\Middleware\JWTAuthMiddleware; use App\Middleware\JWTAuthMiddleware;
use League\Flysystem\Filesystem; use League\Flysystem\Filesystem;
use Psr\Http\Message\ResponseInterface;
/** /**
* Class TalkController * Class TalkController
@ -44,9 +45,10 @@ class TalkMessageController extends CController
/** /**
* 发送文本消息 * 发送文本消息
*
* @RequestMapping(path="text", methods="post") * @RequestMapping(path="text", methods="post")
*/ */
public function text() public function text(): ResponseInterface
{ {
$params = $this->request->inputs(['talk_type', 'receiver_id', 'text']); $params = $this->request->inputs(['talk_type', 'receiver_id', 'text']);
$this->validate($params, [ $this->validate($params, [
@ -55,7 +57,7 @@ class TalkMessageController extends CController
'text' => 'required|max:65535', 'text' => 'required|max:65535',
]); ]);
di()->get(TalkMessageService::class)->insertTextMessage([ di()->get(TalkMessageService::class)->insertText([
'talk_type' => $params['talk_type'], 'talk_type' => $params['talk_type'],
'user_id' => $this->uid(), 'user_id' => $this->uid(),
'receiver_id' => $params['receiver_id'], 'receiver_id' => $params['receiver_id'],
@ -67,9 +69,10 @@ class TalkMessageController extends CController
/** /**
* 发送代码块消息 * 发送代码块消息
*
* @RequestMapping(path="code", methods="post") * @RequestMapping(path="code", methods="post")
*/ */
public function code() public function code(): ResponseInterface
{ {
$params = $this->request->inputs(['talk_type', 'receiver_id', 'lang', 'code']); $params = $this->request->inputs(['talk_type', 'receiver_id', 'lang', 'code']);
$this->validate($params, [ $this->validate($params, [
@ -84,7 +87,7 @@ class TalkMessageController extends CController
return $this->response->fail('暂不属于好友关系或群聊成员,无法发送聊天消息!'); return $this->response->fail('暂不属于好友关系或群聊成员,无法发送聊天消息!');
} }
$isTrue = $this->talkMessageService->insertCodeMessage([ $isTrue = $this->talkMessageService->insertCode([
'talk_type' => $params['talk_type'], 'talk_type' => $params['talk_type'],
'user_id' => $user_id, 'user_id' => $user_id,
'receiver_id' => $params['receiver_id'], 'receiver_id' => $params['receiver_id'],
@ -101,9 +104,10 @@ class TalkMessageController extends CController
/** /**
* 发送图片消息 * 发送图片消息
*
* @RequestMapping(path="image", methods="post") * @RequestMapping(path="image", methods="post")
*/ */
public function image(Filesystem $filesystem) public function image(Filesystem $filesystem): ResponseInterface
{ {
$params = $this->request->inputs(['talk_type', 'receiver_id']); $params = $this->request->inputs(['talk_type', 'receiver_id']);
$this->validate($params, [ $this->validate($params, [
@ -134,7 +138,7 @@ class TalkMessageController extends CController
} }
// 创建图片消息记录 // 创建图片消息记录
$isTrue = $this->talkMessageService->insertFileMessage([ $isTrue = $this->talkMessageService->insertFile([
'talk_type' => $params['talk_type'], 'talk_type' => $params['talk_type'],
'user_id' => $user_id, 'user_id' => $user_id,
'receiver_id' => $params['receiver_id'], 'receiver_id' => $params['receiver_id'],
@ -153,9 +157,10 @@ class TalkMessageController extends CController
/** /**
* 发送文件消息 * 发送文件消息
*
* @RequestMapping(path="file", methods="post") * @RequestMapping(path="file", methods="post")
*/ */
public function file(Filesystem $filesystem) public function file(Filesystem $filesystem): ResponseInterface
{ {
$params = $this->request->inputs(['talk_type', 'receiver_id', 'hash_name']); $params = $this->request->inputs(['talk_type', 'receiver_id', 'hash_name']);
$this->validate($params, [ $this->validate($params, [
@ -181,7 +186,7 @@ class TalkMessageController extends CController
return $this->response->fail('文件不存在...'); return $this->response->fail('文件不存在...');
} }
$isTrue = $this->talkMessageService->insertFileMessage([ $isTrue = $this->talkMessageService->insertFile([
'talk_type' => $params['talk_type'], 'talk_type' => $params['talk_type'],
'user_id' => $user_id, 'user_id' => $user_id,
'receiver_id' => $params['receiver_id'] 'receiver_id' => $params['receiver_id']
@ -201,9 +206,10 @@ class TalkMessageController extends CController
/** /**
* 发送投票消息 * 发送投票消息
*
* @RequestMapping(path="vote", methods="post") * @RequestMapping(path="vote", methods="post")
*/ */
public function vote() public function vote(): ResponseInterface
{ {
$params = $this->request->all(); $params = $this->request->all();
$this->validate($params, [ $this->validate($params, [
@ -218,7 +224,7 @@ class TalkMessageController extends CController
return $this->response->fail('暂不属于好友关系或群聊成员,无法发送聊天消息!'); return $this->response->fail('暂不属于好友关系或群聊成员,无法发送聊天消息!');
} }
$isTrue = $this->talkMessageService->insertVoteMessage([ $isTrue = $this->talkMessageService->insertVote([
'talk_type' => TalkModeConstant::GROUP_CHAT, 'talk_type' => TalkModeConstant::GROUP_CHAT,
'user_id' => $user_id, 'user_id' => $user_id,
'receiver_id' => $params['receiver_id'], 'receiver_id' => $params['receiver_id'],
@ -236,9 +242,10 @@ class TalkMessageController extends CController
/** /**
* 投票处理 * 投票处理
*
* @RequestMapping(path="vote/handle", methods="post") * @RequestMapping(path="vote/handle", methods="post")
*/ */
public function handleVote() public function handleVote(): ResponseInterface
{ {
$params = $this->request->inputs(['record_id', 'options']); $params = $this->request->inputs(['record_id', 'options']);
$this->validate($params, [ $this->validate($params, [
@ -260,9 +267,10 @@ class TalkMessageController extends CController
/** /**
* 发送表情包消息 * 发送表情包消息
*
* @RequestMapping(path="emoticon", methods="post") * @RequestMapping(path="emoticon", methods="post")
*/ */
public function emoticon() public function emoticon(): ResponseInterface
{ {
$params = $this->request->inputs(['talk_type', 'receiver_id', 'emoticon_id']); $params = $this->request->inputs(['talk_type', 'receiver_id', 'emoticon_id']);
$this->validate($params, [ $this->validate($params, [
@ -280,7 +288,7 @@ class TalkMessageController extends CController
if (!$emoticon) return $this->response->fail('表情不存在!'); if (!$emoticon) return $this->response->fail('表情不存在!');
$isTrue = $this->talkMessageService->insertFileMessage([ $isTrue = $this->talkMessageService->insertFile([
'talk_type' => $params['talk_type'], 'talk_type' => $params['talk_type'],
'user_id' => $user_id, 'user_id' => $user_id,
'receiver_id' => $params['receiver_id'], 'receiver_id' => $params['receiver_id'],
@ -299,11 +307,15 @@ class TalkMessageController extends CController
/** /**
* 转发消息记录 * 转发消息记录
*
* @RequestMapping(path="forward", methods="post") * @RequestMapping(path="forward", methods="post")
*/ */
public function forward(TalkForwardService $forwardService) public function forward(TalkForwardService $forwardService): ResponseInterface
{ {
$params = $this->request->inputs(['talk_type', 'receiver_id', 'records_ids', 'forward_mode', 'receive_user_ids', 'receive_group_ids']); $params = $this->request->inputs([
'talk_type', 'receiver_id', 'records_ids', 'forward_mode', 'receive_user_ids', 'receive_group_ids'
]);
$this->validate($params, [ $this->validate($params, [
'talk_type' => 'required|in:1,2', 'talk_type' => 'required|in:1,2',
'receiver_id' => 'required|integer|min:1', 'receiver_id' => 'required|integer|min:1',
@ -366,9 +378,10 @@ class TalkMessageController extends CController
/** /**
* 收藏聊天图片 * 收藏聊天图片
*
* @RequestMapping(path="collect", methods="post") * @RequestMapping(path="collect", methods="post")
*/ */
public function collect(EmoticonService $service) public function collect(EmoticonService $service): ResponseInterface
{ {
$params = $this->request->inputs(['record_id']); $params = $this->request->inputs(['record_id']);
$this->validate($params, [ $this->validate($params, [
@ -386,9 +399,10 @@ class TalkMessageController extends CController
/** /**
* 撤销聊天记录 * 撤销聊天记录
*
* @RequestMapping(path="revoke", methods="post") * @RequestMapping(path="revoke", methods="post")
*/ */
public function revoke() public function revoke(): ResponseInterface
{ {
$params = $this->request->inputs(['record_id']); $params = $this->request->inputs(['record_id']);
$this->validate($params, [ $this->validate($params, [
@ -403,9 +417,10 @@ class TalkMessageController extends CController
/** /**
* 删除聊天记录 * 删除聊天记录
*
* @RequestMapping(path="delete", methods="post") * @RequestMapping(path="delete", methods="post")
*/ */
public function delete() public function delete(): ResponseInterface
{ {
$params = $this->request->inputs(['talk_type', 'receiver_id', 'record_id']); $params = $this->request->inputs(['talk_type', 'receiver_id', 'record_id']);
$this->validate($params, [ $this->validate($params, [

View File

@ -1,12 +1,4 @@
<?php <?php
/**
* This is my open source code, please do not use it for commercial applications.
* For the full copyright and license information,
* please view the LICENSE file that was distributed with this source code
*
* @author Yuandong<837215079@qq.com>
* @link https://github.com/gzydong/hyperf-chat
*/
declare(strict_types=1); declare(strict_types=1);
namespace App\Controller\Api\V1; namespace App\Controller\Api\V1;

View File

@ -1,15 +1,6 @@
<?php <?php
declare(strict_types=1); declare(strict_types=1);
/**
* This is my open source code, please do not use it for commercial applications.
* For the full copyright and license information,
* please view the LICENSE file that was distributed with this source code
*
* @author Yuandong<837215079@qq.com>
* @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;
@ -103,11 +94,11 @@ class UsersController extends CController
'avatar' => 'present|url' 'avatar' => 'present|url'
]); ]);
$isTrue = User::where('id', $this->uid())->update($params); $params['updated_at'] = date("Y-m-d H:i:s");
return $isTrue User::where('id', $this->uid())->update($params);
? $this->response->success([], '个人信息修改成功...')
: $this->response->fail('个人信息修改失败!'); return $this->response->success([], '个人信息修改成功...');
} }
/** /**
@ -123,11 +114,12 @@ class UsersController extends CController
'avatar' => 'required|url' 'avatar' => 'required|url'
]); ]);
$isTrue = User::where('id', $this->uid())->update(['avatar' => $params['avatar']]); User::where('id', $this->uid())->update([
'avatar' => $params['avatar'],
'updated_at' => date("Y-m-d H:i:s")
]);
return $isTrue return $this->response->success([], '头像修改成功...');
? $this->response->success([], '头像修改成功...')
: $this->response->fail('头像修改失败!');
} }
/** /**
@ -165,14 +157,16 @@ class UsersController extends CController
$userInfo = $this->user(); $userInfo = $this->user();
// 验证密码是否正确 // 验证密码是否正确
if (!HashHelper::check($this->request->post('old_password'), $userInfo->password)) { if (!HashHelper::check($params['old_password'], $userInfo->password)) {
return $this->response->fail('旧密码验证失败!'); return $this->response->fail('旧密码验证失败!');
} }
$isTrue = $this->userService->resetPassword($userInfo->mobile, $params['new_password']); $isTrue = $this->userService->resetPassword($userInfo->mobile, $params['new_password']);
return $isTrue if (!$isTrue) {
? $this->response->success([], '密码修改成功...') return $this->response->fail('密码修改失败!');
: $this->response->fail('密码修改失败!'); }
return $this->response->success([], '密码修改成功...');
} }
/** /**
@ -191,7 +185,7 @@ class UsersController extends CController
'sms_code' => 'required|digits:6' 'sms_code' => 'required|digits:6'
]); ]);
if (!$smsCodeService->check('change_mobile', $params['mobile'], $params['sms_code'])) { if (!$smsCodeService->check('change_mobile', $params['mobile'], (string)$params['sms_code'])) {
return $this->response->fail('验证码填写错误!'); return $this->response->fail('验证码填写错误!');
} }
@ -226,7 +220,7 @@ class UsersController extends CController
]); ]);
$sendEmailCode = new SendEmailCode(); $sendEmailCode = new SendEmailCode();
if (!$sendEmailCode->check(SendEmailCode::CHANGE_EMAIL, $params['email'], $params['email_code'])) { if (!$sendEmailCode->check(SendEmailCode::CHANGE_EMAIL, $params['email'], (string)$params['email_code'])) {
return $this->response->fail('验证码填写错误!'); return $this->response->fail('验证码填写错误!');
} }

View File

@ -1,5 +1,6 @@
<?php <?php
declare(strict_types=1); declare(strict_types=1);
/** /**
* This is my open source code, please do not use it for commercial applications. * This is my open source code, please do not use it for commercial applications.
* For the full copyright and license information, * For the full copyright and license information,

View File

@ -1,5 +1,4 @@
<?php <?php
declare(strict_types=1); declare(strict_types=1);
namespace App\Exception\Handler; namespace App\Exception\Handler;

View File

@ -1,4 +1,5 @@
<?php <?php
declare(strict_types=1);
namespace App\Exception\Handler; namespace App\Exception\Handler;

View File

@ -1,4 +1,5 @@
<?php <?php
declare(strict_types=1);
namespace App\Exception\Handler; namespace App\Exception\Handler;

View File

@ -1,4 +1,5 @@
<?php <?php
declare(strict_types=1);
namespace App\Exception\Handler; namespace App\Exception\Handler;

View File

@ -1,12 +1,5 @@
<?php <?php
/** declare(strict_types=1);
* This is my open source code, please do not use it for commercial applications.
* For the full copyright and license information,
* please view the LICENSE file that was distributed with this source code
*
* @author Yuandong<837215079@qq.com>
* @link https://github.com/gzydong/hyperf-chat
*/
namespace App\Exception; namespace App\Exception;

View File

@ -1,15 +1,6 @@
<?php <?php
declare(strict_types=1); declare(strict_types=1);
/**
* This is my open source code, please do not use it for commercial applications.
* For the full copyright and license information,
* please view the LICENSE file that was distributed with this source code
*
* @author Yuandong<837215079@qq.com>
* @link https://github.com/gzydong/hyperf-chat
*/
namespace App\Helpers; namespace App\Helpers;
/** /**

View File

@ -1,12 +1,5 @@
<?php <?php
/** declare(strict_types=1);
* This is my open source code, please do not use it for commercial applications.
* For the full copyright and license information,
* please view the LICENSE file that was distributed with this source code
*
* @author Yuandong<837215079@qq.com>
* @link https://github.com/gzydong/hyperf-chat
*/
namespace App\Helpers; namespace App\Helpers;

View File

@ -1,15 +1,6 @@
<?php <?php
declare(strict_types=1); declare(strict_types=1);
/**
* This is my open source code, please do not use it for commercial applications.
* For the full copyright and license information,
* please view the LICENSE file that was distributed with this source code
*
* @author Yuandong<837215079@qq.com>
* @link https://github.com/gzydong/hyperf-chat
*/
namespace App\Helpers; namespace App\Helpers;
/** /**

View File

@ -1,4 +1,6 @@
<?php <?php
declare(strict_types=1);
/** /**
* This is my open source code, please do not use it for commercial applications. * This is my open source code, please do not use it for commercial applications.
* For the full copyright and license information, * For the full copyright and license information,

View File

@ -1,5 +1,6 @@
<?php <?php
declare(strict_types=1); declare(strict_types=1);
/** /**
* This is my open source code, please do not use it for commercial applications. * This is my open source code, please do not use it for commercial applications.
* For the full copyright and license information, * For the full copyright and license information,

View File

@ -1,6 +1,6 @@
<?php <?php
declare(strict_types=1); declare(strict_types=1);
/** /**
* This file is part of Hyperf. * This file is part of Hyperf.
* *

View File

@ -1,5 +1,4 @@
<?php <?php
declare(strict_types=1); declare(strict_types=1);
namespace App\Process; namespace App\Process;

View File

@ -1,5 +1,4 @@
<?php <?php
declare(strict_types=1); declare(strict_types=1);
namespace App\Process; namespace App\Process;

View File

@ -1,4 +1,5 @@
<?php <?php
declare(strict_types=1);
namespace App\Service; namespace App\Service;

View File

@ -32,7 +32,7 @@ class TalkMessageService
* @param array $message * @param array $message
* @return bool * @return bool
*/ */
public function insertTextMessage(array $message): bool public function insertText(array $message): bool
{ {
$message['msg_type'] = TalkMessageType::TEXT_MESSAGE; $message['msg_type'] = TalkMessageType::TEXT_MESSAGE;
$message['content'] = htmlspecialchars($message['content']); $message['content'] = htmlspecialchars($message['content']);
@ -62,7 +62,6 @@ class TalkMessageService
return true; return true;
} }
/** /**
* 创建代码块消息 * 创建代码块消息
* *
@ -70,7 +69,7 @@ class TalkMessageService
* @param array $code * @param array $code
* @return bool * @return bool
*/ */
public function insertCodeMessage(array $message, array $code): bool public function insertCode(array $message, array $code): bool
{ {
Db::beginTransaction(); Db::beginTransaction();
try { try {
@ -117,7 +116,7 @@ class TalkMessageService
* @param array $file * @param array $file
* @return bool * @return bool
*/ */
public function insertFileMessage(array $message, array $file): bool public function insertFile(array $message, array $file): bool
{ {
Db::beginTransaction(); Db::beginTransaction();
try { try {
@ -165,7 +164,7 @@ class TalkMessageService
* @param array $vote * @param array $vote
* @return bool * @return bool
*/ */
public function insertVoteMessage(array $message, array $vote): bool public function insertVote(array $message, array $vote): bool
{ {
$answer_num = GroupMember::where('group_id', $message['receiver_id'])->where('is_quit', 0)->count(); $answer_num = GroupMember::where('group_id', $message['receiver_id'])->where('is_quit', 0)->count();
@ -294,7 +293,7 @@ class TalkMessageService
* @param array $loginParams * @param array $loginParams
* @return bool * @return bool
*/ */
public function insertLoginMessage(array $message, array $loginParams): bool public function insertLogin(array $message, array $loginParams): bool
{ {
Db::beginTransaction(); Db::beginTransaction();
try { try {

View File

@ -14,7 +14,7 @@ class UserFriendService
* @param int $friend_id 好友ID * @param int $friend_id 好友ID
* @return string * @return string
*/ */
public function getFriendRemark(int $user_id, int $friend_id) public function getFriendRemark(int $user_id, int $friend_id): string
{ {
$remark = FriendRemark::getInstance()->read($user_id, $friend_id); $remark = FriendRemark::getInstance()->read($user_id, $friend_id);
if ($remark) return $remark; if ($remark) return $remark;
@ -33,7 +33,7 @@ class UserFriendService
* @param bool $is_mutual 相互互为好友 * @param bool $is_mutual 相互互为好友
* @return bool * @return bool
*/ */
public function isFriend(int $user_id, int $friend_id, $is_mutual = false) public function isFriend(int $user_id, int $friend_id, $is_mutual = false): bool
{ {
$isTrue1 = UsersFriend::where('user_id', $user_id)->where('friend_id', $friend_id)->where('status', 1)->exists(); $isTrue1 = UsersFriend::where('user_id', $user_id)->where('friend_id', $friend_id)->where('status', 1)->exists();

View File

@ -16,9 +16,9 @@ class UserService extends BaseService
* *
* @param int $user_id 用户ID * @param int $user_id 用户ID
* @param array $field 查询字段 * @param array $field 查询字段
* @return User * @return User|object|null
*/ */
public function findById(int $user_id, $field = ['*']) public function findById(int $user_id, $field = ['*']): ?User
{ {
return User::where('id', $user_id)->first($field); return User::where('id', $user_id)->first($field);
} }
@ -149,7 +149,7 @@ class UserService extends BaseService
* @param int $user_id 用户ID * @param int $user_id 用户ID
* @return array * @return array
*/ */
public function getUserFriends(int $user_id) public function getUserFriends(int $user_id): array
{ {
return UsersFriend::leftJoin('users', 'users.id', '=', 'users_friends.friend_id') return UsersFriend::leftJoin('users', 'users.id', '=', 'users_friends.friend_id')
->where('user_id', $user_id)->where('users_friends.status', 1) ->where('user_id', $user_id)->where('users_friends.status', 1)
@ -169,7 +169,7 @@ class UserService extends BaseService
* @param int $user_id 指定用户ID * @param int $user_id 指定用户ID
* @return array * @return array
*/ */
public function getFriendIds(int $user_id) public function getFriendIds(int $user_id): array
{ {
return UsersFriend::where('user_id', $user_id)->where('status', 1)->pluck('friend_id')->toArray(); return UsersFriend::where('user_id', $user_id)->where('status', 1)->pluck('friend_id')->toArray();
} }