SignContractController.php 7.3 KB

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