panghu 1 gadu atpakaļ
vecāks
revīzija
39056bd33d

+ 77 - 0
app/Console/Commands/SignContractCommand.php

@@ -0,0 +1,77 @@
+<?php
+
+namespace App\Console\Commands;
+
+use App\Models\SignContract;
+use App\Servers\ESign\ESignContractServer;
+use Illuminate\Console\Command;
+
+/**
+ * 合同签署任务
+ * Class SignContractCommand
+ * @package App\Console\Commands
+ */
+class SignContractCommand extends Command
+{
+    /**
+     * The name and signature of the console command.
+     *
+     * @var string
+     */
+    protected $signature = 'sign:contract';
+
+    /**
+     * 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 mixed
+     */
+    public function handle()
+    {
+        $this->info('发起合同签署检查');
+        //获取所有文件待转的记录
+        $list = SignContract::where('status',0)->where('is_del',0)->get();
+
+        foreach ($list as $value){
+            $sign_id = $value->{'id'};
+            $file_id = $value->{'file_id'};
+            $sign_json = $value->{'sign_json'};
+            $file_path = $value->{'local_file'};
+            // 获取所有信息
+            $pathInfo = pathinfo($file_path);
+            $file_name = $pathInfo['filename'];
+
+            //获取文件状态
+            $file_status = ESignContractServer::creatServer()->getFileStatus($value->{'file_id'});
+            if(!in_array($file_status,[2,5])){
+                continue;
+            }
+            //发起合同签署
+            $result = ESignContractServer::creatServer()->setContractContract($sign_id,$file_id,$sign_json,$file_name);
+            if ($result['code'] == 0){
+                SignContract::where('id',$sign_id)->where('is_del',0)->update(['status'=>10,'msg'=>$result['msg']]);
+            }else{
+                SignContract::where('id',$sign_id)->where('is_del',0)->update(['status'=>1]);
+            }
+        }
+
+        $this->info('合同签署发起完成');
+        return true;
+    }
+}

+ 3 - 2
app/Console/Commands/TestCommand.php

@@ -26,6 +26,7 @@ use App\Servers\System\JobServer;
 use App\Servers\System\RedisDataServer;
 use App\Servers\System\SmsServer;
 use App\Servers\Wps\ExcelServer;
+use App\Servers\Wps\PdfServer;
 use App\Servers\Wps\WordServer;
 use App\Servers\Wps\WpsServer;
 use Illuminate\Console\Command;
@@ -71,9 +72,9 @@ class TestCommand extends Command
 
         $psnId= 'd1bca85014164a88b896159c799223f9';
         //获取企业内部使用签章列表
-//        ESignServer::creatServer()->internalAuthInfo(1,$psnId);
+        ESignServer::creatServer()->internalAuthInfo(1,$psnId);
 //        ESignServer::creatServer()->psnsealListInfo(1,$psnId);
-        ESignServer::creatServer()->createOrgsealsbyTemplate(1,$psnId);
+//        ESignServer::creatServer()->createOrgsealsbyTemplate(1,$psnId);
         dd(11111);
         //查询是否有合同章
         $sealItem=MemberSeal::where('m_id',1)->first();

+ 2 - 11
app/Http/Controllers/AdminApi/SignContractController.php

@@ -144,22 +144,13 @@ class SignContractController extends AdminController
         $local_file = WordServer::creatServer()->replaceWordText($file_path,$file_name,$text_json);
         //上传文件到e签宝并获得文件id
         $file_id = ESignContractServer::creatServer()->fileUploadUrl($local_file);
-        //获取文件状态
-        $file_status = ESignContractServer::creatServer()->getFileStatus($file_id);
-        dd(111);
 
         $data = compact('contract_id','contract_no','file_id','text_json','sign_json','local_file');
         //存入数据库
         $sign = SignContract::create($data);
-        $sign_id = $sign->{'id'};
-        if (empty($sign_id)){
+        if (empty($sign)){
             return $this->apiResponseError('保存失败');
         }
-        //上传e签宝进行签署
-        $result = ESignContractServer::creatServer()->setContractContract($sign_id,$file_id,$sign_json,$pathInfo['filename'].$contract_no);
-        if ($result['code'] == 0){
-            return $this->apiResponseError($result['msg']);
-        }
-        return $this->apiResponseSuccess($result['msg']);
+        return $this->apiResponseSuccess('保存成功');
     }
 }

+ 20 - 0
app/Models/SignContract.php

@@ -35,4 +35,24 @@ class SignContract extends Model
     {
         return $date->format($this->dateFormat ?: 'Y-m-d H:i:s');
     }
+
+    private $statusEnum=[
+        0=>'文件生成中',
+        1=>'待签署',
+        2=>'已签署',
+        3=>'已撤销',
+        4=>'已拒签',
+        5=>'已过期',
+        7=>'已拒签',
+        10=>'签署失败',
+    ];
+
+    /**
+     * 序列化数据字典
+     */
+    function initializeModel(){
+        if($this->{'status'}!==null){
+            $this->{'status_str'}=empty($this->statusEnum[$this->{'status'}])?'无':$this->statusEnum[$this->{'status'}];
+        }
+    }
 }

+ 42 - 31
app/Servers/ESign/ESignContractServer.php

@@ -162,7 +162,6 @@ class ESignContractServer
         //获取对应关键字定位
 //dd(111);
         $positionRet=ESignContractServer::creatServer()->getKeywordPositions($fileId,$keywords);
-        dd($positionRet);
         if(empty($positionRet['code'])){
             return ['code'=>0,'msg'=>'签署区域定位失败'];
         }else{
@@ -190,13 +189,15 @@ class ESignContractServer
             $signersData = [];
             //签署方是机构还是个人
             if ($value['auth_type'] == 'PSN'){
-                $signerType = 0;
                 $member = Member::where('psnId',$value['id_no'])->first();
                 //获取企业签章
                 $m_id = $member->{'id'};
-                $seal=MemberSeal::where('m_id',$m_id)->select(['id','seal_id'])->first();
+                $seal=MemberSeal::where('m_id',$m_id)->where('seal_status',1)->select(['id','seal_id'])->first();
+                //印章ID
+                $assignedSealId=$seal->{'seal_id'};
                 //组装信息
-                $signersData[] = [
+                $signersData = [
+                    "signerType" => 0,
                     "psnSignerInfo" => [
                         "psnAccount" => $member->{'phone'},
                         'psnInfo'=>[
@@ -205,6 +206,21 @@ class ESignContractServer
                             'psnIDCardType'=>'CRED_PSN_CH_IDCARD',
                         ],
                     ],
+                    "signFields" =>[
+                        [
+                            "fileId" =>$fileId,
+                            "normalSignFieldConfig" => [
+                                "autoSign" =>false,
+                                "signFieldStyle" =>1,
+                                "assignedSealId"=>$assignedSealId,    // 在signFields中设置 assignedSealId为授权企业印章id
+                                "signFieldPosition" => [
+                                    "positionPage" =>$value['positionPage'].'',
+                                    "positionX" =>(int)$value['positionX'],
+                                    "positionY" =>(int)$value['positionY'],
+                                ]
+                            ]
+                        ]
+                    ],
                 ];
             }else{
                 $signerType = 1;
@@ -212,7 +228,10 @@ class ESignContractServer
                 //获取用户签章
                 $firm_id = $firm->{'id'};
                 $seal=FirmSeal::where('firm_id',$firm_id)->where('seal_type','CONTRACT')->select(['id','seal_id'])->first();
-                $signersData[] = [
+                //印章ID
+                $assignedSealId=$seal->{'seal_id'};
+                $signersData = [
+                    "signerType" => 1,
                     "orgSignerInfo" => [
                         "orgName" => $firm->{'firm_name'},
                         'orgInfo'=>[
@@ -226,31 +245,24 @@ class ESignContractServer
                                 'psnIDCardType'=>'CRED_PSN_CH_IDCARD'
                             ]
                         ]
-
                     ],
-                ];
-            }
-            //印章ID
-            $assignedSealId=$seal->{'seal_id'};
-
-            $signersData[] = [
-                "signFields" =>[
-                    [
-                        "fileId" =>$fileId,
-                        "normalSignFieldConfig" => [
-                            "autoSign" =>false,
-                            "signFieldStyle" =>1,
-                            "assignedSealId"=>$assignedSealId,    // 在signFields中设置 assignedSealId为授权企业印章id
-                            "signFieldPosition" => [
-                                "positionPage" =>$value['pageNum'].'',
-                                "positionX" =>(int)$value['positionX'],
-                                "positionY" =>(int)$value['positionY'],
+                    "signFields" =>[
+                        [
+                            "fileId" =>$fileId,
+                            "normalSignFieldConfig" => [
+                                "autoSign" =>false,
+                                "signFieldStyle" =>1,
+                                "assignedSealId"=>$assignedSealId,    // 在signFields中设置 assignedSealId为授权企业印章id
+                                "signFieldPosition" => [
+                                    "positionPage" =>$value['positionPage'].'',
+                                    "positionX" =>(int)$value['positionX'],
+                                    "positionY" =>(int)$value['positionY'],
+                                ]
                             ]
                         ]
-                    ]
-                ],
-                "signerType" =>$signerType
-            ];
+                    ],
+                ];
+            }
 
             $signers[]=$signersData;
             //对应签署方做记录
@@ -259,7 +271,7 @@ class ESignContractServer
                 'authType' => $value['auth_type'],
                 'id_no' => $value['id_no'],
                 'keyword' => $value['keyword'],
-                'page_num' => $value['pageNum'],
+                'page_num' => $value['positionPage'],
                 'position_x' => $value['positionX'],
                 'position_y' => $value['positionY'],
             ]);
@@ -302,7 +314,7 @@ class ESignContractServer
                 "signFlowTitle" =>$signFlowTitle,
                 "autoStart"=>true,
                 "autoFinish"=>true,
-                'notifyUrl'=>route('notify.esignNotify')
+                'notifyUrl'=>route('adminApi.notify.esignNotify')
             ],
             "signers"=>$signers
         ];
@@ -314,8 +326,7 @@ class ESignContractServer
 //        EsignLogHelper::printMsg($signAndBuildSignAndJsonHeader);
         $response = EsignHttpHelper::doCommHttp($config['eSignHost'], $apiaddr, $requestType, $signAndBuildSignAndJsonHeader, $paramStr);
 //        EsignLogHelper::printMsg($response->getStatus());
-//        EsignLogHelper::printMsg($response->getBody());
-
+        EsignLogHelper::printMsg($response->getBody());
         $signFlowId = false;
         if($response->getStatus() == 200){
             $result = json_decode($response->getBody());

+ 8 - 23
app/Servers/ESign/ESignServer.php

@@ -173,8 +173,6 @@ class ESignServer
             $this->psnauthurl($m_id,$phone,$psnName,$id_number);
         }
 
-
-
         return $realnameStatus;
     }
 
@@ -189,16 +187,22 @@ class ESignServer
     function internalAuthInfo($mId,$psnId,$pageNum=1){
 
         $config=$this->config;
-        $apiaddr="/v3/seals/psn-seal-list?psnId=".$psnId."&pageNum={$pageNum}&pageSize=20";
+        $data['psnId'] = $psnId;
+        $data['pageNum'] = $pageNum;
+        $data['pageSize'] = 20;
+
+        ksort($data);
+        $apiaddr="/v3/seals/psn-seal-list?".http_build_query($data);
 //        var_dump($apiaddr);
         $requestType = HttpEmun::GET;
         //生成签名验签+json体的header
         $signAndBuildSignAndJsonHeader = EsignHttpHelper::signAndBuildSignAndJsonHeader($config['eSignAppId'], $config['eSignAppSecret'], "", $requestType, $apiaddr);
 //        dd($signAndBuildSignAndJsonHeader);
+//        EsignLogHelper::printMsg($signAndBuildSignAndJsonHeader);
         //发起接口请求
         $response = EsignHttpHelper::doCommHttp($config['eSignHost'], $apiaddr, $requestType, $signAndBuildSignAndJsonHeader, "");
         $ret=json_decode($response->getBody(),true);
-        dd($ret);
+
         if(isset($ret['code']) && $ret['code']==0){
             //存入签章信息
             $this->setMemberSealList($mId,$ret['data']['seals'],1);
@@ -208,25 +212,6 @@ class ESignServer
         }
     }
 
-    function psnsealListInfo($psnId){
-        $config=$this->config;
-        $apiaddr="/v3/seals/psn-seal-list?psnId=".$psnId."&pageNum=1&pageSize=20";
-        $requestType = HttpEmun::GET;
-//生成签名验签+json体的header
-        $signAndBuildSignAndJsonHeader = EsignHttpHelper::signAndBuildSignAndJsonHeader($config['eSignAppId'], $config['eSignAppSecret'], "", $requestType, $apiaddr);
-//发起接口请求
-        //发起接口请求
-        EsignLogHelper::printMsg($signAndBuildSignAndJsonHeader);
-        $response = EsignHttpHelper::doCommHttp($config['eSignHost'], $apiaddr, $requestType, $signAndBuildSignAndJsonHeader, "");
-        EsignLogHelper::printMsg($response->getStatus());
-        $code=json_decode($response->getBody())->code;
-        if($code ===0){
-            EsignLogHelper::printMsg("查询个人印章列表接口调用成功");
-            EsignLogHelper::printMsg($response->getBody());
-        }else{
-            EsignLogHelper::printMsg($response->getBody());
-        }
-    }
 
 
     /**