From ccf555ac2ff015b853fb96a69f56458bb0cf653d Mon Sep 17 00:00:00 2001 From: aaron <> Date: Thu, 20 Feb 2025 12:21:57 +0800 Subject: [PATCH] update --- app/api/endpoints/order.py | 3 +-- app/api/endpoints/user.py | 2 +- app/api/endpoints/withdraw.py | 30 +++++++++++++++++++++++++++--- app/models/community.py | 9 ++++++++- 4 files changed, 37 insertions(+), 7 deletions(-) diff --git a/app/api/endpoints/order.py b/app/api/endpoints/order.py index 6b5621d..539d0a4 100644 --- a/app/api/endpoints/order.py +++ b/app/api/endpoints/order.py @@ -701,8 +701,7 @@ async def deliveryman_cancel_order( ): """配送员取消订单""" order = db.query(ShippingOrderDB).filter( - ShippingOrderDB.orderid == orderid, - ShippingOrderDB.deliveryman_user_id == deliveryman.userid + ShippingOrderDB.orderid == orderid ).first() if not order: diff --git a/app/api/endpoints/user.py b/app/api/endpoints/user.py index 1464f7c..f618dbb 100644 --- a/app/api/endpoints/user.py +++ b/app/api/endpoints/user.py @@ -504,7 +504,7 @@ async def change_password( if not redis_code: return error_response(message="验证码已过期") - if redis_code.decode() != request.verify_code: + if redis_code != request.verify_code: return error_response(message="验证码错误") try: diff --git a/app/api/endpoints/withdraw.py b/app/api/endpoints/withdraw.py index 8016a08..fd9b70f 100644 --- a/app/api/endpoints/withdraw.py +++ b/app/api/endpoints/withdraw.py @@ -17,6 +17,8 @@ router = APIRouter() class WithdrawApproveRequest(BaseModel): """提现审核请求""" + skip: int = Field(default=0) + limit: int = Field(default=20) transaction_id: str = Field(..., max_length=64) # 银行交易流水号 class WithdrawRejectRequest(BaseModel): @@ -150,18 +152,40 @@ async def reject_withdraw( @router.get("/user", response_model=ResponseModel) async def get_user_withdraws( status: Optional[WithdrawStatus] = None, + skip: int = Field(default=0), + limit: int = Field(default=20), db: Session = Depends(get_db), current_user: UserDB = Depends(get_current_user) ): """获取提现记录列表""" - query = db.query(WithdrawDB).filter(WithdrawDB.user_id == current_user.userid) + query = db.query(WithdrawDB).join( + UserBankCardDB, + WithdrawDB.bank_card_id == UserBankCardDB.id + ).filter(WithdrawDB.user_id == current_user.userid) if status: query = query.filter(WithdrawDB.status == status) + + total = query.count() - withdraws = query.order_by(WithdrawDB.create_time.desc()).all() + withdraws = query.order_by(WithdrawDB.create_time.desc()).offset(skip).limit(limit).all() - return success_response(data=[WithdrawInfo.model_validate(w) for w in withdraws]) + withdraw_list = [] + for w in withdraws: + withdraw_info = WithdrawInfo.model_validate(w) + # 添加额外信息 + withdraw_info_dict = withdraw_info.model_dump() + withdraw_info_dict.update({ + "bank_card_number": w.bank_card.card_number, # 银行卡号 + "bank_name": w.bank_card.bank_name, # 银行名称 + "name": w.bank_card.name, # 持卡人姓名 + }) + withdraw_list.append(withdraw_info_dict) + + return success_response(data={ + "items": withdraw_list, + "total": total + }) @router.get("", response_model=ResponseModel) async def get_all_withdraws( diff --git a/app/models/community.py b/app/models/community.py index b607ed1..222c7f7 100644 --- a/app/models/community.py +++ b/app/models/community.py @@ -4,7 +4,7 @@ from sqlalchemy import Column, Integer, String, DECIMAL, DateTime, Enum from sqlalchemy.sql import func from pydantic import BaseModel, Field from .database import Base - +from app.core.imageprocessor import process_image, ImageFormat class CommunityStatus(str, enum.Enum): UNOPEN = "UNOPEN" # 未运营 OPENING = "OPENING" # 已运营 @@ -23,6 +23,12 @@ class CommunityDB(Base): create_time = Column(DateTime(timezone=True), server_default=func.now()) update_time = Column(DateTime(timezone=True), onupdate=func.now()) + @property + def optimized_qy_group_qrcode(self): + if self.qy_group_qrcode: + return process_image(self.qy_group_qrcode).thumbnail(600, 600).format(ImageFormat.WEBP).build() + return None + # Pydantic 模型 class CommunityCreate(BaseModel): name: str = Field(..., max_length=100) @@ -48,6 +54,7 @@ class CommunityInfo(BaseModel): longitude: float status: CommunityStatus qy_group_qrcode: Optional[str] = None + optimized_qy_group_qrcode: Optional[str] = None distance: Optional[float] = None # 距离,单位:米 class Config: