SignContractController.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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. $psnInfo = SignRecord::where('sign_id',$value->{'id'})->where('authType','PSN')->select(['status','sign_url','id_no'])->first();
  89. if (!empty($psnInfo)){
  90. $psnInfo->{'name'} = Member::where('psnId',$psnInfo->{'id_no'})->value('name');
  91. }else{
  92. $psnInfo = [
  93. 'status' => 1,
  94. 'sign_url' => '',
  95. 'id_no' => '',
  96. 'name' => '',
  97. ];
  98. }
  99. $psnInfo->initializeModel();
  100. //获取企业签署链接
  101. $orgInfo = SignRecord::where('sign_id',$value->{'id'})->where('authType','ORG')->select(['status','sign_url','id_no'])->first();
  102. if (!empty($orgInfo)){
  103. $orgInfo->{'name'} = Firm::where('orgId',$psnInfo->{'id_no'})->value('firm_name');
  104. }else{
  105. $orgInfo = [
  106. 'status' => 1,
  107. 'sign_url' => '',
  108. 'id_no' => '',
  109. 'name' => '',
  110. ];
  111. }
  112. $orgInfo->initializeModel();
  113. $value->{'psnInfo'} = $psnInfo;
  114. $value->{'orgInfo'} = $orgInfo;
  115. $value->initializeModel();
  116. }
  117. return $this->apiResponseSuccess('获取列表成功', [
  118. 'items' => $list->items(),
  119. 'total' => $list->total(),
  120. 'limit' => 10,
  121. ]);
  122. }
  123. /**
  124. * 创建合同签署
  125. * @return \Illuminate\Http\JsonResponse
  126. * @throws \PhpOffice\PhpWord\Exception\Exception
  127. */
  128. function createSignContract()
  129. {
  130. $contract_id=request()->input('contract_id','');//合同id
  131. $contract_no=request()->input('contract_no','');//合同编号
  132. $text_json=request()->input('textsJson','');//替换文本json
  133. $sign_json=request()->input('signJson','');//签署区域信息
  134. if(empty($contract_id)){
  135. return $this->apiResponseError('请选择合同');
  136. }
  137. if(empty($text_json)){
  138. return $this->apiResponseError('请填写合同信息');
  139. }
  140. if(empty($sign_json)){
  141. return $this->apiResponseError('请选择签署信息');
  142. }
  143. //获取合同信息
  144. $contract = Contract::where(['id'=>$contract_id])->first();
  145. if (empty($contract)){
  146. return $this->apiResponseError('合同不存在');
  147. }
  148. //替换合同信息
  149. $file_path = $contract->{'contracts_file'};
  150. // 获取所有信息
  151. $pathInfo = pathinfo($file_path);
  152. $file_name = $pathInfo['filename'].$contract_no.'.'.$pathInfo['extension'];
  153. //替换合同信息
  154. $local_file = WordServer::creatServer()->replaceWordText($file_path,$file_name,$text_json);
  155. //上传文件到e签宝并获得文件id
  156. $file_id = ESignContractServer::creatServer()->fileUploadUrl($local_file);
  157. $data = compact('contract_id','contract_no','file_id','text_json','sign_json','local_file');
  158. //存入数据库
  159. $sign = SignContract::create($data);
  160. if (empty($sign)){
  161. return $this->apiResponseError('保存失败');
  162. }
  163. return $this->apiResponseSuccess('保存成功');
  164. }
  165. /**
  166. * 下载合同
  167. * @return \Illuminate\Http\JsonResponse
  168. */
  169. function downloadContract()
  170. {
  171. $contract_id=request()->input('contract_id','');//合同id
  172. if(empty($contract_id)){
  173. return $this->apiResponseError('请选择合同');
  174. }
  175. //获取合同信息
  176. $contract = SignContract::where(['id'=>$contract_id])->first();
  177. if (empty($contract)){
  178. return $this->apiResponseError('合同不存在');
  179. }
  180. if ($contract->{'status'} != 2){
  181. return $this->apiResponseError('合同未签署完毕');
  182. }
  183. //上传文件到e签宝并获得文件id
  184. $result = ESignContractServer::creatServer()->downloadFileUrl($contract->{'flow_id'});
  185. if (empty($result)){
  186. return $this->apiResponseError('获取失败');
  187. }
  188. return $this->apiResponseSuccess('成功',$result);
  189. }
  190. }