update
This commit is contained in:
parent
cc00274eab
commit
94e48983da
@ -129,6 +129,7 @@ async def get_communities(
|
||||
"extra_package_price": float(community.extra_package_price),
|
||||
"extra_package_threshold": community.extra_package_threshold,
|
||||
"more_station_price": float(community.more_station_price),
|
||||
"weekdays": community.weekdays,
|
||||
"distance": float(distance_value) if distance_value is not None else None,
|
||||
"admin": None if community.admin is None else {
|
||||
"id": community.admin.userid,
|
||||
|
||||
@ -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,
|
||||
@ -186,6 +202,24 @@ async def pre_order(
|
||||
):
|
||||
|
||||
try:
|
||||
# 检查是否在服务时间
|
||||
community = db.query(CommunityDB).filter(
|
||||
CommunityDB.id == request.community_id
|
||||
).first()
|
||||
|
||||
if community:
|
||||
# 检查是否在服务时间
|
||||
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]
|
||||
return error_response(code=400, message=message)
|
||||
|
||||
# 检查是否有配送员在线
|
||||
deliveryman_online = db.query(UserDB).filter(
|
||||
UserDB.roles.contains(UserRole.DELIVERYMAN),
|
||||
@ -193,8 +227,6 @@ async def pre_order(
|
||||
UserDB.is_delivering == True
|
||||
).first()
|
||||
|
||||
print(f"deliveryman_online: {deliveryman_online}")
|
||||
|
||||
if deliveryman_online is None:
|
||||
print(f"没有配送员在线, 无法下单")
|
||||
return error_response(code=400, message="没有配送员在线, 无法下单")
|
||||
|
||||
@ -59,7 +59,7 @@ app.add_middleware(
|
||||
)
|
||||
|
||||
# 添加请求日志中间件
|
||||
app.add_middleware(RequestLoggerMiddleware)
|
||||
# app.add_middleware(RequestLoggerMiddleware)
|
||||
app.add_middleware(SessionMiddleware, secret_key=settings.SECRET_KEY)
|
||||
|
||||
# 添加定时任务路由
|
||||
|
||||
@ -1,7 +1,8 @@
|
||||
from typing import Optional
|
||||
from typing import Optional, List
|
||||
import enum
|
||||
from sqlalchemy import Column, Integer, String, DECIMAL, DateTime, Enum, ForeignKey
|
||||
from sqlalchemy.sql import func
|
||||
from sqlalchemy.dialects.mysql import JSON
|
||||
from pydantic import BaseModel, Field, model_validator
|
||||
from .database import Base
|
||||
from sqlalchemy.orm import relationship, backref
|
||||
@ -30,6 +31,9 @@ class CommunityDB(Base):
|
||||
extra_package_price = Column(DECIMAL(10,2), nullable=False, default=1.0) # 额外包裹费用
|
||||
extra_package_threshold = Column(Integer, nullable=False, default=2) # 额外收费阈值
|
||||
more_station_price = Column(DECIMAL(10,2), nullable=False, default=2.0) # 多驿站加价
|
||||
|
||||
# 服务时间
|
||||
weekdays = Column(JSON, nullable=True) # 服务星期几,如[1,2,3,4,5]表示周一到周五
|
||||
|
||||
create_time = Column(DateTime(timezone=True), server_default=func.now())
|
||||
update_time = Column(DateTime(timezone=True), onupdate=func.now())
|
||||
@ -60,6 +64,7 @@ class CommunityCreate(BaseModel):
|
||||
status: CommunityStatus = Field(default=CommunityStatus.UNOPEN)
|
||||
qy_group_qrcode: Optional[str] = Field(None, max_length=200)
|
||||
webot_webhook: Optional[str] = Field(None, max_length=200)
|
||||
weekdays: Optional[List[int]] = Field(None, description="服务星期几,如[1,2,3,4,5]表示周一到周五")
|
||||
|
||||
class CommunityUpdate(BaseModel):
|
||||
name: Optional[str] = Field(None, max_length=100)
|
||||
@ -73,6 +78,7 @@ class CommunityUpdate(BaseModel):
|
||||
extra_package_price: Optional[float] = Field(None)
|
||||
extra_package_threshold: Optional[int] = Field(None)
|
||||
more_station_price: Optional[float] = Field(None)
|
||||
weekdays: Optional[List[int]] = Field(None, description="服务星期几,如[1,2,3,4,5]表示周一到周五")
|
||||
admin_id: Optional[int] = Field(None)
|
||||
|
||||
class CommunityInfo(BaseModel):
|
||||
@ -89,6 +95,7 @@ class CommunityInfo(BaseModel):
|
||||
extra_package_price: Optional[float] = None
|
||||
extra_package_threshold: Optional[int] = None
|
||||
more_station_price: Optional[float] = None
|
||||
weekdays: Optional[List[int]] = None
|
||||
optimized_qy_group_qrcode: Optional[str] = None
|
||||
distance: Optional[float] = None # 距离,单位:米
|
||||
|
||||
|
||||
@ -132,6 +132,7 @@ class OrderPriceCalculateRequest(BaseModel):
|
||||
community_id: int = 0
|
||||
pickup_images: Optional[str] = None
|
||||
pickup_images_count: int = 0
|
||||
delivery_date: Optional[date] = None
|
||||
packages: Optional[List[OrderPackage]] = None
|
||||
|
||||
# 然后再定义 OrderCreate
|
||||
|
||||
BIN
jobs.sqlite
BIN
jobs.sqlite
Binary file not shown.
Loading…
Reference in New Issue
Block a user