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