update
This commit is contained in:
parent
2587b307f9
commit
1c6f82cabc
@ -178,6 +178,22 @@ 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,
|
||||
@ -195,10 +211,17 @@ async def pre_order(
|
||||
# 检查是否在服务时间
|
||||
if community.weekdays and request.delivery_date:
|
||||
if request.delivery_date.isoweekday() not in community.weekdays:
|
||||
message = f"本小区的服务时间为: "
|
||||
for day in community.weekdays:
|
||||
message += f"周{day}, "
|
||||
message = message[:-2]
|
||||
|
||||
#排序
|
||||
sorted_weekdays = sorted(community.weekdays)
|
||||
|
||||
if has_consecutive_weekdays(sorted_weekdays):
|
||||
message = f"本小区的服务时间为: 周{sorted_weekdays[0]}-{sorted_weekdays[-1]}"
|
||||
else:
|
||||
message = f"本小区的服务时间为: "
|
||||
for day in sorted_weekdays:
|
||||
message += f"周{day}, "
|
||||
message = message[:-2]
|
||||
return error_response(code=400, message=message)
|
||||
|
||||
# 检查是否有配送员在线
|
||||
|
||||
BIN
jobs.sqlite
BIN
jobs.sqlite
Binary file not shown.
Loading…
Reference in New Issue
Block a user