fix: 修复参数接收强制转换

This commit is contained in:
Ying
2023-06-25 16:56:18 +08:00
parent b4b73ac2aa
commit 34dd0a2086
3 changed files with 22 additions and 18 deletions

View File

@@ -43,8 +43,8 @@ class Dictionary extends AdminController
{ {
$post = input(); $post = input();
$pid = input('pid'); $pid = input('pid');
$limit = input('limit/d') ?? 10; $limit = input('limit') ?? 10;
$page = input('page/d') ?? 1; $page = input('page') ?? 1;
if ($pid == null) { if ($pid == null) {
$pid = (string)$this->model->minId(); $pid = (string)$this->model->minId();
} }

View File

@@ -163,8 +163,8 @@ class User extends ApiController
*/ */
public function message(Request $request): Response public function message(Request $request): Response
{ {
$page = input('page/d', 1); $page = input('page', 1);
$limit = input('limit/d', 1); $limit = input('limit', 1);
$status = input('status', 'all'); $status = input('status', 'all');
$where[] = ['user_id', '=', $request->userId]; $where[] = ['user_id', '=', $request->userId];
if ($status !== 'all') { if ($status !== 'all') {
@@ -185,7 +185,7 @@ class User extends ApiController
*/ */
public function viewMessage(Request $request): Response public function viewMessage(Request $request): Response
{ {
$id = input('id/d', 0); $id = input('id', 0);
$result = UserService::viewMessage($id, $request->userId); $result = UserService::viewMessage($id, $request->userId);
return $this->success('查询成功', "/", $result); return $this->success('查询成功', "/", $result);
} }

View File

@@ -12,6 +12,7 @@ declare (strict_types=1);
namespace app\index\controller; namespace app\index\controller;
use app\common\exception\OperateException;
use app\common\library\ResultCode; use app\common\library\ResultCode;
use app\common\service\user\UserService; use app\common\service\user\UserService;
use app\common\service\user\UserTokenService; use app\common\service\user\UserTokenService;
@@ -92,8 +93,9 @@ class Third extends HomeController
* @return Response * @return Response
* @throws DataNotFoundException * @throws DataNotFoundException
* @throws DbException * @throws DbException
* @throws ModelNotFoundException
* @throws InvalidArgumentException * @throws InvalidArgumentException
* @throws ModelNotFoundException
* @throws OperateException
*/ */
public function callback() public function callback()
{ {
@@ -102,24 +104,29 @@ class Third extends HomeController
} catch (\Exception $e) { } catch (\Exception $e) {
return $this->error($e->getMessage()); return $this->error($e->getMessage());
} }
$user = $this->oauth->getUserInfo(); $user = $this->oauth->getUserInfo();
if (!empty($user) && !UserTokenService::isLogin()) { if (!empty($user) && !UserTokenService::isLogin()) {
return $this->register($user, $this->type); return $this->register($user, $this->type);
} else if (UserTokenService::isLogin()) { // 绑定用户 } else if (UserTokenService::isLogin()) { // 绑定用户
return $this->doBind($user, $this->type); return $this->doBind($user, $this->type);
} }
return $this->error('登录失败');
} }
/** /**
* 用户注册操作 * 用户注册操作
* @param array $info * @param array $info
* @param string|null $type * @param string $type
* @return Response * @return Response
* @throws DataNotFoundException * @throws DataNotFoundException
* @throws DbException * @throws DbException
* @throws InvalidArgumentException
* @throws ModelNotFoundException * @throws ModelNotFoundException
* @throws OperateException
*/ */
protected function register(array $info = [], string $type = null) protected function register(array $info, string $type): Response
{ {
$openid = $info['openid'] ?? $info['id']; $openid = $info['openid'] ?? $info['id'];
$nickname = $info['userData']['name'] ?? $info['userData']['nickname']; $nickname = $info['userData']['name'] ?? $info['userData']['nickname'];
@@ -204,17 +211,14 @@ class Third extends HomeController
} }
$result = UserTokenService::isLogin(); $result = UserTokenService::isLogin();
if (!empty($result)) { if (empty($result['email']) || empty($result['pwd'])) {
return $this->error('解除绑定需要设置邮箱和密码!');
}
if (empty($result['email']) || empty($result['pwd'])) { $where['type'] = $this->type;
return $this->error('解除绑定需要设置邮箱和密码!'); $where['user_id'] = request()->userId;
} if (UserThird::where($where)->delete()) {
return $this->success('解除绑定成功!');
$where['type'] = $this->type;
$where['user_id'] = request()->userId;
if (UserThird::where($where)->delete()) {
return $this->success('解除绑定成功!');
}
} }
return $this->error(); return $this->error();