返回商家 distance
This commit is contained in:
parent
df52173903
commit
9a92b4f29e
@ -99,13 +99,22 @@ async def update_merchant(
|
||||
@router.get("/{merchant_id}", response_model=ResponseModel)
|
||||
async def get_merchant(
|
||||
merchant_id: int,
|
||||
longitude: Optional[float] = None,
|
||||
latitude: Optional[float] = None,
|
||||
db: Session = Depends(get_db)
|
||||
):
|
||||
"""获取商家详情"""
|
||||
# 构建基础查询
|
||||
merchant = db.query(
|
||||
MerchantDB,
|
||||
UserDB.phone.label('user_phone'),
|
||||
UserDB.nickname.label('user_nickname')
|
||||
UserDB.nickname.label('user_nickname'),
|
||||
text("CASE WHEN :lat IS NOT NULL AND :lon IS NOT NULL THEN "
|
||||
"ST_Distance_Sphere(point(longitude, latitude), point(:lon, :lat)) "
|
||||
"ELSE NULL END as distance").params(
|
||||
lat=latitude,
|
||||
lon=longitude
|
||||
) if longitude and latitude else text("NULL as distance")
|
||||
).join(
|
||||
UserDB,
|
||||
MerchantDB.user_id == UserDB.userid
|
||||
@ -121,7 +130,8 @@ async def get_merchant(
|
||||
merchant_data = merchant_info.model_dump()
|
||||
merchant_data.update({
|
||||
'user_phone': merchant.user_phone,
|
||||
'user_nickname': merchant.user_nickname
|
||||
'user_nickname': merchant.user_nickname,
|
||||
'distance': round(merchant.distance) if merchant.distance else None
|
||||
})
|
||||
|
||||
return success_response(data=merchant_data)
|
||||
@ -207,7 +217,8 @@ async def list_merchants(
|
||||
"product_name": product.name,
|
||||
"product_image": product.optimized_image_url,
|
||||
"product_price": float(product.sale_price),
|
||||
"purchase_limit": product.purchase_limit
|
||||
"purchase_limit": product.purchase_limit,
|
||||
"promotion_text": product.promotion_text
|
||||
}
|
||||
|
||||
# 处理返回结果
|
||||
|
||||
Loading…
Reference in New Issue
Block a user