订单检查接口更新
This commit is contained in:
parent
653501f07f
commit
8faca8e8cb
@ -1363,6 +1363,20 @@ async def get_deliveryman_order_summary(
|
|||||||
"today_count": today_total
|
"today_count": today_total
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@router.get("/deliveryman/new_orders_checked", response_model=ResponseModel)
|
||||||
|
async def get_new_orders_checked(
|
||||||
|
db: Session = Depends(get_db),
|
||||||
|
deliveryman: UserDB = Depends(get_deliveryman_user)
|
||||||
|
):
|
||||||
|
"""获取新订单已检查标记"""
|
||||||
|
success = redis_client.remove_orders(deliveryman.community_id)
|
||||||
|
|
||||||
|
return success_response(data={
|
||||||
|
"message": "新订单已检查标记已移除",
|
||||||
|
"success": success
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
@router.get("/deliveryman/check_new_order", response_model=ResponseModel)
|
@router.get("/deliveryman/check_new_order", response_model=ResponseModel)
|
||||||
async def check_new_orders(
|
async def check_new_orders(
|
||||||
db: Session = Depends(get_db),
|
db: Session = Depends(get_db),
|
||||||
@ -1371,7 +1385,7 @@ async def check_new_orders(
|
|||||||
"""检查新订单"""
|
"""检查新订单"""
|
||||||
|
|
||||||
# 从Redis获取新订单ID列表
|
# 从Redis获取新订单ID列表
|
||||||
order_ids = redis_client.pop_orders_from_queue(deliveryman.community_id, 10)
|
order_ids = redis_client.get_orders_from_queue(deliveryman.community_id, 10)
|
||||||
|
|
||||||
if not order_ids:
|
if not order_ids:
|
||||||
return success_response(data={
|
return success_response(data={
|
||||||
|
|||||||
@ -54,7 +54,7 @@ class RedisClient:
|
|||||||
logging.error(f"添加新订单到队列失败: {str(e)}")
|
logging.error(f"添加新订单到队列失败: {str(e)}")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def pop_orders_from_queue(self, community_id: int, count: int = 10) -> List[str]:
|
def get_orders_from_queue(self, community_id: int, count: int = 10) -> List[str]:
|
||||||
"""
|
"""
|
||||||
获取社区新订单列表
|
获取社区新订单列表
|
||||||
|
|
||||||
@ -67,28 +67,27 @@ class RedisClient:
|
|||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
key = f"community:{community_id}:new_orders"
|
key = f"community:{community_id}:new_orders"
|
||||||
# 获取订单列表,并移除
|
# 获取订单列表,并不移除
|
||||||
orders = self.client.lpop(key, count)
|
orders = self.client.lrange(key, 0, count-1)
|
||||||
return orders
|
return orders
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.error(f"获取社区新订单列表失败: {str(e)}")
|
logging.error(f"获取社区新订单列表失败: {str(e)}")
|
||||||
return []
|
return []
|
||||||
|
|
||||||
def remove_order(self, community_id: int, order_id: str) -> bool:
|
def remove_orders(self, community_id: int) -> bool:
|
||||||
"""
|
"""
|
||||||
从社区队列中移除订单
|
从社区队列中移除订单
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
community_id: 社区ID
|
community_id: 社区ID
|
||||||
order_id: 订单ID
|
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
bool: 是否移除成功
|
bool: 是否移除成功
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
key = f"community:{community_id}:new_orders"
|
key = f"community:{community_id}:new_orders"
|
||||||
# 使用 LREM 移除列表中的元素
|
# 使用 ltrim 移除队列中的所有元素
|
||||||
self.client.lrem(key, 0, order_id)
|
self.client.ltrim(key, 0, -1)
|
||||||
return True
|
return True
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.error(f"从队列中移除订单失败: {str(e)}")
|
logging.error(f"从队列中移除订单失败: {str(e)}")
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user