This commit is contained in:
Felix
2025-12-22 18:44:23 +08:00
parent c0c8a45748
commit 711fecbff4
3 changed files with 9 additions and 10 deletions

View File

@@ -86,7 +86,7 @@ class WxPayService:
order = WxOrder(
user_id=user_id,
out_trade_no=str(generated_id),
description=product.title,
description=f"{product.points} 积分",
amount_cents=product.amount_cents,
payer_openid=payer_openid,
trade_state='NOTPAY',
@@ -104,7 +104,7 @@ class WxPayService:
payer = {"openid": payer_openid}
result = WxPayService._safe_call(
wxpay.pay,
description=product.title,
description=f"{product.points} 积分",
out_trade_no=str(order.id),
amount={"total": product.amount_cents, "currency": "CNY"},
pay_type=WeChatPayType.JSAPI,
@@ -311,6 +311,7 @@ class WxPayService:
async def create_refund(user_id: int, out_trade_no: str, amount_cents: int, reason: Optional[str] = None) -> dict:
async with async_db_session.begin() as db:
from backend.utils.snowflake import snowflake
from backend.app.admin.service.points_service import points_service
# 使用退款记录主键 id 作为 out_refund_no
generated_id = snowflake.generate()
compute = await WxPayService.compute_refund_amount_for_out_trade(out_trade_no)
@@ -318,7 +319,6 @@ class WxPayService:
amt_per_point = float(compute.get('amount_per_point') or 0)
final_amount = min(amount_cents or 0, max_refund)
points_to_freeze = int(final_amount / amt_per_point) if amt_per_point > 0 else 0
from backend.app.admin.service.points_service import points_service
order_obj = await wx_order_dao.get_by_out_trade_no(db, out_trade_no)
if order_obj:
await points_service.freeze_points_for_order(db, order_obj.user_id, order_obj.id, points_to_freeze)
@@ -334,14 +334,14 @@ class WxPayService:
await db.flush()
await db.refresh(refund)
notify_url = f"{settings.SERVER_HOST}:{settings.SERVER_PORT}{settings.FASTAPI_API_V1_PATH}/wxpay/notify"
notify_url = f"{settings.SERVER_HOST}:{settings.SERVER_PORT}{settings.FASTAPI_API_V1_PATH}/wxpay/notify/refund"
# notify_url = f"https://app.xhzone.cn:{settings.SERVER_PORT}{settings.FASTAPI_API_V1_PATH}/wxpay/notify"
wxpay = WxPayService._build_wxpay_instance(notify_url)
result = WxPayService._safe_call(
wxpay.refund,
out_trade_no=out_trade_no,
out_refund_no=str(refund.id),
amount={"refund": final_amount, "total": final_amount, "currency": "CNY"},
amount={"refund": final_amount, "total": order_obj.amount_cents, "currency": "CNY"},
reason=reason or "",
)
data = WxPayService._parse_result(result)

View File

@@ -89,5 +89,4 @@ class UpdateImageParam(ImageInfoSchemaBase):
class ProcessImageRequest(BaseModel):
file_id: str
type: str = "word"
dict_level: Optional[DictLevel] = Field(None, description="词典等级")
type: str = "word"

View File

@@ -45,6 +45,7 @@ from backend.app.admin.service.yd_dict_service import yd_dict_service
from backend.app.admin.service.points_service import points_service
from backend.app.admin.service.dict_service import dict_service
from backend.database.redis import redis_client
from backend.app.admin.schema.wx import DictLevel
DAILY_IMAGE_RECOGNITION_MAX_TIMES = 3
@@ -192,9 +193,7 @@ class ImageService:
current_user = request.user
file_id = int(params.file_id)
type = params.type
dict_level = params.dict_level.value
if not dict_level:
dict_level = current_user.dict_level.value
dict_level = DictLevel.LEVEL1.value
# 检查用户积分是否足够(现在积分没有过期概念)
if not await points_service.check_sufficient_points(current_user.id, IMAGE_RECOGNITION_COST):
@@ -359,6 +358,7 @@ class ImageService:
try:
from backend.app.ai.service.sentence_service import SentenceService
if task:
logger.info(f"Create scene sentence task for image {task.image_id}")
await SentenceService.create_scene_task(task.image_id, task.user_id, 'scene_sentence')
except Exception as scene_err:
logger.error(f"Failed to create scene sentence task for task {task_id}: {str(scene_err)}")