ソースを参照

更改数据存储规则:根据store_id 存储

mengqiankang 2 ヶ月 前
コミット
68710e1ece
2 ファイル変更29 行追加6 行削除
  1. 13 6
      alien_store/repositories/contract_repo.py
  2. 16 0
      test.py

+ 13 - 6
alien_store/repositories/contract_repo.py

@@ -281,12 +281,16 @@ class ContractRepository:
 
     async def append_contract_url(self, templates_data, contract_item: dict):
         """
-        根据手机号,向 contract_url(JSON 列表)追加新的合同信息;
-        若手机号不存在,则创建新记录。
+        根据 store_id,向 contract_url(JSON 列表)追加新的合同信息;
+        若 store_id 不存在,则创建新记录。
         """
-        contact_phone = getattr(templates_data, "contact_phone", None)
+        store_id = getattr(templates_data, "store_id", None)
+        if store_id is None:
+            logger.error("append_contract_url missing store_id")
+            return False
+
         result = await self._execute_with_retry(
-            ContractStore.__table__.select().where(ContractStore.contact_phone == contact_phone)
+            ContractStore.__table__.select().where(ContractStore.store_id == store_id)
         )
         rows = result.mappings().all()
         updated = False
@@ -304,6 +308,9 @@ class ContractRepository:
                 update_values = {"contract_url": json.dumps(items, ensure_ascii=False)}
                 if store_name:
                     update_values["store_name"] = store_name
+                contact_phone = getattr(templates_data, "contact_phone", None)
+                if contact_phone:
+                    update_values["contact_phone"] = contact_phone
                 await self._execute_with_retry(
                     ContractStore.__table__.update()
                     .where(ContractStore.id == row["id"])
@@ -315,11 +322,11 @@ class ContractRepository:
             return updated
         # 未找到则创建新记录
         new_record = ContractStore(
-            store_id=getattr(templates_data, "store_id", None),
+            store_id=store_id,
             store_name=store_name,
             business_segment=getattr(templates_data, "business_segment", None),
             merchant_name=getattr(templates_data, "merchant_name", None),
-            contact_phone=contact_phone,
+            contact_phone=getattr(templates_data, "contact_phone", None),
             contract_url=json.dumps([contract_item], ensure_ascii=False),
             seal_url='0.0',
             signing_status='未签署'

+ 16 - 0
test.py

@@ -0,0 +1,16 @@
+import requests
+
+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"
+}
+
+res = requests.post(url, json=body)
+print(res.text)