| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- from redis.asyncio import Redis
- from app.api.v1.module_system.auth.schema import AuthSchema
- from app.core.logger import log
- from app.plugin.module_payment.account.service import AccountService
- from ..schemas import ConsumeChangeContent, VoucherChangeContent
- from .base_handler import BaseHandler
- class BillHandler(BaseHandler[dict]):
- """账单变动通知处理器"""
- async def handle(self, method: str, content: dict, auth: AuthSchema, redis: Redis) -> bool:
- """
- 处理账单变动通知
- """
- try:
- notify_data = ConsumeChangeContent(**content)
- except Exception as e:
- log.error(f"解析账单通知内容失败: {e}")
- return False
- try:
- return await self._process_bill(notify_data, auth)
- except Exception as e:
- log.error(f"处理账单变动通知异常: {e}")
- return False
- async def _process_bill(self, data: ConsumeChangeContent, auth: AuthSchema) -> bool:
- """处理账单"""
- log.info(
- f"账单变动: pay_no={data.pay_no}, "
- f"enterprise_id={data.enterprise_id}, "
- f"consume_amount={data.consume_amount}, "
- f"consume_type={data.consume_type}"
- )
- if data.consume_type == "TRANSFER":
- await AccountService.update_transfer_status_service(
- auth, data.pay_no, "SUCCESS", data.model_dump(exclude_none=True)
- )
-
- return True
-
- async def _handle_trans_change(self, content: dict, auth: AuthSchema) -> bool:
- """
- 处理转账变动通知
- ● 功能说明:转账结果通知,单笔交易账单信息变化时通知。
- ○ 通知中"consume_type":"TRANSFER",可以用于判断转账是否成功。
- """
- return False
- class VoucherHandler(BaseHandler[dict]):
- """凭证变动通知处理器"""
- async def handle(self, method: str, content: dict, auth: AuthSchema, redis: Redis) -> bool:
- """
- 处理凭证变动通知
- """
- try:
- notify_data = VoucherChangeContent(**content)
- except Exception as e:
- log.error(f"解析凭证通知内容失败: {e}")
- return False
- action = notify_data.action
- voucher_id = notify_data.voucher_id
- log.info(f"处理凭证变动通知: action={action}, voucher_id={voucher_id}")
- try:
- return await self._process_voucher(notify_data, auth)
- except Exception as e:
- log.error(f"处理凭证变动通知异常: {e}")
- return False
- async def _process_voucher(self, data: VoucherChangeContent, auth: AuthSchema) -> bool:
- """处理凭证"""
- log.info(
- f"凭证变动: voucher_id={data.voucher_id}, "
- f"enterprise_id={data.enterprise_id}, "
- f"action={data.action}"
- )
- return True
|