This commit is contained in:
aaron 2025-02-16 22:42:09 +08:00
parent 556c8773d6
commit 0fb3a28070

View File

@ -46,9 +46,10 @@ def calculate_price(price_request: OrderPriceCalculateRequest,user: UserDB,db: S
""" """
# 计算所有包裹中的取件码总数 # 计算所有包裹中的取件码总数
package_count = sum( package_count = sum(
len(package.pickup_codes.split(',')) # 如果package.pickup_codes是空字符串则取0
0 if len(package.pickup_codes.split(',')) == 0 else len(package.pickup_codes.split(','))
for package in price_request.packages for package in price_request.packages
if package.pickup_codes if package.pickup_codes
) )
result = OrderPriceResult( result = OrderPriceResult(
@ -188,18 +189,19 @@ async def create_order(
# 创建订单包裹 # 创建订单包裹
for package in order.price_request.packages: for package in order.price_request.packages:
# 如果包裹有取件码,则创建包裹
if len(package.pickup_codes) > 0:
station = db.query(StationDB).filter(
StationDB.id == package.station_id
).first()
station = db.query(StationDB).filter( db_package = ShippingOrderPackageDB(
StationDB.id == package.station_id orderid=orderid,
).first() station_id=package.station_id,
station_name=station.name,
db_package = ShippingOrderPackageDB( pickup_codes=package.pickup_codes
orderid=orderid, )
station_id=package.station_id, db.add(db_package)
station_name=station.name,
pickup_codes=package.pickup_codes
)
db.add(db_package)
try: try:
# 如果使用了优惠券,更新优惠券状态 # 如果使用了优惠券,更新优惠券状态