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 datetime import datetime
from appPublic.uniqueID import getID from appPublic.uniqueID import getID
from sqlor.dbpools import DBPools from sqlor.dbpools import DBPools
from appPublic.timeUtils import curDateString from appPublic.timeUtils import curDateString, timestampstr
from appPublic.argsConvert import ArgsConvert 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 .const import *
from .accountingnode import get_accounting_nodes from .accountingnode import get_accounting_nodes
from .excep import * from .excep import *
from .getaccount import getAccountByName from .getaccount import getAccountByName
from .businessdate import get_business_date from .businessdate import get_business_date
class ConsumeAccounting: class ConsumeBiz(PFBiz):
def __init__(self, cnsume_log): def __init__(self, consume_logs):
self.db = DBPools() self.db = DBPools()
self.recharge_log = recharge_log self.consume_logs = consume_logs
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
}
async def accounting(self, sor): async def accounting(self, sor):
self.sor = sor self.sor = sor
bz_date = await get_business_date(sor=sor) self.orderid = self.consume_logs[0]['orderid']
if bz_date != self.curdate: self.curdate = await get_business_date(sor)
raise AccountingDateNotInBusinessDate(self.curdate, bz_date) 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) for i, log in enumerate(self.consume_logs):
lst = len(nodes) - 1 self.customerid = log['customerid']
self.accountingOrgs = [] self.resellerid = log['resellerid']
for i, n in enumerate(nodes): self.transamount = log['recharge_amt']
if i < lst: self.productid = log['productid']
ao = AccountingOrgs(self, nodes[i], self.customerid, # self.providerid = log['providerid']
resellerid=nodes[i+1]) self.summary = f'{self.action}|{self.customerid}|{self.resellerid}|{self.productid}'
else: self.variable = {
ao = AccountingOrgs(self, nodes[i], self.customerid) "交易金额": log['transamt'],
self.accountingOrgs.append(ao) "交易手续费": log['transfee']
await self.write_bill(sor) }
[await ao.do_accounting(sor) for ao in self.accountingOrgs ] if i == 0:
print(f'recharge ok for {self.bill}, {nodes=}') self.bill = {
return True '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): async def get_orgid_by_trans_role(self, sor, leg, role):
await sor.C('bill', self.bill.copy()) if role == 'owner':
# await sor.C('recharge_log', self.recharge_log.copy()) 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.getaccount import getAccountBalance, getCustomerBalance, getAccountByName, get_account_total_amount
from accounting.bizaccount import BizAccounting from accounting.bizaccount import BizAccounting
from accounting.recharge import RechargeBiz, recharge_accounting from accounting.recharge import RechargeBiz, recharge_accounting
from comsume import ConsumeBiz
def load_accounting(): def load_accounting():
g = ServerEnv() g = ServerEnv()
g.Accounting = Accounting g.Accounting = Accounting
g.RechargeBiz = RechargeBiz g.RechargeBiz = RechargeBiz
g.ConsumeBiz = ConsumeBiz
g.write_bill = write_bill g.write_bill = write_bill
g.openOwnerAccounts = openOwnerAccounts g.openOwnerAccounts = openOwnerAccounts
g.openProviderAccounts = openProviderAccounts g.openProviderAccounts = openProviderAccounts