This commit is contained in:
aaron 2025-02-25 23:22:47 +08:00
parent 62158fe4f0
commit 9cd3c5a39f
4 changed files with 30 additions and 7 deletions

View File

@ -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="用户申请退款"
)

View File

@ -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:

View File

@ -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
)

View File

@ -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 # 出错时返回原数组