accounting/accounting/recharge.py
2025-01-08 16:50:37 +08:00

87 lines
2.5 KiB
Python

from datetime import datetime
from appPublic.uniqueID import getID
from sqlor.dbpools import DBPools
from appPublic.timeUtils import curDateString
from appPublic.argsConvert import ArgsConvert
from .accounting_config import get_accounting_config, Accounting
from .const import *
from .excep import *
from .getaccount import getAccountByName
from .businessdate import get_business_date
class RechargeAccounting:
def __init__(self, recharge_log):
self.db = DBPools()
self.recharge_log = recharge_log
self.customerid = recharge_log['customerid']
self.orderid = recharge_log['orderid']
self.curdate = recharge_log['transdate']
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.variable = {
"交易金额":100,
"充值费率":0.003,
}
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 get_account(self, leg):
if leg.orgtype == '平台':
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)
ao = Accounting(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
async def write_bill(self, sor):
await sor.C('bill', self.bill.copy())
# await sor.C('recharge_log', self.recharge_log.copy())
async def recharge_accounting(sor, customerid, action, orderid, transdate, recharge_amt):
"""
summary:recharge channe(handly, wechat, alipay)
"""
recharge_log = {
"customerid":customerid,
"transdate":transdate,
"orderid":orderid,
"recharge_amt":recharge_amt,
"action":action,
}
ra = RechargeAccounting(recharge_log)
if sor:
r = await ra.accounting(sor)
return True
db = DBPools()
dbname = await rfrun('get_module_dbname', 'accounting')
async with db.sqlorContext(dbname) as sor:
r = await ra.accounting(sor)
return True