FirmController.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <?php
  2. namespace App\Http\Controllers\AdminApi;
  3. use App\Http\Controllers\AdminController;
  4. use App\Models\Firm;
  5. use App\Servers\ESign\ESignFirmServer;
  6. use App\Servers\System\CommonServer;
  7. use App\Servers\System\JobServer;
  8. class FirmController extends AdminController
  9. {
  10. /**
  11. * 获取机构列表
  12. * @return \Illuminate\Http\JsonResponse
  13. */
  14. function getFirmList(){
  15. $where = [['is_del',0]];
  16. $list = Firm::where($where)
  17. ->select(['id','firm_name','license_number','legal_name','orgId','authUrl','authShortUrl','realnameStatus','authorizeUserInfo','created_at'])
  18. ->paginate(10);
  19. return $this->apiResponseSuccess('获取列表成功', [
  20. 'items' => $list->items(),
  21. 'total' => $list->total(),
  22. 'limit' => 10,
  23. ]);
  24. }
  25. /**
  26. * 通知企业认证
  27. * @return \Illuminate\Http\JsonResponse
  28. */
  29. function noticeFirmAuth(){
  30. $id=request()->input('id','');//id
  31. if(empty($id)) return $this->apiResponseError('缺少必要参数');
  32. $info = Firm::where('id',$id)->select(['id','firm_name','phone','license_number','license_img','registered_address','authType','legal_identity_one','legal_identity_two','legal_id_number'])->first();
  33. if (empty($info)) {
  34. return $this->apiResponseError('没有找到该记录');
  35. }
  36. //查询个人认证信息
  37. ESignFirmServer::creatServer()->organizationsIdentityInfo($id,$info->{'firm_name'});
  38. return $this->apiResponseSuccess('成功');
  39. }
  40. /**
  41. * 添加&编辑用户
  42. * @return \Illuminate\Http\JsonResponse
  43. * @throws \Throwable
  44. */
  45. function saveFirm(){
  46. $id=request()->input('id','');//id
  47. $firm_name=request()->input('firm_name','');//姓名
  48. $phone=request()->input('phone','');//电话
  49. $license_number=request()->input('license_number','');//统一社会信用代码
  50. $license_img=request()->input('license_img','');//营业执照
  51. $registered_address=request()->input('registered_address','');//注册地址
  52. $legal_identity_one=request()->input('legal_identity_one','');//法人身份证正明
  53. $legal_identity_two=request()->input('legal_identity_two','');//法人身份证背面
  54. $legal_id_number=request()->input('legal_id_number','');//身份证号
  55. $legal_name=request()->input('legal_name','');//法人姓名
  56. if (empty($firm_name)) return $this->apiResponseError('请填写姓名');
  57. if (empty($legal_name)) return $this->apiResponseError('请填写法人姓名');
  58. if (mb_strlen($firm_name) > 100) return $this->apiResponseError('姓名最大100');
  59. if (empty($phone)) return $this->apiResponseError('请填写手机号');
  60. if (!CommonServer::creatServer()->verifyPhoneNumber($phone)) return $this->apiResponseError('手机号错误');
  61. if (empty($license_number)) return $this->apiResponseError('请填写统一社会信用代码');
  62. if (empty($license_img)) return $this->apiResponseError('请上传营业执照');
  63. if (empty($registered_address)) return $this->apiResponseError('注册地址不能为空');
  64. if (empty($legal_identity_one)) return $this->apiResponseError('请传身份证正面');
  65. if (empty($legal_identity_two)) return $this->apiResponseError('请传身份证反面');
  66. if (empty($legal_id_number)) return $this->apiResponseError('请填身份证号码');
  67. $authType = 'ORG';
  68. $data = compact('firm_name','phone','license_number','license_img','registered_address','authType','legal_identity_one','legal_identity_two','legal_id_number','legal_name');
  69. if(empty($id)){//不存在id就创建
  70. //检查该统一社会信用代码是否存在
  71. $firm = Firm::where('license_number',$license_number)->where('is_del',0)->select(['id'])->first();
  72. if (!empty($firm)){
  73. return $this->apiResponseError('统一社会信用代码已存在');
  74. }
  75. $res = Firm::create($data);
  76. $firm_id = $res->{'id'};
  77. }else{//存在就更新
  78. $info = Firm::where('id',$id)->select(['id'])->first();
  79. if (empty($info)) {
  80. return $this->apiResponseError('没有找到该记录');
  81. }
  82. //检查该统一社会信用代码是否存在
  83. $firm = Firm::where('license_number',$license_number)->where('id','<>',$id)->where('is_del',0)->select(['id'])->first();
  84. if (!empty($firm)){
  85. return $this->apiResponseError('统一社会信用代码已存在');
  86. }
  87. $res = $info->update($data);
  88. $firm_id = $id;
  89. }
  90. //查询个人认证信息
  91. ESignFirmServer::creatServer()->organizationsIdentityInfo($firm_id,$firm_name);
  92. if ($res) {
  93. return $this->apiResponseSuccess('操作成功');
  94. } else {
  95. return $this->apiResponseError('操作失败');
  96. }
  97. }
  98. /**
  99. * 获取详情
  100. * @return \Illuminate\Http\JsonResponse
  101. */
  102. function getFirmInfo()
  103. {
  104. $id = request()->input('id','');//获取需要删除的id
  105. if(empty($id)) return $this->apiResponseError('缺少必要参数');
  106. $info = Firm::where('id',$id)->select(['id','firm_name','phone','license_number','license_img','registered_address','authType','legal_identity_one','legal_identity_two','legal_id_number','legal_name'])->first();
  107. if (empty($info)) {
  108. return $this->apiResponseError('没有找到该记录');
  109. }
  110. return $this->apiResponseSuccess('成功',$info);
  111. }
  112. }