|
@@ -65,61 +65,21 @@ class WordServer
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 合同保存的时候生成文本替换内容
|
|
* 合同保存的时候生成文本替换内容
|
|
|
- * @param FactoringContractFile $file
|
|
|
|
|
- * @return FactoringContractFile|\Illuminate\Database\Eloquent\Model
|
|
|
|
|
* @throws \PhpOffice\PhpWord\Exception\Exception
|
|
* @throws \PhpOffice\PhpWord\Exception\Exception
|
|
|
*/
|
|
*/
|
|
|
- function replaceWordText(FactoringContractFile $file)
|
|
|
|
|
|
|
+ function replaceWordText($file_path,$file_name,$json)
|
|
|
{
|
|
{
|
|
|
- $filePath=public_path($file->{'file_path'});
|
|
|
|
|
|
|
+ $filePath=public_path($file_path);
|
|
|
$phpWord = new TemplateProcessor($filePath);
|
|
$phpWord = new TemplateProcessor($filePath);
|
|
|
- $texts=FactoringContractText::where('level','2')->where('custom','<>','')->select(['id','custom','key'])->get();
|
|
|
|
|
- //获取项目合同
|
|
|
|
|
- $factoring_contract = FactoringContract::where('file_no',$file->{'file_no'})->first();
|
|
|
|
|
- //获取对应项目
|
|
|
|
|
- $factoring = Factoring::where('id',$factoring_contract->{'factoring_id'})->first();
|
|
|
|
|
- //获取资产
|
|
|
|
|
- $property = FactoringProperty::whereIn('id',$factoring_contract->{'property'})->get();
|
|
|
|
|
- foreach ($texts as $text){
|
|
|
|
|
- if(in_array($text->{'key'},['zrf_seal','bls_seal'])){
|
|
|
|
|
- continue;
|
|
|
|
|
- }
|
|
|
|
|
- $keyData=explode(':',$text['key']);
|
|
|
|
|
- if(count($keyData)!=2)continue;
|
|
|
|
|
- if ($keyData[0]=='property'){
|
|
|
|
|
- //如果涉及到资产
|
|
|
|
|
- $str = $this->getPropertyTextKey($property,$keyData[1]);
|
|
|
|
|
- }elseif($keyData[0]=='contract'){
|
|
|
|
|
- //合同和项目基础信息
|
|
|
|
|
- $str = $this->getContractTextKey($factoring_contract,$keyData[1]);
|
|
|
|
|
- }elseif(in_array($keyData[0],['zrf','yszw','hxqy','bls'])){
|
|
|
|
|
- //合同和项目基础信息
|
|
|
|
|
- $str = $this->getPropertyFirmTextKey($property,$keyData[1],$keyData[0]);
|
|
|
|
|
- }elseif($keyData[0]=='earning'){
|
|
|
|
|
- //合同和项目基础信息
|
|
|
|
|
- $str = $this->getEarningTextKey($factoring,$keyData[1]);
|
|
|
|
|
- }
|
|
|
|
|
- if(empty($str))continue;
|
|
|
|
|
- $text['custom']=str_replace(['${','}'],'',$text['custom']);
|
|
|
|
|
- $phpWord->setValue($text['custom'], $str);
|
|
|
|
|
- }
|
|
|
|
|
- $file_path = 'contractComplete/' . date('Ymd') . '/'.$file['file_no'].'/'.$file['version'].'/';
|
|
|
|
|
- CommonServer::creatServer()->creatDir('storage/'.$file_path);
|
|
|
|
|
- $file_name = $file->{'file_name'};
|
|
|
|
|
- $phpWord->saveAs(public_path('storage/'.$file_path.$file_name));
|
|
|
|
|
- $file_url = 'https://'.env('APP_ADMIN_HOST').'/storage/'.$file_path.$file_name;
|
|
|
|
|
- $res = FactoringContractFile::create([
|
|
|
|
|
- 'file_no' => $file['file_no'],
|
|
|
|
|
- 'file_name' => $file_name,
|
|
|
|
|
- 'file_url' => $file_url,
|
|
|
|
|
- 'file_path' => $file_path.$file_name,
|
|
|
|
|
- 'version' => $file['version'],
|
|
|
|
|
- 'type' => 2,
|
|
|
|
|
- 'is_end' => 1,
|
|
|
|
|
- ]);
|
|
|
|
|
- $factoring_contract->update(['contracts_file' => $file_url,'end_file_id'=>$res['id']]);
|
|
|
|
|
- return $res;
|
|
|
|
|
|
|
|
|
|
|
|
+ $data = json_decode($json,true);
|
|
|
|
|
+ foreach ($data as $key=>$text){
|
|
|
|
|
+ $custom='{$' . $key . '}';
|
|
|
|
|
+ $phpWord->setValue($custom, $text);
|
|
|
|
|
+ }
|
|
|
|
|
+ CommonServer::creatServer()->creatDir('storage/contractComplete');
|
|
|
|
|
+ $phpWord->saveAs(public_path('storage/contractComplete/'.$file_name));
|
|
|
|
|
+ return true;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|