This commit is contained in:
yumoqing 2025-12-16 14:51:59 +08:00
parent d87a6c5bad
commit ec250a1593
2 changed files with 55 additions and 47 deletions

View File

@ -1,63 +1,69 @@
from datetime import datetime
from appPublic.uniqueID import getID
from sqlor.dbpools import DBPools
from appPublic.timeUtils import curDateString
from appPublic.timeUtils import curDateString, timestampstr
from appPublic.argsConvert import ArgsConvert
from .accounting_config import get_accounting_config, AccountingOrgs
from appbase.businessdate import get_business_date
from .accounting_config import get_accounting_config, PFBiz
from .const import *
from .accountingnode import get_accounting_nodes
from .excep import *
from .getaccount import getAccountByName
from .businessdate import get_business_date
class ConsumeAccounting:
def __init__(self, cnsume_log):
class ConsumeBiz(PFBiz):
def __init__(self, consume_logs):
self.db = DBPools()
self.recharge_log = recharge_log
self.customerid = recharge_log['customerid']
self.orderid = None
self.curdate = recharge_log['recharge_date']
self.transamount = recharge_log['recharge_amt']
self.timestamp = datetime.now()
self.productid = None
self.providerid = None
self.action = recharge_log['action']
self.summary = self.action
self.billid = getID()
self.bill = {
'id':self.billid,
'customerid':self.recharge_log['customerid'],
'resellerid':None,
'orderid':None,
'business_op':self.recharge_log['action'],
'amount':self.recharge_log['recharge_amt'],
'bill_date':self.curdate,
'bill_timestamp':self.timestamp
}
self.consume_logs = consume_logs
async def accounting(self, sor):
self.sor = sor
bz_date = await get_business_date(sor=sor)
if bz_date != self.curdate:
raise AccountingDateNotInBusinessDate(self.curdate, bz_date)
self.orderid = self.consume_logs[0]['orderid']
self.curdate = await get_business_date(sor)
self.timestamp = timestampstr()
self.action = self.consume_logs[0]['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
nodes = await get_accounting_nodes(sor, self.customerid)
lst = len(nodes) - 1
self.accountingOrgs = []
for i, n in enumerate(nodes):
if i < lst:
ao = AccountingOrgs(self, nodes[i], self.customerid,
resellerid=nodes[i+1])
else:
ao = AccountingOrgs(self, nodes[i], self.customerid)
self.accountingOrgs.append(ao)
await self.write_bill(sor)
[await ao.do_accounting(sor) for ao in self.accountingOrgs ]
print(f'recharge ok for {self.bill}, {nodes=}')
return True
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 write_bill(self, sor):
await sor.C('bill', self.bill.copy())
# await sor.C('recharge_log', self.recharge_log.copy())
async def get_orgid_by_trans_role(self, sor, leg, role):
if role == 'owner':
return '0'
if role == 'customer':
return self.customerid
if role == 'reseller':
return self.resellerid
if role is None or role == 'null':
return None
e = Exception(f'unknown role({role})')
exception(f'Exception:{e}')
raise e

View File

@ -8,11 +8,13 @@ from accounting.openaccount import openOwnerAccounts, openProviderAccounts, open
from accounting.getaccount import getAccountBalance, getCustomerBalance, getAccountByName, get_account_total_amount
from accounting.bizaccount import BizAccounting
from accounting.recharge import RechargeBiz, recharge_accounting
from comsume import ConsumeBiz
def load_accounting():
g = ServerEnv()
g.Accounting = Accounting
g.RechargeBiz = RechargeBiz
g.ConsumeBiz = ConsumeBiz
g.write_bill = write_bill
g.openOwnerAccounts = openOwnerAccounts
g.openProviderAccounts = openProviderAccounts