From d392edb8c1516ce2e6d4c3d5457e949f90368882 Mon Sep 17 00:00:00 2001 From: yumoqing Date: Fri, 26 Dec 2025 18:41:56 +0800 Subject: [PATCH] bugfix --- accounting/consume.py | 75 +++++++++++++++++++++---------------------- 1 file changed, 36 insertions(+), 39 deletions(-) diff --git a/accounting/consume.py b/accounting/consume.py index 7b2d68c..0c3af10 100644 --- a/accounting/consume.py +++ b/accounting/consume.py @@ -4,55 +4,32 @@ from sqlor.dbpools import DBPools from appPublic.timeUtils import curDateString, timestampstr from appPublic.argsConvert import ArgsConvert from appbase.businessdate import get_business_date -from .accounting_config import get_accounting_config, PFBiz +from .accounting_config import get_accounting_config, PFBiz, Accounting from .const import * from .accountingnode import get_accounting_nodes from .excep import * from .getaccount import getAccountByName class ConsumeBiz(PFBiz): - def __init__(self, consume_logs): + def __init__(self, od): self.db = DBPools() - self.consume_logs = consume_logs - - async def accounting(self, sor): - self.sor = sor - self.orderid = self.consume_logs[0]['orderid'] + self.action = od.action + self.orderid = od['orderid'] self.curdate = await get_business_date(sor) self.timestamp = timestampstr() - self.action = self.consume_logs[0]['action'] + self.action = od['action'] self.billid = getID() - if self.action not in ['PAY', 'PAY_REVERSE']: - e = Exception(f'{self.action} action not defined') - exception(f'{__file__}:{__line__}:{e}') - raise e + self.customerid = od['customerid'] + self.resellerid = od['resellerid'] + self.transamount = od['recharge_amt'] + self.productid = od['productid'] + # self.providerid = od['providerid'] + self.summary = f'{self.action}|{self.customerid}|{self.resellerid}|{self.productid}' + self.variable = { + "交易金额": log['transamt'], + "交易手续费": log['transfee'] + } - for i, log in enumerate(self.consume_logs): - self.customerid = log['customerid'] - self.resellerid = log['resellerid'] - self.transamount = log['recharge_amt'] - self.productid = log['productid'] - # self.providerid = log['providerid'] - self.summary = f'{self.action}|{self.customerid}|{self.resellerid}|{self.productid}' - self.variable = { - "交易金额": log['transamt'], - "交易手续费": log['transfee'] - } - if i == 0: - self.bill = { - 'id':self.billid, - 'customerid':self.customerid, - 'resellerid':self.resellerid, - 'orderid':self.orderid, - 'business_op':self.action, - 'amount':log['transamt'], - 'bill_date':self.curdate, - 'bill_timestamp':self.timestamp - } - await sor.C('bill', self.bill.copy()) - ao = Accounting(self) - await ao.do_accounting(sor) - async def get_orgid_by_trans_role(self, sor, leg, role): if role == 'owner': return '0' @@ -65,4 +42,24 @@ class ConsumeBiz(PFBiz): e = Exception(f'unknown role({role})') exception(f'Exception:{e}') raise e - + +async def consume_accounting(sor, orderid, order_details): + ods = [] + billid = getID() + for od in order_details: + od['billid'] = billid + od['orderid'] = orderid + ods.append(ConsumeBiz(od)) + ao = Accounting(ods) + bill = { + 'id':self.billid, + 'customerid':self.customerid, + 'resellerid':self.resellerid, + 'orderid':self.orderid, + 'business_op':self.action, + 'amount':log['transamt'], + 'bill_date':self.curdate, + 'bill_timestamp':self.timestamp + } + await sor.C('bill', bill.copy()) + await ao.do_accounting(sor)