|
|
@@ -0,0 +1,193 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace App\Http\Controllers\Api;
|
|
|
+
|
|
|
+use App\Http\Controllers\ApiController;
|
|
|
+use App\Models\Contract;
|
|
|
+use App\Models\Firm;
|
|
|
+use App\Models\Member;
|
|
|
+use App\Models\SignContract;
|
|
|
+use App\Models\SignRecord;
|
|
|
+use App\Servers\ESign\ESignContractServer;
|
|
|
+use App\Servers\Wps\WordServer;
|
|
|
+
|
|
|
+class SignController extends ApiController
|
|
|
+{
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 创建合同签署
|
|
|
+ * @return \Illuminate\Http\JsonResponse
|
|
|
+ * @throws \PhpOffice\PhpWord\Exception\Exception
|
|
|
+ */
|
|
|
+ function createSignContract()
|
|
|
+ {
|
|
|
+ $contract_id=9;
|
|
|
+ $id_number=request()->input('id_number','');//身份证号
|
|
|
+ $license_number = request()->input('license_number','');//营业执照编号
|
|
|
+ $contract_no=request()->input('order_no','');//合同编号为订单编号
|
|
|
+ $project_name = request()->input('project_name','');//项目名称
|
|
|
+ $total_money = request()->input('total_money','');//项目总资产
|
|
|
+ $liability = request()->input('liability','');//负债率
|
|
|
+ $turnover = request()->input('turnover','');//月均营业额
|
|
|
+ $profit_rate = request()->input('profit_rate','');//年利润率
|
|
|
+ $year = request()->input('year','');//消费押金年限
|
|
|
+ $order_money = request()->input('order_money','');//消费金额
|
|
|
+ $start_year = request()->input('start_year','');//合作开始年
|
|
|
+ $start_month = request()->input('start_month','');//合作开始月
|
|
|
+ $start_day = request()->input('start_day','');//合作开始日
|
|
|
+ $end_year = request()->input('end_year','');//合作结束始年
|
|
|
+ $end_month = request()->input('end_month','');//合作结束月
|
|
|
+ $end_day = request()->input('end_day','');//合作结束日
|
|
|
+
|
|
|
+ if(empty($id_number)){
|
|
|
+ return $this->apiResponseError('请填写身份证号');
|
|
|
+ }
|
|
|
+ if(empty($license_number)){
|
|
|
+ return $this->apiResponseError('请输入营业执照编号');
|
|
|
+ }
|
|
|
+
|
|
|
+ if(empty($project_name)){
|
|
|
+ return $this->apiResponseError('请填写项目名称');
|
|
|
+ }
|
|
|
+ if(empty($total_money)){
|
|
|
+ return $this->apiResponseError('请输入项目总资产');
|
|
|
+ }
|
|
|
+ if(empty($liability)){
|
|
|
+ return $this->apiResponseError('请输入项目负债率');
|
|
|
+ }
|
|
|
+ if(empty($turnover)){
|
|
|
+ return $this->apiResponseError('请输入月均营业额');
|
|
|
+ }
|
|
|
+ if(empty($profit_rate)){
|
|
|
+ return $this->apiResponseError('请输入年利润率');
|
|
|
+ }
|
|
|
+ if(empty($year)){
|
|
|
+ return $this->apiResponseError('请输入合作年限');
|
|
|
+ }
|
|
|
+ if(empty($order_money)){
|
|
|
+ return $this->apiResponseError('请输入消费金额');
|
|
|
+ }
|
|
|
+ if(empty($start_year) || empty($start_month) || empty($start_day) || empty($end_year) || empty($end_month) || empty($end_day)){
|
|
|
+ return $this->apiResponseError('请输入合作期限日期');
|
|
|
+ }
|
|
|
+ //获取企业信息
|
|
|
+ $firm = Firm::where('license_number',$license_number)->select(['firm_name','license_number','realnameStatus','registered_address','phone','legal_name','orgId'])->first();
|
|
|
+ if (empty($firm)) {
|
|
|
+ return $this->apiResponseError('该企业不存在');
|
|
|
+ }
|
|
|
+ //获取用户信息
|
|
|
+ $member = Member::where('id_number',$id_number)->where('is_del',0)->select(['id_number','realnameStatus','phone','name','psnId'])->first();
|
|
|
+ if (empty($member)){
|
|
|
+ return $this->apiResponseError('该用户不存在');
|
|
|
+ }
|
|
|
+ //合同替换内容
|
|
|
+ $text_data['jName'] = $firm->firm_name;
|
|
|
+ $text_data['yName'] = $member->name;
|
|
|
+ $text_data['projectName'] = $project_name;
|
|
|
+ $text_data['totalMoney'] = $total_money;
|
|
|
+ $text_data['liability'] = $liability;
|
|
|
+ $text_data['turnover'] = $turnover;
|
|
|
+ $text_data['profitRate'] = $profit_rate;
|
|
|
+ $text_data['year'] = $year;
|
|
|
+ $text_data['orderMoney'] = $order_money;
|
|
|
+ $text_data['startYear'] = $start_year;
|
|
|
+ $text_data['startMonth'] = $start_month;
|
|
|
+ $text_data['startDay'] = $start_day;
|
|
|
+ $text_data['endYear'] = $end_year;
|
|
|
+ $text_data['endMonth'] = $end_month;
|
|
|
+ $text_data['endDay'] = $end_day;
|
|
|
+ $text_data['jLegalName'] = $firm->legal_name;
|
|
|
+ $text_data['jPhone'] = $firm->phone;
|
|
|
+ $text_data['jAddress'] = $firm->registered_address;
|
|
|
+ $text_data['yIdNumber'] = $member->id_number;
|
|
|
+ $text_data['yPhone'] = $member->phone;
|
|
|
+ $text_data['yAddress'] = '无';
|
|
|
+
|
|
|
+ $text_json = json_encode($text_data);
|
|
|
+ //签章区域内容
|
|
|
+ $sign_data = [
|
|
|
+ [
|
|
|
+ 'keyword' => '甲方(签字/盖章)',
|
|
|
+ 'auth_type' => 'ORG',
|
|
|
+ 'id_no' => $firm->orgId,
|
|
|
+ ],
|
|
|
+ [
|
|
|
+ 'keyword' => '乙方(签字/盖章)',
|
|
|
+ 'auth_type' => 'PSN',
|
|
|
+ 'id_no' => $member->psnId,
|
|
|
+ ],
|
|
|
+ ];
|
|
|
+ $sign_json = json_encode($sign_data);
|
|
|
+
|
|
|
+
|
|
|
+ //获取合同信息
|
|
|
+ $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('保存失败');
|
|
|
+ }
|
|
|
+ $sign_id = $sign->id;
|
|
|
+ return $this->apiResponseSuccess('保存成功',['sign_id'=>$sign_id]);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取签署记录
|
|
|
+ * @return \Illuminate\Http\JsonResponse
|
|
|
+ */
|
|
|
+ function getSignRecord()
|
|
|
+ {
|
|
|
+ $sign_id=request()->input('sign_id','');//合同id
|
|
|
+ if(empty($sign_id)){
|
|
|
+ return $this->apiResponseError('请选择签订记录');
|
|
|
+ }
|
|
|
+ $list = SignRecord::where('sign_id',$sign_id)
|
|
|
+ ->where('is_del',0)
|
|
|
+ ->select(['authType','status'])
|
|
|
+ ->get();
|
|
|
+
|
|
|
+ return $this->apiResponseSuccess('成功',$list);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 下载合同
|
|
|
+ * @return \Illuminate\Http\JsonResponse
|
|
|
+ */
|
|
|
+ function downloadContract()
|
|
|
+ {
|
|
|
+ $sign_id=request()->input('sign_id','');//合同id
|
|
|
+ if(empty($sign_id)){
|
|
|
+ return $this->apiResponseError('请选择签订记录');
|
|
|
+ }
|
|
|
+
|
|
|
+ //获取合同信息
|
|
|
+ $contract = SignContract::where(['id'=>$sign_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);
|
|
|
+ }
|
|
|
+}
|