This commit is contained in:
aaron 2025-03-18 10:17:39 +08:00
parent 64e61ab9a7
commit f155324e2c
2 changed files with 20 additions and 5 deletions

View File

@ -30,26 +30,41 @@ async def get_dashboard_info(
total_user_count = db.query(UserDB).count()
# 查询已下单用户数
orders = db.query(ShippingOrderDB).filter(ShippingOrderDB.status.in_(['COMPLETED', 'UNPAID'])).all()
orders = db.query(ShippingOrderDB).filter(ShippingOrderDB.status != OrderStatus.CANCELLED).all()
has_order_user_count = len(set([order.userid for order in orders]))
has_order_completed_user_count = len(set([order.userid for order in orders if order.status == OrderStatus.COMPLETED or order.status == OrderStatus.UNPAID]))
has_paid_user_count = len(set([order.userid for order in orders if order.status == OrderStatus.COMPLETED and order.final_amount > 0]))
order_count = len(orders)
order_completed_count = len([order for order in orders if order.status == OrderStatus.COMPLETED or order.status == OrderStatus.UNPAID])
#需要支付的订单数量
need_pay_order_count = len([order for order in orders if order.final_amount > 0])
order_unpaid_count = len([order for order in orders if order.status == OrderStatus.UNPAID])
order_pay_count = len([order for order in orders if order.status == OrderStatus.COMPLETED and order.final_amount > 0])
pay_rate = order_pay_count / order_count if order_count > 0 else 0
order_amount = sum([order.original_amount_with_additional_fee for order in orders])
pay_amount = sum([order.final_amount for order in orders if order.status == OrderStatus.COMPLETED and order.final_amount > 0])
pay_rate = order_unpaid_count / need_pay_order_count if need_pay_order_count > 0 else 0
# 已支付的订单数量
order_amount = sum([order.original_amount_with_additional_fee for order in orders if order.status != OrderStatus.CANCELLED])
completed_order_amount = sum([order.original_amount_with_additional_fee for order in orders if order.status == OrderStatus.COMPLETED])
pay_amount = sum([order.final_amount for order in orders if order.status == OrderStatus.COMPLETED and order.final_amount > 0])
unpaid_amount = sum([order.original_amount_with_additional_fee for order in orders if order.status == OrderStatus.UNPAID])
return success_response(data={
"total_community_count": total_community_count,
"total_user_count": total_user_count,
"has_order_user_count": has_order_user_count,
"has_order_completed_user_count": has_order_completed_user_count,
"has_paid_user_count": has_paid_user_count,
"order_count": order_count,
"order_completed_count": order_completed_count,
"order_pay_count": order_pay_count,
"order_unpaid_count": order_unpaid_count,
"pay_rate": pay_rate,
"order_amount": order_amount,
"pay_amount": pay_amount
"pay_amount": pay_amount,
"unpaid_amount": unpaid_amount,
"completed_order_amount": completed_order_amount
})
@router.get("/deliveryman")

Binary file not shown.