FirmController.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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','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. * @throws \Throwable
  29. */
  30. function saveFirm(){
  31. $id=request()->input('id','');//id
  32. $firm_name=request()->input('firm_name','');//姓名
  33. $phone=request()->input('phone','');//电话
  34. $license_number=request()->input('license_number','');//统一社会信用代码
  35. $license_img=request()->input('license_img','');//营业执照
  36. $registered_address=request()->input('registered_address','');//注册地址
  37. $legal_identity_one=request()->input('legal_identity_one','');//法人身份证正明
  38. $legal_identity_two=request()->input('legal_identity_two','');//法人身份证背面
  39. $legal_id_number=request()->input('legal_id_number','');//身份证号
  40. if (empty($firm_name)) return $this->apiResponseError('请填写姓名');
  41. if (mb_strlen($firm_name) > 100) return $this->apiResponseError('姓名最大100');
  42. if (empty($phone)) return $this->apiResponseError('请填写手机号');
  43. if (!CommonServer::creatServer()->verifyPhoneNumber($phone)) return $this->apiResponseError('手机号错误');
  44. if (empty($license_number)) return $this->apiResponseError('请填写统一社会信用代码');
  45. if (empty($license_img)) return $this->apiResponseError('请上传营业执照');
  46. if (empty($registered_address)) return $this->apiResponseError('注册地址不能为空');
  47. if (empty($legal_identity_one)) return $this->apiResponseError('请传身份证正面');
  48. if (empty($legal_identity_two)) return $this->apiResponseError('请传身份证反面');
  49. if (empty($legal_id_number)) return $this->apiResponseError('请填身份证号码');
  50. //检查该统一社会信用代码是否存在
  51. $firm = Firm::where('license_number',$license_number)->where('is_del',0)->select(['id'])->first();
  52. if (!empty($firm)){
  53. return $this->apiResponseError('统一社会信用代码已存在');
  54. }
  55. $authType = 'ORG';
  56. $data = compact('firm_name','phone','license_number','license_img','registered_address','authType','legal_identity_one','legal_identity_two','legal_id_number');
  57. if(empty($id)){//不存在id就创建
  58. $res = Firm::create($data);
  59. }else{//存在就更新
  60. $info = Firm::where('id',$id)->select(['id'])->first();
  61. if (empty($info)) {
  62. return $this->apiResponseError('没有找到该记录');
  63. }
  64. $res = $info->update($data);
  65. }
  66. $firm_id = $res->{'id'};
  67. //查询个人认证信息
  68. ESignFirmServer::creatServer()->organizationsIdentityInfo($firm_id,$firm_name);
  69. if ($res) {
  70. return $this->apiResponseSuccess('操作成功');
  71. } else {
  72. return $this->apiResponseError('操作失败');
  73. }
  74. }
  75. /**
  76. * 获取详情
  77. * @return \Illuminate\Http\JsonResponse
  78. */
  79. function getFirmInfo()
  80. {
  81. $id = request()->input('id','');//获取需要删除的id
  82. if(empty($id)) return $this->apiResponseError('缺少必要参数');
  83. $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();
  84. if (empty($info)) {
  85. return $this->apiResponseError('没有找到该记录');
  86. }
  87. return $this->apiResponseSuccess('成功',$info);
  88. }
  89. }