ZHIWEI666 commited on
Commit
d6cee16
·
verified ·
1 Parent(s): c71735f

同步就提现数据

Browse files
Files changed (2) hide show
  1. database_sql.py +19 -0
  2. router_wallet.py +9 -4
database_sql.py CHANGED
@@ -162,6 +162,25 @@ def _auto_migrate_p7_fields():
162
 
163
  conn.commit()
164
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
165
  except Exception as e:
166
  logger.warning(f"字段迁移跳过 (可能已存在): {e}")
167
 
 
162
 
163
  conn.commit()
164
 
165
+ # ========== 3. 回填旧提现记录数据 ==========
166
+ # 将旧 WITHDRAW 记录的 withdraw_status 从 NULL 更新为 "completed"
167
+ result = conn.execute(text(
168
+ "UPDATE transactions SET withdraw_status = 'completed' "
169
+ "WHERE tx_type = 'WITHDRAW' AND withdraw_status IS NULL"
170
+ ))
171
+ if result.rowcount > 0:
172
+ logger.info(f"[DB Migration] 回填旧提现记录: 更新 {result.rowcount} 条记录的 withdraw_status 为 'completed'")
173
+
174
+ # 将旧记录的 net_amount 从 NULL 更新为 ABS(amount)
175
+ result = conn.execute(text(
176
+ "UPDATE transactions SET net_amount = ABS(amount) "
177
+ "WHERE tx_type = 'WITHDRAW' AND net_amount IS NULL"
178
+ ))
179
+ if result.rowcount > 0:
180
+ logger.info(f"[DB Migration] 回填旧提现记录: 更新 {result.rowcount} 条记录的 net_amount 为 ABS(amount)")
181
+
182
+ conn.commit()
183
+
184
  except Exception as e:
185
  logger.warning(f"字段迁移跳过 (可能已存在): {e}")
186
 
router_wallet.py CHANGED
@@ -883,7 +883,12 @@ async def get_admin_withdrawals(
883
 
884
  query = db.query(Transaction).filter(Transaction.tx_type == "WITHDRAW")
885
  if status:
886
- query = query.filter(Transaction.withdraw_status == status)
 
 
 
 
 
887
 
888
  records = query.order_by(Transaction.created_at.desc()).all()
889
 
@@ -893,9 +898,9 @@ async def get_admin_withdrawals(
893
  "tx_id": r.tx_id,
894
  "account": r.account,
895
  "amount": r.amount,
896
- "alipay_account": r.alipay_account,
897
- "real_name": r.real_name,
898
- "withdraw_status": r.withdraw_status,
899
  "payment_order_id": r.payment_order_id,
900
  "created_at": r.created_at.isoformat() if r.created_at else None
901
  } for r in records]
 
883
 
884
  query = db.query(Transaction).filter(Transaction.tx_type == "WITHDRAW")
885
  if status:
886
+ # 当查询 completed 状态时,同时包含 withdraw_status == "completed" 和 withdraw_status IS NULL(兼容旧数据)
887
+ if status == "completed":
888
+ from sqlalchemy import or_
889
+ query = query.filter(or_(Transaction.withdraw_status == status, Transaction.withdraw_status.is_(None)))
890
+ else:
891
+ query = query.filter(Transaction.withdraw_status == status)
892
 
893
  records = query.order_by(Transaction.created_at.desc()).all()
894
 
 
898
  "tx_id": r.tx_id,
899
  "account": r.account,
900
  "amount": r.amount,
901
+ "alipay_account": r.alipay_account if r.alipay_account else "未记录",
902
+ "real_name": r.real_name if r.real_name else "未记录",
903
+ "withdraw_status": r.withdraw_status if r.withdraw_status else "completed",
904
  "payment_order_id": r.payment_order_id,
905
  "created_at": r.created_at.isoformat() if r.created_at else None
906
  } for r in records]