ZHIWEI666 commited on
Commit
f01b4f8
·
verified ·
1 Parent(s): e3ec187

Upload 7 files

Browse files
Files changed (3) hide show
  1. database_sql.py +5 -1
  2. router_tasks.py +3 -3
  3. router_wallet.py +20 -5
database_sql.py CHANGED
@@ -161,7 +161,11 @@ def _auto_migrate_p7_fields():
161
 
162
  for col_name, col_type in new_columns.items():
163
  if col_name not in columns:
164
- conn.execute(text(f"ALTER TABLE transactions ADD COLUMN {col_name} {col_type}"))
 
 
 
 
165
  logger.info(f"[DB Migration] 添加列 transactions.{col_name}")
166
 
167
  conn.commit()
 
161
 
162
  for col_name, col_type in new_columns.items():
163
  if col_name not in columns:
164
+ # VARCHAR 类型添加 DEFAULT NULL 避免 PostgreSQL NOT NULL 冲突
165
+ if col_type == 'VARCHAR':
166
+ conn.execute(text(f"ALTER TABLE transactions ADD COLUMN {col_name} {col_type} DEFAULT NULL"))
167
+ else:
168
+ conn.execute(text(f"ALTER TABLE transactions ADD COLUMN {col_name} {col_type}"))
169
  logger.info(f"[DB Migration] 添加列 transactions.{col_name}")
170
 
171
  conn.commit()
router_tasks.py CHANGED
@@ -1091,7 +1091,7 @@ async def resolve_dispute(dispute_id: str, resolution: str, ratio: int = None, n
1091
 
1092
  disputes_db = db.load_data("disputes.json", default_data=[])
1093
  tasks_db = db.load_data("tasks.json", default_data=[])
1094
- users_db = db.load_data("users.json", default_data=[])
1095
 
1096
  for dispute in disputes_db:
1097
  if dispute["id"] == dispute_id:
@@ -1106,8 +1106,8 @@ async def resolve_dispute(dispute_id: str, resolution: str, ratio: int = None, n
1106
  total_price = task.get("total_price", 0)
1107
  deposit = task.get("deposit_amount", 0)
1108
 
1109
- publisher = next((u for u in users_db if u["account"] == dispute.get("publisher")), None)
1110
- assignee = next((u for u in users_db if u["account"] == dispute.get("assignee")), None)
1111
 
1112
  is_publisher_initiator = dispute.get("initiator_role") == "publisher"
1113
  initiator = publisher if is_publisher_initiator else assignee
 
1091
 
1092
  disputes_db = db.load_data("disputes.json", default_data=[])
1093
  tasks_db = db.load_data("tasks.json", default_data=[])
1094
+ users_db = db.load_data("users.json", default_data={})
1095
 
1096
  for dispute in disputes_db:
1097
  if dispute["id"] == dispute_id:
 
1106
  total_price = task.get("total_price", 0)
1107
  deposit = task.get("deposit_amount", 0)
1108
 
1109
+ publisher = users_db.get(dispute.get("publisher"))
1110
+ assignee = users_db.get(dispute.get("assignee"))
1111
 
1112
  is_publisher_initiator = dispute.get("initiator_role") == "publisher"
1113
  initiator = publisher if is_publisher_initiator else assignee
router_wallet.py CHANGED
@@ -45,6 +45,22 @@ from verify_code_engine import VERIFY_CODES
45
 
46
  router = APIRouter()
47
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
48
  # ==========================================
49
  # 🚨 替换这里的支付宝初始化逻辑 🚨
50
  # ==========================================
@@ -577,8 +593,8 @@ async def withdraw(request: Request, req: WithdrawRequest, db: Session = Depends
577
  tx_hash = calculate_tx_hash(tx_id, req.account, "WITHDRAW", -actual_withdraw, prev_hash)
578
 
579
  # 脱敏支付宝账号和姓名
580
- masked_alipay = req.alipayAccount[:3] + "****" + req.alipayAccount[-4:] if len(req.alipayAccount) > 7 else req.alipayAccount
581
- masked_name = req.real_name[0] + "*" * (len(req.real_name) - 1) if req.real_name else ""
582
 
583
  new_tx = Transaction(
584
  tx_id=tx_id, account=req.account, tx_type="WITHDRAW", amount=-actual_withdraw,
@@ -668,10 +684,9 @@ async def get_transactions(
668
  if tx.tx_type == "WITHDRAW":
669
  # 脱敏支付宝账号
670
  if tx.alipay_account:
671
- a = tx.alipay_account
672
- tx_data["alipay_account"] = a[:3] + "****" + a[-4:] if len(a) > 7 else a
673
  if tx.real_name:
674
- tx_data["real_name"] = tx.real_name[0] + "*" * (len(tx.real_name) - 1)
675
  tx_data["withdraw_status"] = tx.withdraw_status
676
  tx_data["net_amount"] = tx.net_amount
677
 
 
45
 
46
  router = APIRouter()
47
 
48
+ # ==========================================
49
+ # 脱敏工具函数
50
+ # ==========================================
51
+ def _mask_alipay(account):
52
+ """脱敏支付宝账号"""
53
+ if account and len(account) >= 7:
54
+ return account[:3] + "****" + account[-4:]
55
+ return account or ""
56
+
57
+ def _mask_name(name):
58
+ """脱敏姓名"""
59
+ if name and len(name) > 0:
60
+ return name[0] + "*" * (len(name) - 1)
61
+ return name or ""
62
+
63
+
64
  # ==========================================
65
  # 🚨 替换这里的支付宝初始化逻辑 🚨
66
  # ==========================================
 
593
  tx_hash = calculate_tx_hash(tx_id, req.account, "WITHDRAW", -actual_withdraw, prev_hash)
594
 
595
  # 脱敏支付宝账号和姓名
596
+ masked_alipay = _mask_alipay(req.alipayAccount)
597
+ masked_name = _mask_name(req.real_name)
598
 
599
  new_tx = Transaction(
600
  tx_id=tx_id, account=req.account, tx_type="WITHDRAW", amount=-actual_withdraw,
 
684
  if tx.tx_type == "WITHDRAW":
685
  # 脱敏支付宝账号
686
  if tx.alipay_account:
687
+ tx_data["alipay_account"] = _mask_alipay(tx.alipay_account)
 
688
  if tx.real_name:
689
+ tx_data["real_name"] = _mask_name(tx.real_name)
690
  tx_data["withdraw_status"] = tx.withdraw_status
691
  tx_data["net_amount"] = tx.net_amount
692