This commit is contained in:
aaron 2025-03-16 17:23:52 +08:00
parent 94e48983da
commit 2587b307f9
2 changed files with 4 additions and 23 deletions

View File

@ -178,22 +178,6 @@ def format_delivery_time(delivery_date: datetime, time_period_name: str) -> str:
else:
return f"{delivery_date.strftime('%m-%d')} {time_period_name}"
def has_consecutive_weekdays(weekdays):
if not weekdays or len(weekdays) <= 1:
return True
days = sorted(weekdays)
# 处理环绕情况
if 1 in days and 7 in days and abs(days.index(1) - days.index(7)) == 1:
# 特殊处理周日和周一的连接
temp = days.copy()
temp.remove(1 if days.index(1) == 0 else 7)
return all(temp[i] - temp[i-1] == 1 for i in range(1, len(temp)))
# 普通情况
return all(days[i] - days[i-1] == 1 for i in range(1, len(days)))
@router.post("/pre-order", response_model=ResponseModel)
async def pre_order(
request: OrderPriceCalculateRequest,
@ -211,13 +195,10 @@ async def pre_order(
# 检查是否在服务时间
if community.weekdays and request.delivery_date:
if request.delivery_date.isoweekday() not in community.weekdays:
if has_consecutive_weekdays(community.weekdays):
message = f"本小区的服务时间为: 周{community.weekdays[0]}-{community.weekdays[-1]}"
else:
message = f"本小区的服务时间为: "
for day in community.weekdays:
message += f"{day}, "
message = message[:-2]
message = f"本小区的服务时间为: "
for day in community.weekdays:
message += f"{day}, "
message = message[:-2]
return error_response(code=400, message=message)
# 检查是否有配送员在线

Binary file not shown.