SignContractController.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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. */
  74. function getSignContractList()
  75. {
  76. $search=request()->input('search');
  77. $where = [['is_del',0]];
  78. if(!empty($search)){
  79. $where[] = ['contracts_no','like','%'.$search.'%'];
  80. }
  81. $list = SignContract::where($where)
  82. ->select(['id','contract_no','status','contract_id','created_at'])
  83. ->paginate(10);
  84. foreach ($list as $key => $value) {
  85. $value->{'contracts_name'} = Contract::where('id',$value->contracts_id)->value('name');
  86. }
  87. return $this->apiResponseSuccess('获取列表成功', [
  88. 'items' => $list->items(),
  89. 'total' => $list->total(),
  90. 'limit' => 10,
  91. ]);
  92. }
  93. /**
  94. * 创建合同签署
  95. * @return \Illuminate\Http\JsonResponse
  96. * @throws \PhpOffice\PhpWord\Exception\Exception
  97. */
  98. function createSignContract()
  99. {
  100. $contract_id=request()->input('contract_id','');//合同id
  101. $contract_no=request()->input('contract_no','');//合同编号
  102. $text_json=request()->input('textsJson','');//替换文本json
  103. $sign_json=request()->input('signJson','');//签署区域信息
  104. if(empty($contract_id)){
  105. return $this->apiResponseError('请选择合同');
  106. }
  107. if(empty($text_json)){
  108. return $this->apiResponseError('请填写合同信息');
  109. }
  110. if(empty($sign_json)){
  111. return $this->apiResponseError('请选择签署信息');
  112. }
  113. //获取合同信息
  114. $contract = Contract::where(['id'=>$contract_id])->first();
  115. if (empty($contract)){
  116. return $this->apiResponseError('合同不存在');
  117. }
  118. //替换合同信息
  119. $file_path = $contract->{'contracts_file'};
  120. // 获取所有信息
  121. $pathInfo = pathinfo($file_path);
  122. $file_name = $pathInfo['filename'].$contract_no.'.'.$pathInfo['extension'];
  123. //替换合同信息
  124. $local_file = WordServer::creatServer()->replaceWordText($file_path,$file_name,$text_json);
  125. //上传文件到e签宝并获得文件id
  126. $file_id = ESignContractServer::creatServer()->fileUploadUrl($local_file);
  127. //获取文件状态
  128. $file_status = ESignContractServer::creatServer()->getFileStatus($file_id);
  129. dd(111);
  130. $data = compact('contract_id','contract_no','file_id','text_json','sign_json','local_file');
  131. //存入数据库
  132. $sign = SignContract::create($data);
  133. $sign_id = $sign->{'id'};
  134. if (empty($sign_id)){
  135. return $this->apiResponseError('保存失败');
  136. }
  137. //上传e签宝进行签署
  138. $result = ESignContractServer::creatServer()->setContractContract($sign_id,$file_id,$sign_json,$pathInfo['filename'].$contract_no);
  139. if ($result['code'] == 0){
  140. return $this->apiResponseError($result['msg']);
  141. }
  142. return $this->apiResponseSuccess($result['msg']);
  143. }
  144. }