input('search'); $where = [['is_del',0]]; if(!empty($search)){ $where[] = ['name','like','%'.$search.'%']; } $list = Contract::where($where) ->select(['id','name','texts','sign_party']) ->orderBy('id','desc') ->paginate(10); return $this->apiResponseSuccess('获取列表成功', [ 'items' => $list->items(), 'total' => $list->total(), 'limit' => 10, ]); } /** * 获取机构列表 * @return \Illuminate\Http\JsonResponse */ function getFirmList(){ $search=request()->input('search'); $where = [['is_del',0], ['realnameStatus',1]]; if(!empty($search)){ $where[] = ['firm_name','like','%'.$search.'%']; } $list = Firm::where($where) ->select(['id','firm_name','license_number','legal_name','authType','orgId','realnameStatus','authorizeUserInfo','created_at']) ->orderBy('id','desc') ->paginate(10); return $this->apiResponseSuccess('获取列表成功', [ 'items' => $list->items(), 'total' => $list->total(), 'limit' => 10, ]); } /** * 获取用户列表 * @return \Illuminate\Http\JsonResponse */ function getMemberList(){ $search=request()->input('search'); $where = [['is_del',0], ['realnameStatus',1]]; if(!empty($search)){ $where[] = ['name','like','%'.$search.'%']; } $list = Member::where($where) ->select(['id','name','phone','id_number','authType','psnId','realnameStatus','authorizeUserInfo','created_at']) ->orderBy('id','desc') ->paginate(10); return $this->apiResponseSuccess('获取列表成功', [ 'items' => $list->items(), 'total' => $list->total(), 'limit' => 10, ]); } /** * 获取签署列表 * @return \Illuminate\Http\JsonResponse */ function getSignContractList() { $search=request()->input('search'); $where = [['is_del',0]]; if(!empty($search)){ $where[] = ['contracts_no','like','%'.$search.'%']; } $list = SignContract::where($where) ->select(['id','contract_no','status','contract_id','sign_url','created_at']) ->orderBy('id','desc') ->paginate(10); foreach ($list as $key => $value) { $value->{'contract_name'} = Contract::where('id',$value->{'contract_id'})->value('name'); //获取用户签署链接 $psnInfo = SignRecord::where('sign_id',$value->{'id'})->where('authType','PSN')->select(['status','sign_url','id_no'])->first(); if (!empty($psnInfo)){ $psnInfo->{'name'} = Member::where('psnId',$psnInfo->{'id_no'})->value('name'); $psnInfo->initializeModel(); }else{ $psnInfo = [ 'status' => 1, 'status_str' => '待签署', 'sign_url' => '', 'id_no' => '', 'name' => '', ]; } //获取企业签署链接 $orgInfo = SignRecord::where('sign_id',$value->{'id'})->where('authType','ORG')->select(['status','sign_url','id_no'])->first(); if (!empty($orgInfo)){ $orgInfo->{'name'} = Firm::where('orgId',$orgInfo->{'id_no'})->value('firm_name'); $orgInfo->initializeModel(); }else{ $orgInfo = [ 'status' => 1, 'status_str' => '待签署', 'sign_url' => '', 'id_no' => '', 'name' => '', ]; } $value->{'psnInfo'} = $psnInfo; $value->{'orgInfo'} = $orgInfo; $value->initializeModel(); } return $this->apiResponseSuccess('获取列表成功', [ 'items' => $list->items(), 'total' => $list->total(), 'limit' => 10, ]); } /** * 创建合同签署 * @return \Illuminate\Http\JsonResponse * @throws \PhpOffice\PhpWord\Exception\Exception */ function createSignContract() { $contract_id=request()->input('contract_id','');//合同id $contract_no=request()->input('contract_no','');//合同编号 $text_json=request()->input('textsJson','');//替换文本json $sign_json=request()->input('signJson','');//签署区域信息 if(empty($contract_id)){ return $this->apiResponseError('请选择合同'); } if(empty($text_json)){ return $this->apiResponseError('请填写合同信息'); } if(empty($sign_json)){ return $this->apiResponseError('请选择签署信息'); } //获取合同信息 $contract = Contract::where(['id'=>$contract_id])->first(); if (empty($contract)){ return $this->apiResponseError('合同不存在'); } //替换合同信息 $file_path = $contract->{'contracts_file'}; // 获取所有信息 $pathInfo = pathinfo($file_path); $file_name = $pathInfo['filename'].$contract_no.'.'.$pathInfo['extension']; //替换合同信息 $local_file = WordServer::creatServer()->replaceWordText($file_path,$file_name,$text_json); //上传文件到e签宝并获得文件id $file_id = ESignContractServer::creatServer()->fileUploadUrl($local_file); $data = compact('contract_id','contract_no','file_id','text_json','sign_json','local_file'); //存入数据库 $sign = SignContract::create($data); if (empty($sign)){ return $this->apiResponseError('保存失败'); } return $this->apiResponseSuccess('保存成功'); } /** * 下载合同 * @return \Illuminate\Http\JsonResponse */ function downloadContract() { $contract_id=request()->input('contract_id','');//合同id if(empty($contract_id)){ return $this->apiResponseError('请选择合同'); } //获取合同信息 $contract = SignContract::where(['id'=>$contract_id])->first(); if (empty($contract)){ return $this->apiResponseError('合同不存在'); } if ($contract->{'status'} != 2){ return $this->apiResponseError('合同未签署完毕'); } //上传文件到e签宝并获得文件id $result = ESignContractServer::creatServer()->downloadFileUrl($contract->{'flow_id'}); if (empty($result)){ return $this->apiResponseError('获取失败'); } return $this->apiResponseSuccess('成功',$result); } }