增加固定金额分账
This commit is contained in:
parent
232a49ba32
commit
1fcf9cd3ce
@ -395,6 +395,8 @@ async def get_order_detail(
|
||||
deliveryman_share = 0
|
||||
if current_user.delivery_commission_rate is not None:
|
||||
deliveryman_share = round(order.original_amount * (current_user.delivery_commission_rate / 100.0), 2)
|
||||
if current_user.delivery_commission_fixed is not None:
|
||||
deliveryman_share = current_user.delivery_commission_fixed
|
||||
|
||||
# 如果有配送员 id,则获取配送员信息
|
||||
if order.deliveryman_user_id:
|
||||
@ -1064,7 +1066,10 @@ async def deliveryman_complete_order(
|
||||
order.completed_time = datetime.now()
|
||||
|
||||
# 计算配送员分账金额
|
||||
if current_user.delivery_commission_rate is not None:
|
||||
deliveryman_share = order.original_amount * current_user.delivery_commission_rate / 100
|
||||
else:
|
||||
deliveryman_share = current_user.delivery_commission_fixed
|
||||
|
||||
# 使用账户管理器处理分账
|
||||
account_manager = AccountManager(db)
|
||||
|
||||
@ -23,7 +23,7 @@ from app.models.user_auth import UserAuthDB, UserAuthCreate, UserAuthInfo
|
||||
from app.core.qcloud import qcloud_manager
|
||||
from app.models.merchant import MerchantDB
|
||||
from app.models.address import AddressDB, AddressInfo
|
||||
from app.models.user import UserUpdateRoles, UserUpdateDeliveryCommissionRate
|
||||
from app.models.user import UserUpdateRoles, UserUpdateDeliveryCommission
|
||||
from app.models.order import ShippingOrderDB, OrderStatus
|
||||
from app.core.redis_client import redis_client
|
||||
|
||||
@ -243,9 +243,9 @@ async def update_user_info(
|
||||
db.rollback()
|
||||
return error_response(code=500, message=f"更新失败: {str(e)}")
|
||||
|
||||
@router.put("/delivery-commission-rate", response_model=ResponseModel)
|
||||
async def update_delivery_commission_rate(
|
||||
update_data: UserUpdateDeliveryCommissionRate,
|
||||
@router.put("/delivery-commission", response_model=ResponseModel)
|
||||
async def update_delivery_commission(
|
||||
update_data: UserUpdateDeliveryCommission,
|
||||
db: Session = Depends(get_db),
|
||||
current_user: UserDB = Depends(get_admin_user)
|
||||
):
|
||||
@ -255,7 +255,11 @@ async def update_delivery_commission_rate(
|
||||
if not user:
|
||||
return error_response(code=404, message="用户不存在")
|
||||
|
||||
if update_data.delivery_commission_rate:
|
||||
user.delivery_commission_rate = update_data.delivery_commission_rate
|
||||
|
||||
if update_data.delivery_commission_fixed:
|
||||
user.delivery_commission_fixed = update_data.delivery_commission_fixed
|
||||
db.commit()
|
||||
db.refresh(user)
|
||||
|
||||
|
||||
@ -50,6 +50,7 @@ class UserDB(Base):
|
||||
community_id = Column(Integer, ForeignKey("communities.id"), nullable=True) # 归属小区
|
||||
is_auth = Column(Boolean, nullable=False, default=False)
|
||||
delivery_commission_rate = Column(Integer, nullable=False, default=0) # 配送佣金比例
|
||||
delivery_commission_fixed = Column(DECIMAL(10, 2), nullable=False, default=0) # 配送佣金固定金额
|
||||
|
||||
@property
|
||||
def optimized_avatar(self):
|
||||
@ -83,6 +84,7 @@ class UserInfo(BaseModel):
|
||||
community_name: Optional[str] = None
|
||||
is_auth: bool = False
|
||||
delivery_commission_rate: Optional[int] = None
|
||||
delivery_commission_fixed: Optional[float] = None
|
||||
|
||||
class Config:
|
||||
from_attributes = True
|
||||
@ -119,9 +121,10 @@ class UserUpdateRoles(BaseModel):
|
||||
user_id: int
|
||||
roles: List[UserRole]
|
||||
|
||||
class UserUpdateDeliveryCommissionRate(BaseModel):
|
||||
class UserUpdateDeliveryCommission(BaseModel):
|
||||
user_id: int
|
||||
delivery_commission_rate: int
|
||||
delivery_commission_rate: Optional[int] = None
|
||||
delivery_commission_fixed: Optional[float] = None
|
||||
|
||||
def generate_user_code(db=None) -> str:
|
||||
"""生成6位大写字母+数字的用户编码"""
|
||||
|
||||
Loading…
Reference in New Issue
Block a user