123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- <?php
- /**
- * Created by PhpStorm
- * User:林志杰
- * Email:[email protected]
- * Motto:纵有疾风起,人生不言弃!
- * Time:2020/2/8 1:10
- */
- declare(strict_types=1);
- namespace app\api\controller;
- use app\api\validate\User as UserValidate;
- use app\BaseController;
- use app\common\business\User as UserBusiness;
- class Login extends BaseController
- {
- public function index(): object
- {
- if (!$this->request->param('phone_number', '', 'trim')) {
- return show(config('status.error'), '非法请求');
- }
- $phoneNumber = $this->request->param("phone_number", '', 'trim');
- $code = input('param.code', 0, 'intval');
- $type = input('param.type', 0, 'intval');
- // 参数校验
- $data = [
- 'phoneNumber' => $phoneNumber,
- 'code' => $code,
- 'type' => $type,
- ];
- $validate = new UserValidate();
- if (!$validate->scene('login')->check($data)) {
- return show(config('status.error'), $validate->getError());
- }
- try {
- $result = (new UserBusiness())->login($data);
- } catch (\Exception $e) {
- return show($e->getCode(), $e->getMessage());
- }
- if ($result) {
- return show(config('status.success'), "登陆成功", $result);
- }
- return show(config('status.error'), "登录失败");
- }
- }
|