From d55e536838cd92a7f5cafe37aae8c882d6717bb4 Mon Sep 17 00:00:00 2001 From: aaron <> Date: Wed, 19 Feb 2025 16:02:48 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E4=B8=BA=E4=B8=9C=E5=85=AB=E5=8C=BA?= =?UTF-8?q?=E6=97=B6=E9=97=B4=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/endpoints/order.py | 8 ++++---- app/core/utils.py | 10 ++++++++++ requirements.txt | 3 ++- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/app/api/endpoints/order.py b/app/api/endpoints/order.py index 054481c..e156e3d 100644 --- a/app/api/endpoints/order.py +++ b/app/api/endpoints/order.py @@ -578,7 +578,7 @@ async def cancel_order( template_id=settings.DELIVERY_ORDER_CANCELLED_TEMPLATE_ID, data={ "character_string1": order.orderid, - "time19": datetime.now().strftime("%Y-%m-%d %H:%M:%S"), + "time19": CommonUtils.get_current_time(), "thing5": "用户主动取消订单" } ) @@ -744,7 +744,7 @@ async def deliveryman_cancel_order( template_id=settings.DELIVERY_ORDER_CANCELLED_TEMPLATE_ID, data={ "character_string1": order.orderid, - "time19": datetime.now().strftime("%Y-%m-%d %H:%M:%S"), + "time19": CommonUtils.get_current_time(), "thing5": order.cancel_reason } ) @@ -821,7 +821,7 @@ async def complete_order( data={ "character_string13": order.orderid, "thing3": deliveryman_user.nickname, - "time5" : datetime.now().strftime("%Y-%m-%d %H:%M:%S") + "time5" : CommonUtils.get_current_time() }, miniprogram={ "appid": settings.WECHAT_APPID, @@ -883,7 +883,7 @@ async def receive_order( template_id=settings.DELIVERY_ORDER_RECEIVED_TEMPLATE_ID, data={ "character_string9": order.orderid, - "time8": datetime.now().strftime("%Y-%m-%d %H:%M:%S"), + "time8": CommonUtils.get_current_time(), "thing3": deliveryman_user.nickname }, miniprogram={ diff --git a/app/core/utils.py b/app/core/utils.py index 96a6ad3..4c9853a 100644 --- a/app/core/utils.py +++ b/app/core/utils.py @@ -1,9 +1,19 @@ from datetime import datetime import time from typing import Optional +import pytz # 需要先安装: pip install pytz class CommonUtils: """工具类""" + + @staticmethod + def get_current_time(timezone='Asia/Shanghai'): + """ + 获取指定时区的当前时间 + :param timezone: 时区名称,默认为上海时区(东八区) + """ + tz = pytz.timezone(timezone) + return datetime.now(tz).strftime('%Y-%m-%d %H:%M:%S') @staticmethod def generate_order_id(prefix: str) -> str: diff --git a/requirements.txt b/requirements.txt index 7ca76cf..4ceeca8 100644 --- a/requirements.txt +++ b/requirements.txt @@ -15,4 +15,5 @@ bcrypt aiohttp==3.9.1 cryptography==42.0.2 qrcode>=7.3.1 -pillow>=9.0.0 \ No newline at end of file +pillow>=9.0.0 +pytz==2024.1 \ No newline at end of file