瀏覽代碼

更改过期合同

mengqiankang 2 月之前
父節點
當前提交
eb029d56d6
共有 3 個文件被更改,包括 60 次插入12 次删除
  1. 29 1
      alien_store/api/router.py
  2. 10 0
      common/esigntool/main.py
  3. 21 11
      test.py

+ 29 - 1
alien_store/api/router.py

@@ -16,6 +16,7 @@ from alien_store.schemas.response.contract_store import (
 )
 from alien_store.services.contract_server import ContractServer
 from common.esigntool.main import *
+from common.esigntool import main as esign_main
 import re, urllib.parse
 
 # ------------------- 日志配置 -------------------
@@ -201,9 +202,36 @@ async def get_contract_detail(
 
     status = item.get("status")
     if status == 0:
+        file_id = item.get("file_id")
+        if not file_id:
+            return ErrorResponse(success=False, message="缺少 file_id,无法获取合同详情")
+        try:
+            detail_resp = esign_main.get_contract_detail(file_id)
+            detail_json = json.loads(detail_resp)
+            data = detail_json.get("data") if isinstance(detail_json, dict) else None
+            contract_url = None
+            if isinstance(data, dict):
+                contract_url = data.get("fileDownloadUrl")
+            if not contract_url and isinstance(detail_json, dict):
+                contract_url = detail_json.get("fileDownloadUrl")
+        except Exception as e:
+            logger.error(f"get_contract_detail failed file_id={file_id}: {e}")
+            return ErrorResponse(success=False, message="获取合同链接失败", raw=str(e))
+
+        if not contract_url:
+            logger.error(f"get_contract_detail missing contract_url file_id={file_id}: {detail_resp}")
+            return ErrorResponse(success=False, message="e签宝返回缺少合同链接", raw=detail_resp)
+
+        if row and isinstance(items, list):
+            for it in items:
+                if it.get("sign_flow_id") == sign_flow_id:
+                    it["contract_url"] = contract_url
+                    break
+            await templates_server.update_contract_items(row["id"], items)
+
         return {
             "status": 0,
-            "contract_url": item.get("contract_url", ""),
+            "contract_url": contract_url,
             "sign_url": item.get("sign_url", ""),
             "sign_flow_id": sign_flow_id
         }

+ 10 - 0
common/esigntool/main.py

@@ -97,6 +97,16 @@ def fill_in_template(name):
     print(resp.text)
     return resp.text
 
+def get_contract_detail(file_id):
+    """查询PDF模板填写后文件"""
+    api_path = f"/v3/files/{file_id}"
+    method = "GET"
+    json_headers = buildSignJsonHeader(config.appId, config.scert, method, api_path)
+    resp = requests.request(method, config.host + api_path, headers=json_headers)
+    print(resp.text)
+    return resp.text
+
+get_contract_detail("f0371b4ae7c64c8ca16be3bf031d1d6e")
 # def create_by_file(file_id, file_name,  contact_phone, merchant_name):
 #     """基于文件发起签署"""
 #     api_path = "/v3/sign-flow/create-by-file"

+ 21 - 11
test.py

@@ -1,16 +1,26 @@
 import requests
 
-url = "http://127.0.0.1:8001/api/store/get_esign_templates"
+# url = "http://127.0.0.1:8001/api/store/get_esign_templates"
 # url = "http://120.26.186.130:33333/api/store/get_esign_templates"
 
-body = {
-    "store_id": 999,
-    "store_name": "爱丽恩严(大连)商务科技有限公司深圳分公司",
-    "business_segment": "生活服务",
-    "merchant_name": "彭少荣",
-    "contact_phone": "13923864580",
-    "ord_id": "91440300MADDW7XC4C"
-}
+# body = {
+#     "store_id": 999,
+#     "store_name": "爱丽恩严(大连)商务科技有限公司深圳分公司",
+#     "business_segment": "生活服务",
+#     "merchant_name": "彭少荣",
+#     "contact_phone": "13923864580",
+#     "ord_id": "91440300MADDW7XC4C"
+# }
 
-res = requests.post(url, json=body)
-print(res.text)
+# res = requests.post(url, json=body)
+# print(res.text)
+
+url = "http://127.0.0.1:8001/api/store/contracts/400"
+resp = requests.get(url)
+print(resp.text)
+
+
+
+# url = "http://127.0.0.1:8001/api/store/contracts/detail/c2259cb97f3f4066b7bca57a62e3843a"
+# resp = requests.get(url)
+# print(resp.text)