Login.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. /**
  3. * Created by PhpStorm
  4. * User:林志杰
  5. * Email:[email protected]
  6. * Motto:纵有疾风起,人生不言弃!
  7. * Time:2020/2/8 1:10
  8. */
  9. declare(strict_types=1);
  10. namespace app\api\controller;
  11. use app\api\validate\User as UserValidate;
  12. use app\BaseController;
  13. use app\common\business\User as UserBusiness;
  14. class Login extends BaseController
  15. {
  16. public function index(): object
  17. {
  18. $phoneNumber = $this->request->param("phone_number", '', 'trim');
  19. $code = input('param.code', 0, 'intval');
  20. $type = input('param.type', 0, 'intval');
  21. // 参数校验
  22. $data = [
  23. 'phoneNumber' => $phoneNumber,
  24. 'code' => $code,
  25. 'type' => $type,
  26. ];
  27. $validate = new UserValidate();
  28. if (!$validate->scene('login')->check($data)) {
  29. return show(config('status.error'), $validate->getError());
  30. }
  31. $result = (new UserBusiness())->login($data);
  32. if ($result) {
  33. return show(config('status.success'), "登陆成功");
  34. }
  35. return show(config('status.error'), "登录失败");
  36. }
  37. }