update
This commit is contained in:
parent
cfb8794f71
commit
f3cfdb9fec
@ -9,6 +9,8 @@ from datetime import datetime, timedelta
|
|||||||
from app.core.response import success_response, error_response, ResponseModel
|
from app.core.response import success_response, error_response, ResponseModel
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
from app.models.user_auth import UserAuthDB
|
from app.models.user_auth import UserAuthDB
|
||||||
|
from app.models.statistics import DailyCommunityOrderStats, DailyOrderStats
|
||||||
|
|
||||||
router = APIRouter()
|
router = APIRouter()
|
||||||
|
|
||||||
# 获取基础信息
|
# 获取基础信息
|
||||||
@ -37,6 +39,7 @@ async def get_dashboard_info(
|
|||||||
yesterday_user_count = len([user for user in users if user.create_time.date() == datetime.now().date() - timedelta(days=1)])
|
yesterday_user_count = len([user for user in users if user.create_time.date() == datetime.now().date() - timedelta(days=1)])
|
||||||
|
|
||||||
# 查询已下单用户数
|
# 查询已下单用户数
|
||||||
|
|
||||||
orders = db.query(ShippingOrderDB).filter(ShippingOrderDB.status != OrderStatus.CANCELLED).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_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_order_completed_user_count = len(set([order.userid for order in orders if order.status == OrderStatus.COMPLETED or order.status == OrderStatus.UNPAID]))
|
||||||
@ -93,6 +96,64 @@ async def get_dashboard_info(
|
|||||||
"yesterday_order_amount": yesterday_order_amount
|
"yesterday_order_amount": yesterday_order_amount
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@router.get("/order_stats")
|
||||||
|
async def get_order_stats(
|
||||||
|
limit: int = 10,
|
||||||
|
skip: int = 0,
|
||||||
|
db: Session = Depends(get_db)
|
||||||
|
):
|
||||||
|
# 获取今日订单量
|
||||||
|
query = db.query(DailyOrderStats).order_by(DailyOrderStats.stats_date.desc()).offset(skip).limit(limit)
|
||||||
|
total = query.count()
|
||||||
|
items = query.all()
|
||||||
|
|
||||||
|
result = []
|
||||||
|
for item in items:
|
||||||
|
result.append({
|
||||||
|
"stats_date": item.stats_date,
|
||||||
|
"total_order_count": item.total_order_count,
|
||||||
|
"total_original_amount": item.total_original_amount,
|
||||||
|
"total_final_amount": item.total_final_amount,
|
||||||
|
"total_communities": item.total_communities
|
||||||
|
})
|
||||||
|
|
||||||
|
return success_response(data={
|
||||||
|
"items": result,
|
||||||
|
"total": total
|
||||||
|
})
|
||||||
|
|
||||||
|
@router.get("/community_stats")
|
||||||
|
async def get_community_stats(
|
||||||
|
community_id: Optional[int] = None,
|
||||||
|
limit: int = 10,
|
||||||
|
skip: int = 0,
|
||||||
|
db: Session = Depends(get_db)
|
||||||
|
):
|
||||||
|
# 获取今日订单量
|
||||||
|
query = db.query(DailyCommunityOrderStats).order_by(DailyCommunityOrderStats.stats_date.desc()).offset(skip).limit(limit)
|
||||||
|
total = query.count()
|
||||||
|
|
||||||
|
if community_id:
|
||||||
|
query = query.filter(DailyCommunityOrderStats.community_id == community_id)
|
||||||
|
items = query.all()
|
||||||
|
|
||||||
|
result = []
|
||||||
|
for item in items:
|
||||||
|
result.append({
|
||||||
|
"community_id": item.community_id,
|
||||||
|
"community_name": item.community_name,
|
||||||
|
"order_count": item.order_count,
|
||||||
|
"total_original_amount": item.total_original_amount,
|
||||||
|
"total_final_amount": item.total_final_amount,
|
||||||
|
"stats_date": item.stats_date
|
||||||
|
})
|
||||||
|
|
||||||
|
return success_response(data={
|
||||||
|
"items": result,
|
||||||
|
"total": total
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
@router.get("/deliveryman")
|
@router.get("/deliveryman")
|
||||||
async def get_deliveryman_dashboard_info(
|
async def get_deliveryman_dashboard_info(
|
||||||
community_id: Optional[int] = None,
|
community_id: Optional[int] = None,
|
||||||
|
|||||||
BIN
jobs.sqlite
BIN
jobs.sqlite
Binary file not shown.
Loading…
Reference in New Issue
Block a user