Enterprises.php 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. <?php
  2. namespace app\controller;
  3. use app\BaseController;
  4. use app\service\EnterprisesService;
  5. use app\service\UserService;
  6. use app\validate\Id;
  7. use app\validate\Page;
  8. use app\validate\Qydm;
  9. use app\validate\EnterprisesLogin;
  10. use app\validate\UserLogin;
  11. use thans\jwt\facade\JWTAuth;
  12. use think\db\exception\DataNotFoundException;
  13. use think\db\exception\DbException;
  14. use think\db\exception\ModelNotFoundException;
  15. use think\exception\ValidateException;
  16. use think\response\Json;
  17. use think\annotation\Route;
  18. use think\annotation\route\Middleware;
  19. use hg\apidoc\annotation as Apidoc;
  20. /**
  21. * @Apidoc\Title("企业信息")
  22. * @Apidoc\Group("企业")
  23. * @Apidoc\Sort (3)
  24. */
  25. class Enterprises extends BaseController
  26. {
  27. protected $middleware = [
  28. 'jwt',
  29. ];
  30. use ResponseJson;
  31. /**
  32. * @Apidoc\Title("企业列表")
  33. * @Apidoc\Tag("企业")
  34. * @Apidoc\Method ("GET")
  35. * @Apidoc\Author ("ihavoc")
  36. * @Route("getEnterPrisesList",method="GET")
  37. * @Middleware({"jwt"})
  38. */
  39. public function getEnterPrisesList(): Json
  40. {
  41. $page = $this->request->get();
  42. try {
  43. validate(Page::class)->check($page);
  44. }catch (ValidateException $e){
  45. $page["page"]=1;
  46. $page["size"] = 15;
  47. }
  48. try {
  49. return $this->JsonSucess(EnterprisesService::getEnterPrisesList($page, getXzqdmSub()));
  50. } catch (DataNotFoundException $dbE) {
  51. return $this->JsonError($dbE);
  52. } catch (ModelNotFoundException $dbE) {
  53. return $this->JsonError($dbE);
  54. } catch (DbException $dbE) {
  55. return $this->JsonError($dbE);
  56. }
  57. }
  58. /**
  59. * @Apidoc\Title("企业信息by ID")
  60. * @Apidoc\Tag("企业")
  61. * @Apidoc\Method ("GET")
  62. * @Apidoc\Author ("ihavoc")
  63. * @Route("getEnterPrisesInfo",method="GET")
  64. * @Middleware({"jwt"})
  65. */
  66. public function getEnterPrisesInfo(): Json
  67. {
  68. $id= $this->request->get();
  69. try {
  70. validate(Id::class)->check($id);
  71. }catch (ValidateException $e){
  72. $this->JsonError($e->getError());
  73. }
  74. try {
  75. return $this->JsonSucess(EnterprisesService::getEnterprisesInfoById($id["id"]));
  76. } catch (DataNotFoundException $dbE) {
  77. return $this->JsonError($dbE);
  78. } catch (ModelNotFoundException $dbE) {
  79. return $this->JsonError($dbE);
  80. } catch (DbException $dbE) {
  81. return $this->JsonError($dbE);
  82. }
  83. }
  84. /**
  85. * @Apidoc\Title("企业信息by Qydm")
  86. * @Apidoc\Tag("企业")
  87. * @Apidoc\Method ("GET")
  88. * @Apidoc\Author ("ihavoc")
  89. * @Route("getEnterPrisesByQydm",method="GET")
  90. * @Middleware({"jwt"})
  91. */
  92. public function getEnterPrisesByQydm(): Json
  93. {
  94. $qydm= $this->request->get();
  95. try {
  96. validate(Qydm::class)->check($qydm);
  97. }catch (ValidateException $e){
  98. $this->JsonError($e->getError());
  99. }
  100. try {
  101. return $this->JsonSucess(EnterprisesService::getEnterprisesInfoByQydm(getQydm()));
  102. } catch (DataNotFoundException|ModelNotFoundException|DbException $dbE) {
  103. return $this->JsonError($dbE->getMessage());
  104. }
  105. }
  106. /**
  107. * @Apidoc\Title("监管企业信息by Qydm")
  108. * @Apidoc\Tag("企业")
  109. * @Apidoc\Method ("GET")
  110. * @Apidoc\Author ("ihavoc")
  111. * @Route("getEnterPrisesByQydmGOV",method="GET")
  112. * @Middleware({"jwt"})
  113. */
  114. public function getEnterPrisesByQydmGOV(): Json
  115. {
  116. $qydm= $this->request->get();
  117. try {
  118. validate(Qydm::class)->check($qydm);
  119. }catch (ValidateException $e){
  120. $this->JsonError($e->getError());
  121. }
  122. try {
  123. return $this->JsonSucess(EnterprisesService::getEnterprisesInfoByQydm($qydm["qydm"]));
  124. } catch (DataNotFoundException|ModelNotFoundException|DbException $dbE) {
  125. return $this->JsonError($dbE->getMessage());
  126. }
  127. }
  128. /**
  129. * @Apidoc\Title("删除企业信息")
  130. * @Apidoc\Tag("企业")
  131. * @Apidoc\Method ("POST")
  132. * @Apidoc\Author ("ihavoc")
  133. * @Route("delEnterPrisesById",method="POST")
  134. * @Middleware({"jwt"})
  135. */
  136. public function delEnterPrisesById(): Json
  137. {
  138. $id= $this->request->POST();
  139. try {
  140. validate(Id::class)->check($id);
  141. }catch (ValidateException $e){
  142. $this->JsonError($e->getError());
  143. }
  144. try {
  145. return $this->JsonSucess(EnterprisesService::delEnterprises($id["id"]));
  146. } catch (DataNotFoundException $dbE) {
  147. return $this->JsonError($dbE->getMessage());
  148. } catch (ModelNotFoundException $dbE) {
  149. return $this->JsonError($dbE->getMessage());
  150. } catch (DbException $dbE) {
  151. return $this->JsonError($dbE->getMessage());
  152. }
  153. }
  154. /**
  155. * @Apidoc\Title("更新企业信息")
  156. * @Apidoc\Tag("企业")
  157. * @Apidoc\Method ("POST")
  158. * @Apidoc\Author ("ihavoc")
  159. * @Route("updateEnterPrisesById",method="POST")
  160. * @Middleware({"jwt"})
  161. */
  162. public function updateEnterPrisesById(): Json
  163. {
  164. $info= $this->request->post();
  165. try {
  166. validate(Qydm::class)->check($info);
  167. }catch (ValidateException $e){
  168. $this->JsonError($e->getError());
  169. }
  170. try {
  171. return $this->JsonSucess(EnterprisesService::editEnterprisesInfo($info,$info["id"]));
  172. } catch (DataNotFoundException $dbE) {
  173. return $this->JsonError($dbE->getMessage());
  174. } catch (ModelNotFoundException $dbE) {
  175. return $this->JsonError($dbE->getMessage());
  176. } catch (DbException $dbE) {
  177. return $this->JsonError($dbE->getMessage());
  178. }
  179. }
  180. /**
  181. * @Apidoc\Title("添加企业信息")
  182. * @Apidoc\Tag("企业")
  183. * @Apidoc\Method ("POST")
  184. * @Apidoc\Author ("ihavoc")
  185. * @Route("addEnterPrises",method="POST")
  186. * @Middleware({"jwt"})
  187. */
  188. public function addEnterPrises(): Json
  189. {
  190. $info= $this->request->post();
  191. try {
  192. validate(\app\validate\Enterprises::class)->check($info);
  193. }catch (ValidateException $e){
  194. $this->JsonError($e->getError());
  195. }
  196. if ($info["entity_type"]=="个人"){
  197. $info["qydm"]=$info["towns"].".".$info["fzr_id_number"];
  198. }else{
  199. $info["qydm"]=$info["towns"].".".$info["xydm"];
  200. }
  201. return $this->JsonSucess(EnterprisesService::addEnterprises($info));
  202. }
  203. /**
  204. * @Apidoc\Title("企业用户登录接口")
  205. * @Apidoc\Tag("企业用户登录")
  206. * @Apidoc\Author("yang")
  207. * @Apidoc\Method ("POST")
  208. * @throws ModelNotFoundException
  209. * @throws DataNotFoundException
  210. * @throws DbException
  211. * @Route("enterpriseslogin",method="POST")
  212. * @Middleware({})
  213. */
  214. public function enterpriseslogin():Json{
  215. $loginInfo = $this->request->post();
  216. // dump($loginInfo);die;
  217. try {
  218. validate(EnterprisesLogin::class)->check($loginInfo);
  219. }catch (ValidateException $e){
  220. return $this->JsonError($e->getError(),0);
  221. }
  222. $userInfo=EnterprisesService::selectLoginInfo($loginInfo);
  223. if ($userInfo){
  224. $token = JWTAuth::builder(['qydm' => $userInfo["qydm"]]);//参数为用户认证的信息,请自行添加
  225. return $this->JsonSucess(["token"=>$token,"userInfo"=>$userInfo],1);
  226. }else{
  227. return $this->JsonError(1002);
  228. }
  229. }
  230. /**
  231. * @Apidoc\Title("注册企业信息")
  232. * @Apidoc\Tag("企业")
  233. * @Apidoc\Method ("POST")
  234. * @Apidoc\Author ("yang")
  235. * @Route("registerEnterPrises",method="POST")
  236. * @Middleware({})
  237. */
  238. public function registerEnterPrises(): Json
  239. {
  240. $info= $this->request->post();
  241. try {
  242. validate(\app\validate\Enterprises::class)->check($info);
  243. }catch (ValidateException $e){
  244. $this->JsonError($e->getError());
  245. }
  246. if ($info["entity_type"]=="个人"){
  247. $info["qydm"]=$info["towns"].".".$info["fzr_id_number"];
  248. }else{
  249. $info["qydm"]=$info["towns"].".".$info["xydm"];
  250. }
  251. $info['creation_time'] = date('Y-m-d h:i:s', time());
  252. return $this->JsonSucess(EnterprisesService::addEnterprises($info));
  253. }
  254. }