初始化
parent
8ce33cada3
commit
84b9900f7d
|
@ -18,6 +18,7 @@
|
||||||
- JSON
|
- JSON
|
||||||
- PDO
|
- PDO
|
||||||
- Redis >= 5.0.0
|
- Redis >= 5.0.0
|
||||||
|
- AMQP
|
||||||
|
|
||||||
## 4、项目安装
|
## 4、项目安装
|
||||||
[接口文档](https://docs.apipost.cn/view/9c75130d7006e6e5#3184466)
|
[接口文档](https://docs.apipost.cn/view/9c75130d7006e6e5#3184466)
|
||||||
|
|
|
@ -103,7 +103,7 @@ class ArticleController extends CController
|
||||||
public function getArticleDetail()
|
public function getArticleDetail()
|
||||||
{
|
{
|
||||||
$this->validate($this->request->all(), [
|
$this->validate($this->request->all(), [
|
||||||
'article_id' => 'required|integer',
|
'article_id' => 'required|integer'
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return $this->response->success(
|
return $this->response->success(
|
||||||
|
@ -124,7 +124,7 @@ class ArticleController extends CController
|
||||||
$params = $this->request->all();
|
$params = $this->request->all();
|
||||||
$this->validate($params, [
|
$this->validate($params, [
|
||||||
'class_id' => 'required|integer',
|
'class_id' => 'required|integer',
|
||||||
'class_name' => 'required',
|
'class_name' => 'required'
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$class_id = $this->articleService->editArticleClass($this->uid(), $params['class_id'], $params['class_name']);
|
$class_id = $this->articleService->editArticleClass($this->uid(), $params['class_id'], $params['class_name']);
|
||||||
|
@ -260,7 +260,7 @@ class ArticleController extends CController
|
||||||
'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'], [
|
||||||
|
@ -309,6 +309,7 @@ class ArticleController extends CController
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$isTrue = $this->articleService->updateArticleStatus($this->uid(), (int)$params['article_id'], 1);
|
$isTrue = $this->articleService->updateArticleStatus($this->uid(), (int)$params['article_id'], 1);
|
||||||
|
|
||||||
return $isTrue
|
return $isTrue
|
||||||
? $this->response->success([], '笔记恢复成功...')
|
? $this->response->success([], '笔记恢复成功...')
|
||||||
: $this->response->fail('笔记恢复失败...');
|
: $this->response->fail('笔记恢复失败...');
|
||||||
|
@ -406,6 +407,7 @@ class ArticleController extends CController
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$isTrue = $this->articleService->updateArticleTag($this->uid(), (int)$params['article_id'], $params['tags']);
|
$isTrue = $this->articleService->updateArticleTag($this->uid(), (int)$params['article_id'], $params['tags']);
|
||||||
|
|
||||||
return $isTrue
|
return $isTrue
|
||||||
? $this->response->success([], 'success...')
|
? $this->response->success([], 'success...')
|
||||||
: $this->response->fail('编辑失败...');
|
: $this->response->fail('编辑失败...');
|
||||||
|
|
|
@ -7,7 +7,6 @@ use Hyperf\HttpServer\Annotation\Controller;
|
||||||
use Hyperf\HttpServer\Annotation\RequestMapping;
|
use Hyperf\HttpServer\Annotation\RequestMapping;
|
||||||
use Hyperf\HttpServer\Annotation\Middleware;
|
use Hyperf\HttpServer\Annotation\Middleware;
|
||||||
use App\Middleware\JWTAuthMiddleware;
|
use App\Middleware\JWTAuthMiddleware;
|
||||||
use Phper666\JWTAuth\JWT;
|
|
||||||
use App\Constants\ResponseCode;
|
use App\Constants\ResponseCode;
|
||||||
use App\Model\User;
|
use App\Model\User;
|
||||||
use App\Service\UserService;
|
use App\Service\UserService;
|
||||||
|
@ -26,12 +25,6 @@ class AuthController extends CController
|
||||||
*/
|
*/
|
||||||
private $userService;
|
private $userService;
|
||||||
|
|
||||||
/**
|
|
||||||
* @Inject
|
|
||||||
* @var JWT
|
|
||||||
*/
|
|
||||||
private $jwt;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Inject
|
* @Inject
|
||||||
* @var SmsCodeService
|
* @var SmsCodeService
|
||||||
|
@ -43,7 +36,6 @@ class AuthController extends CController
|
||||||
*
|
*
|
||||||
* @RequestMapping(path="login", methods="post")
|
* @RequestMapping(path="login", methods="post")
|
||||||
*
|
*
|
||||||
* @param JWT $jwt
|
|
||||||
* @return \Psr\Http\Message\ResponseInterface
|
* @return \Psr\Http\Message\ResponseInterface
|
||||||
* @throws \Psr\SimpleCache\InvalidArgumentException
|
* @throws \Psr\SimpleCache\InvalidArgumentException
|
||||||
*/
|
*/
|
||||||
|
@ -61,7 +53,7 @@ class AuthController extends CController
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!$userInfo) {
|
if (!$userInfo) {
|
||||||
return $this->response->fail('账号不存在或密码填写错误...', ResponseCode::FAIL);
|
return $this->response->fail('账号不存在或密码填写错误...');
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -85,7 +77,7 @@ class AuthController extends CController
|
||||||
'motto' => $userInfo['motto'],
|
'motto' => $userInfo['motto'],
|
||||||
'email' => $userInfo['email'],
|
'email' => $userInfo['email'],
|
||||||
]
|
]
|
||||||
], '登录成功...');
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -154,12 +146,12 @@ class AuthController extends CController
|
||||||
]);
|
]);
|
||||||
|
|
||||||
if (!$this->smsCodeService->check('forget_password', $params['mobile'], $params['sms_code'])) {
|
if (!$this->smsCodeService->check('forget_password', $params['mobile'], $params['sms_code'])) {
|
||||||
return $this->response->fail('验证码填写错误...', ResponseCode::FAIL);
|
return $this->response->fail('验证码填写错误');
|
||||||
}
|
}
|
||||||
|
|
||||||
$isTrue = $this->userService->resetPassword($params['mobile'], $params['password']);
|
$isTrue = $this->userService->resetPassword($params['mobile'], $params['password']);
|
||||||
if (!$isTrue) {
|
if (!$isTrue) {
|
||||||
return $this->response->fail('重置密码失败...', ResponseCode::FAIL);
|
return $this->response->fail('重置密码失败');
|
||||||
}
|
}
|
||||||
|
|
||||||
// 删除验证码缓存
|
// 删除验证码缓存
|
||||||
|
@ -217,6 +209,7 @@ class AuthController extends CController
|
||||||
[$isTrue, $result] = $this->smsCodeService->send($params['type'], $params['mobile']);
|
[$isTrue, $result] = $this->smsCodeService->send($params['type'], $params['mobile']);
|
||||||
if (!$isTrue) {
|
if (!$isTrue) {
|
||||||
// ... 处理发送失败逻辑,当前默认发送成功
|
// ... 处理发送失败逻辑,当前默认发送成功
|
||||||
|
return $this->response->fail('验证码发送失败');
|
||||||
}
|
}
|
||||||
|
|
||||||
// 测试环境下直接返回验证码
|
// 测试环境下直接返回验证码
|
||||||
|
|
|
@ -21,14 +21,21 @@ class CController extends AbstractController
|
||||||
*/
|
*/
|
||||||
protected $response;
|
protected $response;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Inject
|
||||||
|
* @var JWT
|
||||||
|
*/
|
||||||
|
protected $jwt;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取当前登录用户ID
|
* 获取当前登录用户ID
|
||||||
*
|
*
|
||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
public function uid(){
|
public function uid()
|
||||||
$token = request()->getQueryParams()['token']??null;
|
{
|
||||||
$data = container()->get(JWT::class)->getParserData($token);
|
$token = request()->getQueryParams()['token'] ?? null;
|
||||||
|
$data = $this->jwt->getParserData($token);
|
||||||
return $data['user_id'];
|
return $data['user_id'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,7 +37,7 @@ class DownloadController extends CController
|
||||||
{
|
{
|
||||||
$params = $this->request->inputs(['cr_id']);
|
$params = $this->request->inputs(['cr_id']);
|
||||||
$this->validate($params, [
|
$this->validate($params, [
|
||||||
'cr_id' => 'required|integer',
|
'cr_id' => 'required|integer'
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$recordsInfo = ChatRecord::select(['msg_type', 'source', 'user_id', 'receive_id'])->where('id', $params['cr_id'])->first();
|
$recordsInfo = ChatRecord::select(['msg_type', 'source', 'user_id', 'receive_id'])->where('id', $params['cr_id'])->first();
|
||||||
|
@ -81,7 +81,7 @@ class DownloadController extends CController
|
||||||
{
|
{
|
||||||
$params = $this->request->inputs(['annex_id']);
|
$params = $this->request->inputs(['annex_id']);
|
||||||
$this->validate($params, [
|
$this->validate($params, [
|
||||||
'annex_id' => 'required|integer',
|
'annex_id' => 'required|integer'
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$info = ArticleAnnex::select(['save_dir', 'original_name'])
|
$info = ArticleAnnex::select(['save_dir', 'original_name'])
|
||||||
|
|
|
@ -11,6 +11,7 @@ use App\Constants\ResponseCode;
|
||||||
use App\Model\Emoticon;
|
use App\Model\Emoticon;
|
||||||
use App\Model\EmoticonDetail;
|
use App\Model\EmoticonDetail;
|
||||||
use App\Service\EmoticonService;
|
use App\Service\EmoticonService;
|
||||||
|
use App\Service\UploadService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class EmoticonController
|
* Class EmoticonController
|
||||||
|
@ -26,7 +27,7 @@ class EmoticonController extends CController
|
||||||
* @Inject
|
* @Inject
|
||||||
* @var EmoticonService
|
* @var EmoticonService
|
||||||
*/
|
*/
|
||||||
public $emoticonService;
|
private $emoticonService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取用户表情包列表
|
* 获取用户表情包列表
|
||||||
|
@ -91,7 +92,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();
|
||||||
|
@ -131,8 +132,11 @@ class EmoticonController extends CController
|
||||||
* 自定义上传表情包
|
* 自定义上传表情包
|
||||||
*
|
*
|
||||||
* @RequestMapping(path="upload-emoticon", methods="post")
|
* @RequestMapping(path="upload-emoticon", methods="post")
|
||||||
|
*
|
||||||
|
* @param UploadService $uploadService
|
||||||
|
* @return \Psr\Http\Message\ResponseInterface
|
||||||
*/
|
*/
|
||||||
public function uploadEmoticon()
|
public function uploadEmoticon(UploadService $uploadService)
|
||||||
{
|
{
|
||||||
$file = $this->request->file('emoticon');
|
$file = $this->request->file('emoticon');
|
||||||
if (!$file->isValid()) {
|
if (!$file->isValid()) {
|
||||||
|
@ -150,14 +154,16 @@ class EmoticonController extends CController
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
$save_path = '';
|
// 读取图片信息
|
||||||
|
|
||||||
$user_id = $this->uid();
|
|
||||||
$imgInfo = getimagesize($file->getPath());
|
$imgInfo = getimagesize($file->getPath());
|
||||||
$filename = create_image_name($ext, $imgInfo[0], $imgInfo[1]);
|
|
||||||
|
$save_path = $uploadService->media($file, 'media/images/emoticon', create_image_name($ext, $imgInfo[0], $imgInfo[1]));
|
||||||
|
if (!$save_path) {
|
||||||
|
return $this->response->fail('图片上传失败');
|
||||||
|
}
|
||||||
|
|
||||||
$result = EmoticonDetail::create([
|
$result = EmoticonDetail::create([
|
||||||
'user_id' => $user_id,
|
'user_id' => $this->uid(),
|
||||||
'url' => $save_path,
|
'url' => $save_path,
|
||||||
'file_suffix' => $ext,
|
'file_suffix' => $ext,
|
||||||
'file_size' => $file->getSize(),
|
'file_size' => $file->getSize(),
|
||||||
|
@ -181,7 +187,7 @@ class EmoticonController extends CController
|
||||||
*/
|
*/
|
||||||
public function collectEmoticon()
|
public function collectEmoticon()
|
||||||
{
|
{
|
||||||
$params = $this->request->all();
|
$params = $this->request->inputs(['record_id']);
|
||||||
$this->validate($params, [
|
$this->validate($params, [
|
||||||
'record_id' => 'required|integer'
|
'record_id' => 'required|integer'
|
||||||
]);
|
]);
|
||||||
|
@ -204,15 +210,13 @@ class EmoticonController extends CController
|
||||||
*/
|
*/
|
||||||
public function delCollectEmoticon()
|
public function delCollectEmoticon()
|
||||||
{
|
{
|
||||||
$params = $this->request->all();
|
$params = $this->request->inputs(['ids']);
|
||||||
$this->validate($params, [
|
$this->validate($params, [
|
||||||
'ids' => 'required'
|
'ids' => 'required|ids'
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$ids = explode(',', trim($params['ids']));
|
return $this->emoticonService->deleteCollect($this->uid(), parse_ids($params['ids'])) ?
|
||||||
|
$this->response->success([]) :
|
||||||
return $this->emoticonService->deleteCollect($this->uid(), $ids) ?
|
$this->response->fail();
|
||||||
$this->response->success([], 'success') :
|
|
||||||
$this->response->fail('fail');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,7 +31,7 @@ class GroupController extends CController
|
||||||
* @Inject
|
* @Inject
|
||||||
* @var GroupService
|
* @var GroupService
|
||||||
*/
|
*/
|
||||||
public $groupService;
|
private $groupService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Inject
|
* @Inject
|
||||||
|
@ -57,11 +57,10 @@ class GroupController extends CController
|
||||||
$params = $this->request->inputs(['group_name', 'uids']);
|
$params = $this->request->inputs(['group_name', 'uids']);
|
||||||
$this->validate($params, [
|
$this->validate($params, [
|
||||||
'group_name' => 'required',
|
'group_name' => 'required',
|
||||||
'uids' => 'required',
|
'uids' => 'required|ids'
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$friend_ids = array_filter(explode(',', $params['uids']));
|
$friend_ids = parse_ids($params['uids']);
|
||||||
$friend_ids = array_unique($friend_ids);
|
|
||||||
|
|
||||||
$user_id = $this->uid();
|
$user_id = $this->uid();
|
||||||
[$isTrue, $data] = $this->groupService->create($user_id, [
|
[$isTrue, $data] = $this->groupService->create($user_id, [
|
||||||
|
@ -92,7 +91,7 @@ class GroupController extends CController
|
||||||
|
|
||||||
return $this->response->success([
|
return $this->response->success([
|
||||||
'group_id' => $data['group_id']
|
'group_id' => $data['group_id']
|
||||||
], '群聊创建成功...');
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -104,7 +103,7 @@ class GroupController extends CController
|
||||||
{
|
{
|
||||||
$params = $this->request->inputs(['group_id']);
|
$params = $this->request->inputs(['group_id']);
|
||||||
$this->validate($params, [
|
$this->validate($params, [
|
||||||
'group_id' => 'required|integer',
|
'group_id' => 'required|integer'
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$isTrue = $this->groupService->dismiss($params['group_id'], $this->uid());
|
$isTrue = $this->groupService->dismiss($params['group_id'], $this->uid());
|
||||||
|
@ -129,11 +128,10 @@ class GroupController extends CController
|
||||||
$params = $this->request->inputs(['group_id', 'uids']);
|
$params = $this->request->inputs(['group_id', 'uids']);
|
||||||
$this->validate($params, [
|
$this->validate($params, [
|
||||||
'group_id' => 'required|integer',
|
'group_id' => 'required|integer',
|
||||||
'uids' => 'required',
|
'uids' => 'required|ids'
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$uids = array_filter(explode(',', $params['uids']));
|
$uids = parse_ids($params['uids']);
|
||||||
$uids = array_unique($uids);
|
|
||||||
|
|
||||||
$user_id = $this->uid();
|
$user_id = $this->uid();
|
||||||
[$isTrue, $record_id] = $this->groupService->invite($user_id, $params['group_id'], $uids);
|
[$isTrue, $record_id] = $this->groupService->invite($user_id, $params['group_id'], $uids);
|
||||||
|
@ -205,7 +203,7 @@ class GroupController extends CController
|
||||||
'group_id' => 'required|integer',
|
'group_id' => 'required|integer',
|
||||||
'group_name' => 'required',
|
'group_name' => 'required',
|
||||||
'group_profile' => 'required',
|
'group_profile' => 'required',
|
||||||
'avatar' => 'required',
|
'avatar' => 'required'
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$result = UsersGroup::where('id', $params['group_id'])->where('user_id', $this->uid())->update([
|
$result = UsersGroup::where('id', $params['group_id'])->where('user_id', $this->uid())->update([
|
||||||
|
@ -421,7 +419,7 @@ class GroupController extends CController
|
||||||
'group_id' => 'required|integer',
|
'group_id' => 'required|integer',
|
||||||
'notice_id' => 'required|integer',
|
'notice_id' => 'required|integer',
|
||||||
'title' => 'required',
|
'title' => 'required',
|
||||||
'content' => 'required',
|
'content' => 'required'
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$user_id = $this->uid();
|
$user_id = $this->uid();
|
||||||
|
|
|
@ -287,9 +287,9 @@ class TalkController extends CController
|
||||||
//转发方方式[1:逐条转发;2:合并转发]
|
//转发方方式[1:逐条转发;2:合并转发]
|
||||||
'forward_mode' => 'required|in:1,2',
|
'forward_mode' => 'required|in:1,2',
|
||||||
//转发的好友的ID
|
//转发的好友的ID
|
||||||
// 'receive_user_ids' => 'array',
|
//'receive_user_ids' => 'array',
|
||||||
//转发的群聊ID
|
//转发的群聊ID
|
||||||
// 'receive_group_ids' => 'array',
|
//'receive_group_ids' => 'array',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$user_id = $this->uid();
|
$user_id = $this->uid();
|
||||||
|
|
|
@ -39,7 +39,6 @@ class UploadController extends CController
|
||||||
* 图片文件流上传接口
|
* 图片文件流上传接口
|
||||||
*
|
*
|
||||||
* @RequestMapping(path="file-stream", methods="post")
|
* @RequestMapping(path="file-stream", methods="post")
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public function fileStream()
|
public function fileStream()
|
||||||
{
|
{
|
||||||
|
@ -56,7 +55,6 @@ class UploadController extends CController
|
||||||
* 获取拆分文件信息
|
* 获取拆分文件信息
|
||||||
*
|
*
|
||||||
* @RequestMapping(path="get-file-split-info", methods="get")
|
* @RequestMapping(path="get-file-split-info", methods="get")
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public function getFileSplitInfo()
|
public function getFileSplitInfo()
|
||||||
{
|
{
|
||||||
|
@ -72,6 +70,7 @@ class UploadController extends CController
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* 文件拆分上传接口
|
||||||
*
|
*
|
||||||
* @RequestMapping(path="file-subarea-upload", methods="post")
|
* @RequestMapping(path="file-subarea-upload", methods="post")
|
||||||
*
|
*
|
||||||
|
|
|
@ -35,13 +35,13 @@ class UsersController extends CController
|
||||||
* @Inject
|
* @Inject
|
||||||
* @var FriendService
|
* @var FriendService
|
||||||
*/
|
*/
|
||||||
protected $friendService;
|
private $friendService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Inject
|
* @Inject
|
||||||
* @var UserService
|
* @var UserService
|
||||||
*/
|
*/
|
||||||
protected $userService;
|
private $userService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @inject
|
* @inject
|
||||||
|
@ -140,7 +140,7 @@ class UsersController extends CController
|
||||||
'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' => '',
|
||||||
|
@ -187,6 +187,7 @@ class UsersController extends CController
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$isTrue = User::where('id', $this->uid())->update(['avatar' => $params['avatar']]);
|
$isTrue = User::where('id', $this->uid())->update(['avatar' => $params['avatar']]);
|
||||||
|
|
||||||
return $isTrue
|
return $isTrue
|
||||||
? $this->response->success([], '头像修改成功...')
|
? $this->response->success([], '头像修改成功...')
|
||||||
: $this->response->fail('头像修改失败...');
|
: $this->response->fail('头像修改失败...');
|
||||||
|
@ -228,10 +229,11 @@ class UsersController 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' => "required",
|
'remarks' => "required"
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$isTrue = $this->friendService->editFriendRemark($this->uid(), $params['friend_id'], $params['remarks']);
|
$isTrue = $this->friendService->editFriendRemark($this->uid(), $params['friend_id'], $params['remarks']);
|
||||||
|
|
||||||
return $isTrue
|
return $isTrue
|
||||||
? $this->response->success([], '备注修改成功...')
|
? $this->response->success([], '备注修改成功...')
|
||||||
: $this->response->fail('备注修改失败...');
|
: $this->response->fail('备注修改失败...');
|
||||||
|
@ -247,7 +249,7 @@ class UsersController 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',
|
'remarks' => 'present'
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$user = $this->userService->findById($params['friend_id']);
|
$user = $this->userService->findById($params['friend_id']);
|
||||||
|
@ -276,7 +278,6 @@ class UsersController extends CController
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return $this->response->success([], '发送好友申请成功...');
|
return $this->response->success([], '发送好友申请成功...');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -290,7 +291,7 @@ class UsersController 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',
|
'remarks' => 'present'
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$isTrue = $this->friendService->handleFriendApply($this->uid(), (int)$params['apply_id'], $params['remarks']);
|
$isTrue = $this->friendService->handleFriendApply($this->uid(), (int)$params['apply_id'], $params['remarks']);
|
||||||
|
@ -323,7 +324,7 @@ class UsersController extends CController
|
||||||
{
|
{
|
||||||
$params = $this->request->inputs(['apply_id']);
|
$params = $this->request->inputs(['apply_id']);
|
||||||
$this->validate($params, [
|
$this->validate($params, [
|
||||||
'apply_id' => 'required|integer',
|
'apply_id' => 'required|integer'
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$isTrue = $this->friendService->delFriendApply($this->uid(), (int)$params['apply_id']);
|
$isTrue = $this->friendService->delFriendApply($this->uid(), (int)$params['apply_id']);
|
||||||
|
@ -342,7 +343,7 @@ class UsersController 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);
|
||||||
|
@ -376,7 +377,7 @@ class UsersController extends CController
|
||||||
$params = $this->request->inputs(['old_password', 'new_password']);
|
$params = $this->request->inputs(['old_password', 'new_password']);
|
||||||
$this->validate($params, [
|
$this->validate($params, [
|
||||||
'old_password' => 'required',
|
'old_password' => 'required',
|
||||||
'new_password' => 'required',
|
'new_password' => 'required'
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$userInfo = $this->userService->findById($this->uid(), ['id', 'password', 'mobile']);
|
$userInfo = $this->userService->findById($this->uid(), ['id', 'password', 'mobile']);
|
||||||
|
@ -406,7 +407,7 @@ class UsersController extends CController
|
||||||
$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'
|
||||||
]);
|
]);
|
||||||
|
|
||||||
if (!$smsCodeService->check('change_mobile', $params['mobile'], $params['sms_code'])) {
|
if (!$smsCodeService->check('change_mobile', $params['mobile'], $params['sms_code'])) {
|
||||||
|
@ -425,6 +426,7 @@ class UsersController extends CController
|
||||||
|
|
||||||
// 清除缓存信息
|
// 清除缓存信息
|
||||||
$smsCodeService->delCode('change_mobile', $params['mobile']);
|
$smsCodeService->delCode('change_mobile', $params['mobile']);
|
||||||
|
|
||||||
return $this->response->success([], '手机号更换成功...');
|
return $this->response->success([], '手机号更换成功...');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -439,7 +441,7 @@ class UsersController extends CController
|
||||||
$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'
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$sendEmailCode = new SendEmailCode();
|
$sendEmailCode = new SendEmailCode();
|
||||||
|
@ -459,6 +461,7 @@ class UsersController extends CController
|
||||||
}
|
}
|
||||||
|
|
||||||
$sendEmailCode->delCode(SendEmailCode::CHANGE_EMAIL, $params['email']);
|
$sendEmailCode->delCode(SendEmailCode::CHANGE_EMAIL, $params['email']);
|
||||||
|
|
||||||
return $this->response->success([], '邮箱设置成功...');
|
return $this->response->success([], '邮箱设置成功...');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -474,7 +477,7 @@ class UsersController extends CController
|
||||||
{
|
{
|
||||||
$params = $this->request->inputs(['mobile']);
|
$params = $this->request->inputs(['mobile']);
|
||||||
$this->validate($params, [
|
$this->validate($params, [
|
||||||
'mobile' => "present|regex:/^1[345789][0-9]{9}$/",
|
'mobile' => "present|regex:/^1[345789][0-9]{9}$/"
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$user_id = $this->uid();
|
$user_id = $this->uid();
|
||||||
|
@ -488,12 +491,14 @@ class UsersController extends CController
|
||||||
|
|
||||||
$data = ['is_debug' => true];
|
$data = ['is_debug' => true];
|
||||||
[$isTrue, $result] = $smsCodeService->send('change_mobile', $params['mobile']);
|
[$isTrue, $result] = $smsCodeService->send('change_mobile', $params['mobile']);
|
||||||
if ($isTrue) {
|
if (!$isTrue) {
|
||||||
$data['sms_code'] = $result['data']['code'];
|
|
||||||
} else {
|
|
||||||
// ... 处理发送失败逻辑,当前默认发送成功
|
// ... 处理发送失败逻辑,当前默认发送成功
|
||||||
|
return $this->response->fail('验证码发送失败');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 测试环境下直接返回验证码
|
||||||
|
$data['sms_code'] = $result['data']['code'];
|
||||||
|
|
||||||
return $this->response->success($data, '验证码发送成功...');
|
return $this->response->success($data, '验证码发送成功...');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -509,7 +514,7 @@ class UsersController extends CController
|
||||||
{
|
{
|
||||||
$params = $this->request->inputs(['email']);
|
$params = $this->request->inputs(['email']);
|
||||||
$this->validate($params, [
|
$this->validate($params, [
|
||||||
'email' => "required|email",
|
'email' => "required|email"
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$isTrue = $sendEmailCode->send(SendEmailCode::CHANGE_EMAIL, '绑定邮箱', $params['email']);
|
$isTrue = $sendEmailCode->send(SendEmailCode::CHANGE_EMAIL, '绑定邮箱', $params['email']);
|
||||||
|
|
|
@ -0,0 +1,38 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Listener;
|
||||||
|
|
||||||
|
use Hyperf\Event\Contract\ListenerInterface;
|
||||||
|
use Hyperf\Validation\Contract\ValidatorFactoryInterface;
|
||||||
|
use Hyperf\Validation\Event\ValidatorFactoryResolved;
|
||||||
|
use Hyperf\Event\Annotation\Listener;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Listener
|
||||||
|
*/
|
||||||
|
class ValidatorFactoryResolvedListener implements ListenerInterface
|
||||||
|
{
|
||||||
|
|
||||||
|
public function listen(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
ValidatorFactoryResolved::class,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function process(object $event)
|
||||||
|
{
|
||||||
|
/** @var ValidatorFactoryInterface $validatorFactory */
|
||||||
|
$validatorFactory = $event->validatorFactory;
|
||||||
|
|
||||||
|
// 注册了 ids 验证器(验证英文逗号拼接的整形数字字符串 例如:[1,2,3,4,5])
|
||||||
|
$validatorFactory->extend('ids', function ($attribute, $value, $parameters, $validator) {
|
||||||
|
$arr = explode(',', $value);
|
||||||
|
foreach ($arr as $id) {
|
||||||
|
if (!check_int($id)) return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
|
@ -46,7 +46,7 @@ class Response
|
||||||
*
|
*
|
||||||
* @return PsrResponseInterface
|
* @return PsrResponseInterface
|
||||||
*/
|
*/
|
||||||
public function fail($message = 'FAIL', $data = [], $code = ResponseCode::FAIL)
|
public function fail($message = 'fail', $data = [], $code = ResponseCode::FAIL)
|
||||||
{
|
{
|
||||||
return $this->response->json(compact('code', 'message', 'data'));
|
return $this->response->json(compact('code', 'message', 'data'));
|
||||||
}
|
}
|
||||||
|
|
|
@ -198,3 +198,22 @@ function arraysSort(array $array, $field, $sort = SORT_DESC)
|
||||||
array_multisort(array_column($array, $field), $sort, $array);
|
array_multisort(array_column($array, $field), $sort, $array);
|
||||||
return $array;
|
return $array;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断0或正整数
|
||||||
|
*
|
||||||
|
* @param string $int 验证字符串
|
||||||
|
* @param bool $isZero 判断是否可为0
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
function check_int($int, $isZero = false)
|
||||||
|
{
|
||||||
|
$reg = $isZero ? '/^[+]{0,1}(\d+)$/' : '/^[1-9]\d*$/';
|
||||||
|
return is_numeric($int) && preg_match($reg, $int);
|
||||||
|
}
|
||||||
|
|
||||||
|
function parse_ids($ids)
|
||||||
|
{
|
||||||
|
return array_unique(explode(',', trim($ids)));
|
||||||
|
}
|
||||||
|
|
|
@ -174,4 +174,6 @@ return [
|
||||||
|
|
||||||
'chinese_word' => 'The :attribute must contain valid characters(chinese/english character, number, underscore)',
|
'chinese_word' => 'The :attribute must contain valid characters(chinese/english character, number, underscore)',
|
||||||
'sequential_array' => 'The :attribute must be sequential array',
|
'sequential_array' => 'The :attribute must be sequential array',
|
||||||
|
|
||||||
|
'ids' => ' :attribute 字段 ids 格式不正确',
|
||||||
];
|
];
|
||||||
|
|
|
@ -174,4 +174,6 @@ return [
|
||||||
|
|
||||||
'chinese_word' => ':attribute 必须包含以下有效字符 (中文/英文,数字, 下划线)',
|
'chinese_word' => ':attribute 必须包含以下有效字符 (中文/英文,数字, 下划线)',
|
||||||
'sequential_array' => ':attribute 必须是一个有序数组',
|
'sequential_array' => ':attribute 必须是一个有序数组',
|
||||||
|
|
||||||
|
'ids' => ' :attribute 字段 ids 格式不正确',
|
||||||
];
|
];
|
||||||
|
|
Loading…
Reference in New Issue