diff --git a/app/api/endpoints/merchant_order.py b/app/api/endpoints/merchant_order.py index d2e2aca..3fe3b2f 100644 --- a/app/api/endpoints/merchant_order.py +++ b/app/api/endpoints/merchant_order.py @@ -262,8 +262,7 @@ async def apply_refund( wechat = WeChatClient() await wechat.apply_refund( order_id=order.order_id, - # total_amount=int(float(order.pay_amount) * 100), # 转换为分 - total_amount=int(1), # 测试 1 分钱 + total_amount=int(float(order.pay_amount) * 100) if not settings.DEBUG else 1, # 转换为分 reason="用户申请退款" ) diff --git a/app/api/endpoints/order.py b/app/api/endpoints/order.py index 4477d26..e998547 100644 --- a/app/api/endpoints/order.py +++ b/app/api/endpoints/order.py @@ -254,7 +254,7 @@ async def create_order( ).first() # 对package.pickup_codes中分割的取件码,进行排序 - sorted_pickup_codes = sorted(package.pickup_codes.split(",")) + sorted_pickup_codes = CommonUtils.sort_strings_by_first_number(package.pickup_codes.split(",")) db_package = ShippingOrderPackageDB( orderid=orderid, @@ -401,7 +401,7 @@ async def get_order_detail( "orderid": p.orderid, "station_id": p.station_id, "station_name": p.station_name, - "pickup_codes": p.pickup_codes, + "pickup_codes": CommonUtils.sort_strings_by_first_number(p.pickup_codes.split(",")), "create_time": p.create_time } for p in packages] else: diff --git a/app/api/endpoints/wechat.py b/app/api/endpoints/wechat.py index db609c0..64897d8 100644 --- a/app/api/endpoints/wechat.py +++ b/app/api/endpoints/wechat.py @@ -165,8 +165,7 @@ async def create_payment( result = await wechat.create_jsapi_payment( openid=current_user.openid, out_trade_no=request.order_id, - # total_amount=int(float(amount) * 100), # 转换为分 - total_amount=int(1), # 测试 1 分钱 + total_amount=int(float(amount) * 100) if not settings.DEBUG else 1, # 转换为分 description=description ) diff --git a/app/core/utils.py b/app/core/utils.py index 584acbe..0dd5751 100644 --- a/app/core/utils.py +++ b/app/core/utils.py @@ -1,7 +1,8 @@ from datetime import datetime import time -from typing import Optional +from typing import Optional, List import pytz # 需要先安装: pip install pytz +import re class CommonUtils: """工具类""" @@ -46,3 +47,27 @@ class CommonUtils: date_str = now.strftime('%Y%m%d') timestamp = str(int(time.time() * 1000))[-8:] return f"{date_str}{timestamp}" + + @staticmethod + def extract_first_number(s: str) -> int: + """ + 提取字符串中的第一个数字 + 如果没有数字,返回0 + """ + try: + # 使用正则表达式匹配第一个数字 + match = re.search(r'\d+', s) + return int(match.group()) if match else 0 + except: + return 0 + + @staticmethod + def sort_strings_by_first_number(strings: List[str]) -> List[str]: + """ + 按第一个数字排序字符串数组 + """ + try: + return sorted(strings, key=CommonUtils.extract_first_number) + except Exception as e: + print(f"排序出错: {str(e)}") + return strings # 出错时返回原数组