ZHIWEI666 commited on
Commit
3b9e29d
·
verified ·
1 Parent(s): c6147cc

Upload 3 files

Browse files
Files changed (3) hide show
  1. models_sql.py +4 -4
  2. requirements.txt +17 -17
  3. router_wallet.py +7 -7
models_sql.py CHANGED
@@ -16,10 +16,10 @@ class Wallet(Base):
16
  __tablename__ = "wallets"
17
 
18
  account = Column(String, primary_key=True, index=True)
19
- balance = Column(Integer, default=0) # 用于消费的余额 (充值获得)
20
- earn_balance = Column(Integer, default=0) # 创作者销售收益余额 (别人购买获得)
21
- tip_balance = Column(Integer, default=0) # 【新增】创作者打赏收益余额 (粉丝赞助获得)
22
- frozen_balance = Column(Integer, default=0) # 提现审核冻结中的余额
23
 
24
  # 乐观锁版本号,防止并发扣款被击穿
25
  version = Column(Integer, default=1)
 
16
  __tablename__ = "wallets"
17
 
18
  account = Column(String, primary_key=True, index=True)
19
+ balance = Column(Integer, default=0, nullable=False) # 用于消费的余额 (充值获得)
20
+ earn_balance = Column(Integer, default=0, nullable=False) # 创作者销售收益余额 (别人购买获得)
21
+ tip_balance = Column(Integer, default=0, nullable=False) # 【新增】创作者打赏收益余额 (粉丝赞助获得)
22
+ frozen_balance = Column(Integer, default=0, nullable=False) # 提现审核冻结中的余额
23
 
24
  # 乐观锁版本号,防止并发扣款被击穿
25
  version = Column(Integer, default=1)
requirements.txt CHANGED
@@ -1,18 +1,18 @@
1
- # 🔒 P0安全修复:依赖版本锁定,防止供应链攻击和不兼容更新
2
- fastapi==0.104.1
3
- uvicorn==0.24.0
4
- pydantic==2.5.2
5
- huggingface_hub==0.19.4
6
- datasets==2.15.0
7
- python-multipart==0.0.6
8
- alibabacloud_dysmsapi20170525==2.0.24
9
- sqlalchemy==2.0.23
10
- psycopg2-binary==2.9.9
11
- httpx==0.25.2
12
- aiofiles==23.2.1
13
- # 🚀 P2优化:速率限制
14
- slowapi==0.1.9
15
- # 🔒 P0安全增强:bcrypt密码哈希
16
- bcrypt==4.1.2
17
- # 🔧 P0修复:升级支付宝SDK,打破旧版死锁,自动适配最新安全加密库
18
  python-alipay-sdk>=3.3.0
 
1
+ # 🔒 P0安全修复:依赖版本锁定,防止供应链攻击和不兼容更新
2
+ fastapi==0.104.1
3
+ uvicorn==0.24.0
4
+ pydantic==2.5.2
5
+ huggingface_hub==0.19.4
6
+ datasets==2.15.0
7
+ python-multipart==0.0.6
8
+ alibabacloud_dysmsapi20170525==2.0.24
9
+ sqlalchemy==2.0.23
10
+ psycopg2-binary==2.9.9
11
+ httpx==0.25.2
12
+ aiofiles==23.2.1
13
+ # 🚀 P2优化:速率限制
14
+ slowapi==0.1.9
15
+ # 🔒 P0安全增强:bcrypt密码哈希
16
+ bcrypt==4.1.2
17
+ # 🔧 P0修复:升级支付宝SDK,打破旧版死锁,自动适配最新安全加密库
18
  python-alipay-sdk>=3.3.0
router_wallet.py CHANGED
@@ -147,10 +147,10 @@ async def alipay_notify(request: Request, db: Session = Depends(get_db)):
147
  try:
148
  wallet = db.query(Wallet).filter(Wallet.account == account).with_for_update().first()
149
  if not wallet:
150
- wallet = Wallet(account=account)
151
  db.add(wallet)
152
 
153
- wallet.balance += amount
154
 
155
  last_tx = db.query(Transaction).filter(Transaction.account == account).order_by(Transaction.created_at.desc()).first()
156
  prev_hash = last_tx.tx_hash if last_tx else "GENESIS_HASH"
@@ -191,10 +191,10 @@ async def check_order(order_id: str, account: str = None, db: Session = Depends(
191
 
192
  wallet = db.query(Wallet).filter(Wallet.account == account).with_for_update().first()
193
  if not wallet:
194
- wallet = Wallet(account=account)
195
  db.add(wallet)
196
 
197
- wallet.balance += amount
198
 
199
  last_tx = db.query(Transaction).filter(Transaction.account == account).order_by(Transaction.created_at.desc()).first()
200
  prev_hash = last_tx.tx_hash if last_tx else "GENESIS_HASH"
@@ -307,11 +307,11 @@ async def purchase_item(request: Request, req: PurchaseRequest, db: Session = De
307
 
308
  seller_wallet = db.query(Wallet).filter(Wallet.account == seller_account).with_for_update().first()
309
  if not seller_wallet:
310
- seller_wallet = Wallet(account=seller_account)
311
  db.add(seller_wallet)
312
 
313
- buyer_wallet.balance -= price
314
- seller_wallet.earn_balance += price
315
 
316
  # 🔄 P7后悔模式:记录购买价格
317
  new_ownership = Ownership(account=req.account, item_id=req.item_id, price_paid=price)
 
147
  try:
148
  wallet = db.query(Wallet).filter(Wallet.account == account).with_for_update().first()
149
  if not wallet:
150
+ wallet = Wallet(account=account, balance=0, earn_balance=0, tip_balance=0, frozen_balance=0)
151
  db.add(wallet)
152
 
153
+ wallet.balance = (wallet.balance or 0) + amount
154
 
155
  last_tx = db.query(Transaction).filter(Transaction.account == account).order_by(Transaction.created_at.desc()).first()
156
  prev_hash = last_tx.tx_hash if last_tx else "GENESIS_HASH"
 
191
 
192
  wallet = db.query(Wallet).filter(Wallet.account == account).with_for_update().first()
193
  if not wallet:
194
+ wallet = Wallet(account=account, balance=0, earn_balance=0, tip_balance=0, frozen_balance=0)
195
  db.add(wallet)
196
 
197
+ wallet.balance = (wallet.balance or 0) + amount
198
 
199
  last_tx = db.query(Transaction).filter(Transaction.account == account).order_by(Transaction.created_at.desc()).first()
200
  prev_hash = last_tx.tx_hash if last_tx else "GENESIS_HASH"
 
307
 
308
  seller_wallet = db.query(Wallet).filter(Wallet.account == seller_account).with_for_update().first()
309
  if not seller_wallet:
310
+ seller_wallet = Wallet(account=seller_account, balance=0, earn_balance=0, tip_balance=0, frozen_balance=0)
311
  db.add(seller_wallet)
312
 
313
+ buyer_wallet.balance = (buyer_wallet.balance or 0) - price
314
+ seller_wallet.earn_balance = (seller_wallet.earn_balance or 0) + price
315
 
316
  # 🔄 P7后悔模式:记录购买价格
317
  new_ownership = Ownership(account=req.account, item_id=req.item_id, price_paid=price)