diff --git a/app/api/endpoints/order.py b/app/api/endpoints/order.py index d2ac95d..c3712ab 100644 --- a/app/api/endpoints/order.py +++ b/app/api/endpoints/order.py @@ -410,10 +410,12 @@ async def get_order_detail( # 计算配送员分账金额 deliveryman_share = 0 - if current_user.delivery_commission_rate is not None: - deliveryman_share = round(order.original_amount_with_additional_fee * (current_user.delivery_commission_rate / 100.0), 2) - if current_user.delivery_commission_fixed is not None: + if current_user.delivery_commission_fixed > 0: deliveryman_share = current_user.delivery_commission_fixed + elif current_user.delivery_commission_rate > 0: + deliveryman_share = round(order.original_amount_with_additional_fee * (current_user.delivery_commission_rate / 100.0), 2) + else: + deliveryman_share = 0 # 如果有配送员 id,则获取配送员信息 if order.deliveryman_user_id: @@ -1166,19 +1168,23 @@ async def deliveryman_complete_order( order.completed_time = datetime.now() # 计算配送员分账金额 - if current_user.delivery_commission_rate is not None: + if current_user.delivery_commission_rate > 0: deliveryman_share = order.original_amount_with_additional_fee * current_user.delivery_commission_rate / 100 - else: + elif current_user.delivery_commission_fixed > 0: deliveryman_share = current_user.delivery_commission_fixed + else: + deliveryman_share = 0 # 使用账户管理器处理分账 - account_manager = AccountManager(db) - account_manager.change_balance( - user_id=order.deliveryman_user_id, - amount=deliveryman_share, - description=f"配送订单收益", - transaction_id=orderid - ) + if deliveryman_share > 0: + account_manager = AccountManager(db) + account_manager.change_balance( + user_id=order.deliveryman_user_id, + amount=deliveryman_share, + description=f"配送订单收益", + transaction_id=orderid + ) + db.commit() # 如果当前订单是首单,如果有邀请人,给邀请人发放优惠券