SignContractController.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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\Models\SignRecord;
  9. use App\Servers\ESign\ESignContractServer;
  10. use App\Servers\Wps\WordServer;
  11. class SignContractController extends AdminController
  12. {
  13. /**
  14. * 获取项目合同
  15. * @return \Illuminate\Http\JsonResponse
  16. */
  17. function getContractList()
  18. {
  19. $search=request()->input('search');
  20. $where = [['is_del',0]];
  21. if(!empty($search)){
  22. $where[] = ['name','like','%'.$search.'%'];
  23. }
  24. $list = Contract::where($where)
  25. ->select(['id','name','texts','sign_party'])
  26. ->paginate(10);
  27. return $this->apiResponseSuccess('获取列表成功', [
  28. 'items' => $list->items(),
  29. 'total' => $list->total(),
  30. 'limit' => 10,
  31. ]);
  32. }
  33. /**
  34. * 获取机构列表
  35. * @return \Illuminate\Http\JsonResponse
  36. */
  37. function getFirmList(){
  38. $search=request()->input('search');
  39. $where = [['is_del',0], ['realnameStatus',1]];
  40. if(!empty($search)){
  41. $where[] = ['firm_name','like','%'.$search.'%'];
  42. }
  43. $list = Firm::where($where)
  44. ->select(['id','firm_name','license_number','legal_name','authType','orgId','realnameStatus','authorizeUserInfo','created_at'])
  45. ->paginate(10);
  46. return $this->apiResponseSuccess('获取列表成功', [
  47. 'items' => $list->items(),
  48. 'total' => $list->total(),
  49. 'limit' => 10,
  50. ]);
  51. }
  52. /**
  53. * 获取用户列表
  54. * @return \Illuminate\Http\JsonResponse
  55. */
  56. function getMemberList(){
  57. $search=request()->input('search');
  58. $where = [['is_del',0], ['realnameStatus',1]];
  59. if(!empty($search)){
  60. $where[] = ['name','like','%'.$search.'%'];
  61. }
  62. $list = Member::where($where)
  63. ->select(['id','name','phone','id_number','authType','psnId','realnameStatus','authorizeUserInfo','created_at'])
  64. ->paginate(10);
  65. return $this->apiResponseSuccess('获取列表成功', [
  66. 'items' => $list->items(),
  67. 'total' => $list->total(),
  68. 'limit' => 10,
  69. ]);
  70. }
  71. /**
  72. * 获取签署列表
  73. * @return \Illuminate\Http\JsonResponse
  74. */
  75. function getSignContractList()
  76. {
  77. $search=request()->input('search');
  78. $where = [['is_del',0]];
  79. if(!empty($search)){
  80. $where[] = ['contracts_no','like','%'.$search.'%'];
  81. }
  82. $list = SignContract::where($where)
  83. ->select(['id','contract_no','status','contract_id','sign_url','created_at'])
  84. ->paginate(10);
  85. foreach ($list as $key => $value) {
  86. $value->{'contract_name'} = Contract::where('id',$value->{'contract_id'})->value('name');
  87. //获取用户签署链接
  88. $value->{'psn_sign_url'} = SignRecord::where('sign_id',$value->{'id'})->where('authType','PSN')->value('sign_url');
  89. //获取企业签署链接
  90. $value->{'org_sign_url'} = SignRecord::where('sign_id',$value->{'id'})->where('authType','ORG')->value('sign_url');
  91. $value->initializeModel();
  92. }
  93. return $this->apiResponseSuccess('获取列表成功', [
  94. 'items' => $list->items(),
  95. 'total' => $list->total(),
  96. 'limit' => 10,
  97. ]);
  98. }
  99. /**
  100. * 创建合同签署
  101. * @return \Illuminate\Http\JsonResponse
  102. * @throws \PhpOffice\PhpWord\Exception\Exception
  103. */
  104. function createSignContract()
  105. {
  106. $contract_id=request()->input('contract_id','');//合同id
  107. $contract_no=request()->input('contract_no','');//合同编号
  108. $text_json=request()->input('textsJson','');//替换文本json
  109. $sign_json=request()->input('signJson','');//签署区域信息
  110. if(empty($contract_id)){
  111. return $this->apiResponseError('请选择合同');
  112. }
  113. if(empty($text_json)){
  114. return $this->apiResponseError('请填写合同信息');
  115. }
  116. if(empty($sign_json)){
  117. return $this->apiResponseError('请选择签署信息');
  118. }
  119. //获取合同信息
  120. $contract = Contract::where(['id'=>$contract_id])->first();
  121. if (empty($contract)){
  122. return $this->apiResponseError('合同不存在');
  123. }
  124. //替换合同信息
  125. $file_path = $contract->{'contracts_file'};
  126. // 获取所有信息
  127. $pathInfo = pathinfo($file_path);
  128. $file_name = $pathInfo['filename'].$contract_no.'.'.$pathInfo['extension'];
  129. //替换合同信息
  130. $local_file = WordServer::creatServer()->replaceWordText($file_path,$file_name,$text_json);
  131. //上传文件到e签宝并获得文件id
  132. $file_id = ESignContractServer::creatServer()->fileUploadUrl($local_file);
  133. $data = compact('contract_id','contract_no','file_id','text_json','sign_json','local_file');
  134. //存入数据库
  135. $sign = SignContract::create($data);
  136. if (empty($sign)){
  137. return $this->apiResponseError('保存失败');
  138. }
  139. return $this->apiResponseSuccess('保存成功');
  140. }
  141. /**
  142. * 下载合同
  143. * @return \Illuminate\Http\JsonResponse
  144. */
  145. function downloadContract()
  146. {
  147. $contract_id=request()->input('contract_id','');//合同id
  148. if(empty($contract_id)){
  149. return $this->apiResponseError('请选择合同');
  150. }
  151. //获取合同信息
  152. $contract = SignContract::where(['id'=>$contract_id])->first();
  153. if (empty($contract)){
  154. return $this->apiResponseError('合同不存在');
  155. }
  156. if ($contract->{'status'} != 2){
  157. return $this->apiResponseError('合同未签署完毕');
  158. }
  159. //上传文件到e签宝并获得文件id
  160. $result = ESignContractServer::creatServer()->downloadFileUrl($contract->{'flow_id'});
  161. if (empty($result)){
  162. return $this->apiResponseError('获取失败');
  163. }
  164. return $this->apiResponseSuccess('成功',$result);
  165. }
  166. }