|
|
@@ -50,7 +50,8 @@ class ContractRepository:
|
|
|
async def mark_signed_by_phone(self, contact_phone: str, sign_flow_id: str, signing_time: datetime | None = None):
|
|
|
"""
|
|
|
根据手机号 + sign_flow_id 将合同标记为已签署,只更新匹配的合同项
|
|
|
- 同时写入签署/生效/到期时间(签署时间=T,生效=T+1天,失效=生效+365天)
|
|
|
+ 当 is_master 为 1 时,更新签署状态和时间字段
|
|
|
+ 同时写入签署/生效/到期时间(签署时间=T,生效=T+1天0点,失效=生效+365天)
|
|
|
"""
|
|
|
result = await self.db.execute(
|
|
|
ContractStore.__table__.select().where(ContractStore.contact_phone == contact_phone)
|
|
|
@@ -66,18 +67,30 @@ class ContractRepository:
|
|
|
except Exception:
|
|
|
items = None
|
|
|
changed = False
|
|
|
+ matched_item = None
|
|
|
if isinstance(items, list):
|
|
|
for item in items:
|
|
|
if item.get("sign_flow_id") == sign_flow_id:
|
|
|
item["status"] = 1
|
|
|
+ matched_item = item
|
|
|
changed = True
|
|
|
- # 时间处理
|
|
|
- signing_dt = signing_time
|
|
|
- effective_dt = expiry_dt = None
|
|
|
- if signing_dt:
|
|
|
- effective_dt = signing_dt + timedelta(days=1)
|
|
|
- expiry_dt = effective_dt + timedelta(days=365)
|
|
|
- if changed:
|
|
|
+ break
|
|
|
+
|
|
|
+ # 只有当 is_master 为 1 时才更新时间字段
|
|
|
+ if changed and matched_item and matched_item.get("is_master") == 1:
|
|
|
+ # 时间处理
|
|
|
+ signing_dt = signing_time
|
|
|
+ effective_dt = expiry_dt = None
|
|
|
+ if signing_dt:
|
|
|
+ # effective_time 是 signing_time 第二天的 0 点
|
|
|
+ effective_dt = (signing_dt + timedelta(days=1)).replace(hour=0, minute=0, second=0, microsecond=0)
|
|
|
+ expiry_dt = effective_dt + timedelta(days=365)
|
|
|
+
|
|
|
+ # 更新 contract_url 中对应字典的时间字段
|
|
|
+ matched_item["signing_time"] = signing_dt.strftime("%Y-%m-%d %H:%M:%S") if signing_dt else ""
|
|
|
+ matched_item["effective_time"] = effective_dt.strftime("%Y-%m-%d %H:%M:%S") if effective_dt else ""
|
|
|
+ matched_item["expiry_time"] = expiry_dt.strftime("%Y-%m-%d %H:%M:%S") if expiry_dt else ""
|
|
|
+
|
|
|
await self.db.execute(
|
|
|
ContractStore.__table__.update()
|
|
|
.where(ContractStore.id == row["id"])
|
|
|
@@ -90,6 +103,16 @@ class ContractRepository:
|
|
|
)
|
|
|
)
|
|
|
updated = True
|
|
|
+ elif changed:
|
|
|
+ # is_master 不为 1 时,只更新 status,不更新时间字段
|
|
|
+ await self.db.execute(
|
|
|
+ ContractStore.__table__.update()
|
|
|
+ .where(ContractStore.id == row["id"])
|
|
|
+ .values(
|
|
|
+ contract_url=json.dumps(items, ensure_ascii=False) if items else contract_url_raw,
|
|
|
+ )
|
|
|
+ )
|
|
|
+ updated = True
|
|
|
if updated:
|
|
|
await self.db.commit()
|
|
|
return updated
|