panghu 1 yıl önce
ebeveyn
işleme
69b5ef1c92

+ 72 - 0
app/Console/Commands/TestCommand.php

@@ -0,0 +1,72 @@
+<?php
+
+namespace App\Console\Commands;
+
+use App\Mail\ExampleEmail;
+use App\Models\Factoring;
+use App\Models\FactoringContract;
+use App\Models\FactoringContractFile;
+use App\Models\FactoringProperty;
+use App\Models\Firm;
+use App\Models\IndentNum;
+use App\Models\Member;
+use App\Models\SignMember;
+use App\Models\SignSeal;
+use App\Models\SignSealAuth;
+use App\Servers\ESign\comm\EsignLogHelper;
+use App\Servers\ESign\ESignContractServer;
+use App\Servers\ESign\ESignFirmServer;
+use App\Servers\ESign\ESignServer;
+use App\Servers\Financing\ContractServer;
+use App\Servers\Financing\FinancingServer;
+use App\Servers\Firm\FirmServer;
+use App\Servers\System\EmailServer;
+use App\Servers\System\JobServer;
+use App\Servers\System\RedisDataServer;
+use App\Servers\System\SmsServer;
+use App\Servers\Wps\ExcelServer;
+use App\Servers\Wps\WordServer;
+use App\Servers\Wps\WpsServer;
+use Illuminate\Console\Command;
+use Illuminate\Support\Facades\Log;
+use Illuminate\Support\Facades\Storage;
+
+class TestCommand extends Command
+{
+    /**
+     * The name and signature of the console command.
+     *
+     * @var string
+     */
+    protected $signature = 'test';
+
+    /**
+     * The console command description.
+     *
+     * @var string
+     */
+    protected $description = '测试命令';
+
+    /**
+     * Create a new command instance.
+     *
+     * @return void
+     */
+    public function __construct()
+    {
+        parent::__construct();
+    }
+
+    /**
+     * Execute the console command.
+     *
+     * @return int
+     */
+    public function handle()
+    {
+        $file_path = 'storage/contract/测试.docx';
+        $json = '{"name": "江雨","text":"测试一下","phone":"13012341234"}';
+        $file = WordServer::creatServer()->replaceWordText($file_path,'123.docx',$json);
+        dd($file);
+    }
+}

+ 6 - 3
app/Http/Controllers/AdminApi/ContractController.php

@@ -46,15 +46,18 @@ class ContractController extends AdminController
         if (empty($file)){
             return $this->apiResponseError('请选择文件');
         }
-        //检查合同名称是否存在
 
+        //检查合同名称是否存在
         $info = Contract::where('name',$name)->where('is_del',0)->select(['id'])->first();
         if (!empty($info)) {
             return $this->apiResponseError('合同名称已存在');
         }
 
-        $file_name = $file->{'file_name'};
-        $contracts_file = Storage::put($file_name, $file, 'public/contract');
+        $extension = request()->file->extension();//获取文件扩展名
+        $file_name = $name.'.'.$extension;
+        $contracts_file = request()->file->storeAs('public/contract', $file_name);
+
+
 
         $data = compact('name','contracts_file');
 

+ 10 - 50
app/Servers/Wps/WordServer.php

@@ -65,61 +65,21 @@ class WordServer
 
     /**
      * 合同保存的时候生成文本替换内容
-     * @param FactoringContractFile $file
-     * @return FactoringContractFile|\Illuminate\Database\Eloquent\Model
      * @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);
-        $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;
     }
 
 

+ 0 - 2
storage/app/public/.gitignore

@@ -1,2 +0,0 @@
-*
-!.gitignore