Index.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <?php
  2. namespace app\controller;
  3. use app\BaseController;
  4. use app\model\Ry;
  5. use app\model\ZdCpmc;
  6. use app\service\NszyService;
  7. use app\service\QyBasicService;
  8. use app\service\RyService;
  9. use app\service\ZdCpmcService;
  10. use app\validate\UserLogin;
  11. use think\db\exception\DataNotFoundException;
  12. use think\db\exception\DbException;
  13. use think\db\exception\ModelNotFoundException;
  14. use think\exception\ValidateException;
  15. use think\response\Json;
  16. use think\annotation\Route;
  17. use think\annotation\route\Middleware;
  18. use hg\apidoc\annotation as Apidoc;
  19. use thans\jwt\facade\JWTAuth;
  20. class Index extends BaseController
  21. {
  22. protected $middleware = [
  23. 'jwt' => ['except' => ['login'] ],
  24. ];
  25. use ResponseJson;
  26. /**
  27. * @Apidoc\Title("基础的接口演示")
  28. * @Apidoc\Tag("基础,示例")
  29. * @Apidoc\Method ("GET")
  30. * @Route("/")
  31. * @Middleware({})
  32. */
  33. public function index()
  34. {
  35. return $this->JsonSucess(["info"=>"这是后端接口"]);
  36. }
  37. public function hello($name = 'ThinkPHP6')
  38. {
  39. return 'hello,' . $name;
  40. }
  41. /**
  42. * @Apidoc\Title("登录接口")
  43. * @Apidoc\Tag("用户登录")
  44. * @Apidoc\Method ("GET")
  45. * @throws ModelNotFoundException
  46. * @throws DataNotFoundException
  47. * @throws DbException
  48. * @Route("login")
  49. * @Middleware({})
  50. */
  51. public function login():Json{
  52. $loginInfo = $this->request->get();
  53. try {
  54. validate(UserLogin::class)->check($loginInfo);
  55. }catch (ValidateException $e){
  56. return $this->JsonError($e->getError(),0);
  57. }
  58. $userInfo=RyService::selectLoginInfo($loginInfo);
  59. if ($userInfo){
  60. $token = JWTAuth::builder(['qydm' => $userInfo["qydm"]]);//参数为用户认证的信息,请自行添加
  61. return $this->JsonSucess(["token"=>$token,"userInfo"=>$userInfo],1001);
  62. }else{
  63. return $this->JsonError(1002);
  64. }
  65. }
  66. /**
  67. * @throws ModelNotFoundException
  68. * @throws DataNotFoundException
  69. * @throws DbException
  70. * @Route("/getQyBasicList")
  71. * @Middleware({"jwt"})
  72. */
  73. public function getQyBasicList(): Json
  74. {
  75. getQydm();
  76. return $this->JsonSucess(QyBasicService::selectQyBasic());
  77. }
  78. /**
  79. * @throws ModelNotFoundException
  80. * @throws DataNotFoundException
  81. * @throws DbException
  82. * @Route("getNszyByQydm")
  83. * @Middleware({"jwt"})
  84. */
  85. public function getNszyByQydm():Json{
  86. return $this->JsonSucess(NszyService::selectNszyByQydm(getQydm()));
  87. }
  88. /**
  89. * @throws ModelNotFoundException
  90. * @throws DataNotFoundException
  91. * @throws DbException
  92. * @Route("getJiangdou")
  93. *
  94. */
  95. public function getJiangdou(){
  96. return json(ZdCpmcService::getQydmBycpmc());
  97. }
  98. }