SignContractController.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <?php
  2. namespace App\Http\Controllers\AdminApi;
  3. use App\Http\Controllers\AdminController;
  4. use App\Models\Contract;
  5. use App\Models\Firm;
  6. use App\Models\Member;
  7. use App\Models\SignContract;
  8. use App\Servers\ESign\ESignContractServer;
  9. use App\Servers\Wps\WordServer;
  10. class SignContractController extends AdminController
  11. {
  12. /**
  13. * 获取项目合同
  14. * @return \Illuminate\Http\JsonResponse
  15. */
  16. function getContractList()
  17. {
  18. $search=request()->input('search');
  19. $where = [['is_del',0]];
  20. if(!empty($search)){
  21. $where[] = ['name','like','%'.$search.'%'];
  22. }
  23. $list = Contract::where($where)
  24. ->select(['id','name','texts','sign_party'])
  25. ->paginate(10);
  26. return $this->apiResponseSuccess('获取列表成功', [
  27. 'items' => $list->items(),
  28. 'total' => $list->total(),
  29. 'limit' => 10,
  30. ]);
  31. }
  32. /**
  33. * 获取机构列表
  34. * @return \Illuminate\Http\JsonResponse
  35. */
  36. function getFirmList(){
  37. $search=request()->input('search');
  38. $where = [['is_del',0], ['realnameStatus',1], ['authorizeUserInfo',1]];
  39. if(!empty($search)){
  40. $where[] = ['firm_name','like','%'.$search.'%'];
  41. }
  42. $list = Firm::where($where)
  43. ->select(['id','firm_name','license_number','legal_name','authType','orgId','realnameStatus','authorizeUserInfo','created_at'])
  44. ->paginate(10);
  45. return $this->apiResponseSuccess('获取列表成功', [
  46. 'items' => $list->items(),
  47. 'total' => $list->total(),
  48. 'limit' => 10,
  49. ]);
  50. }
  51. /**
  52. * 获取用户列表
  53. * @return \Illuminate\Http\JsonResponse
  54. */
  55. function getMemberList(){
  56. $search=request()->input('search');
  57. $where = [['is_del',0], ['realnameStatus',1], ['authorizeUserInfo',1]];
  58. if(!empty($search)){
  59. $where[] = ['name','like','%'.$search.'%'];
  60. }
  61. $list = Member::where($where)
  62. ->select(['id','name','phone','id_number','authType','psnId','realnameStatus','authorizeUserInfo','created_at'])
  63. ->paginate(10);
  64. return $this->apiResponseSuccess('获取列表成功', [
  65. 'items' => $list->items(),
  66. 'total' => $list->total(),
  67. 'limit' => 10,
  68. ]);
  69. }
  70. /**
  71. * 创建合同签署
  72. * @return \Illuminate\Http\JsonResponse
  73. * @throws \PhpOffice\PhpWord\Exception\Exception
  74. */
  75. function createSignContract()
  76. {
  77. $contract_id=request()->input('contract_id','');//合同id
  78. $contract_no=request()->input('contract_no','');//合同编号
  79. $text_json=request()->input('textsJson','');//替换文本json
  80. $sign_json=request()->input('signJson','');//签署区域信息
  81. if(empty($contract_id)){
  82. return $this->apiResponseError('请选择合同');
  83. }
  84. if(empty($text_json)){
  85. return $this->apiResponseError('请填写合同信息');
  86. }
  87. if(empty($sign_json)){
  88. return $this->apiResponseError('请选择签署信息');
  89. }
  90. //获取合同信息
  91. $contract = Contract::where(['id'=>$contract_id])->first();
  92. if (empty($contract)){
  93. return $this->apiResponseError('合同不存在');
  94. }
  95. //替换合同信息
  96. $file_path = $contract->{'contracts_file'};
  97. // 获取所有信息
  98. $pathInfo = pathinfo($file_path);
  99. $file_name = $pathInfo['filename'].$contract_no.'.'.$pathInfo['extension'];
  100. //替换合同信息
  101. $local_file = WordServer::creatServer()->replaceWordText($file_path,$file_name,$text_json);
  102. //上传文件到e签宝并获得文件id
  103. $file_id = ESignContractServer::creatServer()->fileUploadUrl($local_file);
  104. $data = compact('contract_id','contract_no','file_id','text_json','sign_json','local_file');
  105. //存入数据库
  106. $sign = SignContract::create($data);
  107. $sign_id = $sign->{'id'};
  108. if (empty($sign_id)){
  109. return $this->apiResponseError('保存失败');
  110. }
  111. //上传e签宝进行签署
  112. $result = ESignContractServer::creatServer()->setContractContract($sign_id,$file_id,$sign_json,$pathInfo['filename'].$contract_no);
  113. if ($result['code'] == 0){
  114. return $this->apiResponseError($result['msg']);
  115. }
  116. return $this->apiResponseSuccess($result['msg']);
  117. }
  118. }