|
@@ -0,0 +1,282 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace app\controller;
|
|
|
+
|
|
|
+use app\BaseController;
|
|
|
+use app\service\EnterprisesService;
|
|
|
+use app\service\UserService;
|
|
|
+use app\validate\Id;
|
|
|
+use app\validate\Page;
|
|
|
+use app\validate\Qydm;
|
|
|
+use app\validate\EnterprisesLogin;
|
|
|
+use app\validate\UserLogin;
|
|
|
+use thans\jwt\facade\JWTAuth;
|
|
|
+use think\db\exception\DataNotFoundException;
|
|
|
+use think\db\exception\DbException;
|
|
|
+use think\db\exception\ModelNotFoundException;
|
|
|
+use think\exception\ValidateException;
|
|
|
+use think\response\Json;
|
|
|
+use think\annotation\Route;
|
|
|
+use think\annotation\route\Middleware;
|
|
|
+use hg\apidoc\annotation as Apidoc;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @Apidoc\Title("企业信息")
|
|
|
+ * @Apidoc\Group("企业")
|
|
|
+ * @Apidoc\Sort (3)
|
|
|
+ */
|
|
|
+class Enterprises extends BaseController
|
|
|
+{
|
|
|
+ protected $middleware = [
|
|
|
+ 'jwt',
|
|
|
+ ];
|
|
|
+ use ResponseJson;
|
|
|
+ /**
|
|
|
+ * @Apidoc\Title("企业列表")
|
|
|
+ * @Apidoc\Tag("企业")
|
|
|
+ * @Apidoc\Method ("GET")
|
|
|
+ * @Apidoc\Author ("ihavoc")
|
|
|
+ * @Route("getEnterPrisesList",method="GET")
|
|
|
+ * @Middleware({"jwt"})
|
|
|
+ */
|
|
|
+ public function getEnterPrisesList(): Json
|
|
|
+ {
|
|
|
+ $page = $this->request->get();
|
|
|
+ try {
|
|
|
+ validate(Page::class)->check($page);
|
|
|
+ }catch (ValidateException $e){
|
|
|
+ $page["page"]=1;
|
|
|
+ $page["size"] = 15;
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ return $this->JsonSucess(EnterprisesService::getEnterPrisesList($page, getXzqdmSub()));
|
|
|
+ } catch (DataNotFoundException $dbE) {
|
|
|
+ return $this->JsonError($dbE);
|
|
|
+ } catch (ModelNotFoundException $dbE) {
|
|
|
+ return $this->JsonError($dbE);
|
|
|
+ } catch (DbException $dbE) {
|
|
|
+ return $this->JsonError($dbE);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * @Apidoc\Title("企业信息by ID")
|
|
|
+ * @Apidoc\Tag("企业")
|
|
|
+ * @Apidoc\Method ("GET")
|
|
|
+ * @Apidoc\Author ("ihavoc")
|
|
|
+ * @Route("getEnterPrisesInfo",method="GET")
|
|
|
+ * @Middleware({"jwt"})
|
|
|
+ */
|
|
|
+ public function getEnterPrisesInfo(): Json
|
|
|
+ {
|
|
|
+ $id= $this->request->get();
|
|
|
+ try {
|
|
|
+ validate(Id::class)->check($id);
|
|
|
+ }catch (ValidateException $e){
|
|
|
+ $this->JsonError($e->getError());
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ return $this->JsonSucess(EnterprisesService::getEnterprisesInfoById($id["id"]));
|
|
|
+ } catch (DataNotFoundException $dbE) {
|
|
|
+ return $this->JsonError($dbE);
|
|
|
+ } catch (ModelNotFoundException $dbE) {
|
|
|
+ return $this->JsonError($dbE);
|
|
|
+ } catch (DbException $dbE) {
|
|
|
+ return $this->JsonError($dbE);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * @Apidoc\Title("企业信息by Qydm")
|
|
|
+ * @Apidoc\Tag("企业")
|
|
|
+ * @Apidoc\Method ("GET")
|
|
|
+ * @Apidoc\Author ("ihavoc")
|
|
|
+ * @Route("getEnterPrisesByQydm",method="GET")
|
|
|
+ * @Middleware({"jwt"})
|
|
|
+ */
|
|
|
+ public function getEnterPrisesByQydm(): Json
|
|
|
+ {
|
|
|
+ $qydm= $this->request->get();
|
|
|
+ try {
|
|
|
+ validate(Qydm::class)->check($qydm);
|
|
|
+ }catch (ValidateException $e){
|
|
|
+ $this->JsonError($e->getError());
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ return $this->JsonSucess(EnterprisesService::getEnterprisesInfoByQydm(getQydm()));
|
|
|
+ } catch (DataNotFoundException|ModelNotFoundException|DbException $dbE) {
|
|
|
+ return $this->JsonError($dbE->getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * @Apidoc\Title("监管企业信息by Qydm")
|
|
|
+ * @Apidoc\Tag("企业")
|
|
|
+ * @Apidoc\Method ("GET")
|
|
|
+ * @Apidoc\Author ("ihavoc")
|
|
|
+ * @Route("getEnterPrisesByQydmGOV",method="GET")
|
|
|
+ * @Middleware({"jwt"})
|
|
|
+ */
|
|
|
+ public function getEnterPrisesByQydmGOV(): Json
|
|
|
+ {
|
|
|
+ $qydm= $this->request->get();
|
|
|
+ try {
|
|
|
+ validate(Qydm::class)->check($qydm);
|
|
|
+ }catch (ValidateException $e){
|
|
|
+ $this->JsonError($e->getError());
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ return $this->JsonSucess(EnterprisesService::getEnterprisesInfoByQydm($qydm["qydm"]));
|
|
|
+ } catch (DataNotFoundException|ModelNotFoundException|DbException $dbE) {
|
|
|
+ return $this->JsonError($dbE->getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * @Apidoc\Title("删除企业信息")
|
|
|
+ * @Apidoc\Tag("企业")
|
|
|
+ * @Apidoc\Method ("POST")
|
|
|
+ * @Apidoc\Author ("ihavoc")
|
|
|
+ * @Route("delEnterPrisesById",method="POST")
|
|
|
+ * @Middleware({"jwt"})
|
|
|
+ */
|
|
|
+ public function delEnterPrisesById(): Json
|
|
|
+ {
|
|
|
+ $id= $this->request->POST();
|
|
|
+ try {
|
|
|
+ validate(Id::class)->check($id);
|
|
|
+ }catch (ValidateException $e){
|
|
|
+ $this->JsonError($e->getError());
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ return $this->JsonSucess(EnterprisesService::delEnterprises($id["id"]));
|
|
|
+ } catch (DataNotFoundException $dbE) {
|
|
|
+ return $this->JsonError($dbE->getMessage());
|
|
|
+ } catch (ModelNotFoundException $dbE) {
|
|
|
+ return $this->JsonError($dbE->getMessage());
|
|
|
+ } catch (DbException $dbE) {
|
|
|
+ return $this->JsonError($dbE->getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * @Apidoc\Title("更新企业信息")
|
|
|
+ * @Apidoc\Tag("企业")
|
|
|
+ * @Apidoc\Method ("POST")
|
|
|
+ * @Apidoc\Author ("ihavoc")
|
|
|
+ * @Route("updateEnterPrisesById",method="POST")
|
|
|
+ * @Middleware({"jwt"})
|
|
|
+ */
|
|
|
+ public function updateEnterPrisesById(): Json
|
|
|
+ {
|
|
|
+ $info= $this->request->post();
|
|
|
+ try {
|
|
|
+ validate(Qydm::class)->check($info);
|
|
|
+ }catch (ValidateException $e){
|
|
|
+ $this->JsonError($e->getError());
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ return $this->JsonSucess(EnterprisesService::editEnterprisesInfo($info,$info["id"]));
|
|
|
+ } catch (DataNotFoundException $dbE) {
|
|
|
+
|
|
|
+ return $this->JsonError($dbE->getMessage());
|
|
|
+ } catch (ModelNotFoundException $dbE) {
|
|
|
+
|
|
|
+ return $this->JsonError($dbE->getMessage());
|
|
|
+ } catch (DbException $dbE) {
|
|
|
+
|
|
|
+ return $this->JsonError($dbE->getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * @Apidoc\Title("添加企业信息")
|
|
|
+ * @Apidoc\Tag("企业")
|
|
|
+ * @Apidoc\Method ("POST")
|
|
|
+ * @Apidoc\Author ("ihavoc")
|
|
|
+ * @Route("addEnterPrises",method="POST")
|
|
|
+ * @Middleware({"jwt"})
|
|
|
+ */
|
|
|
+ public function addEnterPrises(): Json
|
|
|
+ {
|
|
|
+ $info= $this->request->post();
|
|
|
+ try {
|
|
|
+ validate(\app\validate\Enterprises::class)->check($info);
|
|
|
+ }catch (ValidateException $e){
|
|
|
+ $this->JsonError($e->getError());
|
|
|
+ }
|
|
|
+ if ($info["entity_type"]=="个人"){
|
|
|
+ $info["qydm"]=$info["towns"].".".$info["fzr_id_number"];
|
|
|
+ }else{
|
|
|
+ $info["qydm"]=$info["towns"].".".$info["xydm"];
|
|
|
+ }
|
|
|
+
|
|
|
+ return $this->JsonSucess(EnterprisesService::addEnterprises($info));
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @Apidoc\Title("企业用户登录接口")
|
|
|
+ * @Apidoc\Tag("企业用户登录")
|
|
|
+ * @Apidoc\Author("yang")
|
|
|
+ * @Apidoc\Method ("POST")
|
|
|
+ * @throws ModelNotFoundException
|
|
|
+ * @throws DataNotFoundException
|
|
|
+ * @throws DbException
|
|
|
+ * @Route("enterpriseslogin",method="POST")
|
|
|
+ * @Middleware({})
|
|
|
+ */
|
|
|
+ public function enterpriseslogin():Json{
|
|
|
+ $loginInfo = $this->request->post();
|
|
|
+ // dump($loginInfo);die;
|
|
|
+ try {
|
|
|
+ validate(EnterprisesLogin::class)->check($loginInfo);
|
|
|
+ }catch (ValidateException $e){
|
|
|
+ return $this->JsonError($e->getError(),0);
|
|
|
+ }
|
|
|
+ $userInfo=EnterprisesService::selectLoginInfo($loginInfo);
|
|
|
+ if ($userInfo){
|
|
|
+ $token = JWTAuth::builder(['qydm' => $userInfo["qydm"]]);//参数为用户认证的信息,请自行添加
|
|
|
+ return $this->JsonSucess(["token"=>$token,"userInfo"=>$userInfo],1);
|
|
|
+ }else{
|
|
|
+ return $this->JsonError(1002);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @Apidoc\Title("注册企业信息")
|
|
|
+ * @Apidoc\Tag("企业")
|
|
|
+ * @Apidoc\Method ("POST")
|
|
|
+ * @Apidoc\Author ("yang")
|
|
|
+ * @Route("registerEnterPrises",method="POST")
|
|
|
+ * @Middleware({})
|
|
|
+ */
|
|
|
+ public function registerEnterPrises(): Json
|
|
|
+ {
|
|
|
+ $info= $this->request->post();
|
|
|
+ try {
|
|
|
+ validate(\app\validate\Enterprises::class)->check($info);
|
|
|
+ }catch (ValidateException $e){
|
|
|
+ $this->JsonError($e->getError());
|
|
|
+ }
|
|
|
+ if ($info["entity_type"]=="个人"){
|
|
|
+ $info["qydm"]=$info["towns"].".".$info["fzr_id_number"];
|
|
|
+ }else{
|
|
|
+ $info["qydm"]=$info["towns"].".".$info["xydm"];
|
|
|
+ }
|
|
|
+
|
|
|
+ $info['creation_time'] = date('Y-m-d h:i:s', time());
|
|
|
+ return $this->JsonSucess(EnterprisesService::addEnterprises($info));
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|