from datetime import datetime from appPublic.uniqueID import getID 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, Accounting from .const import * from .accountingnode import get_accounting_nodes from .excep import * from .getaccount import getAccountByName class ConsumeBiz(PFBiz): def __init__(self, od): self.db = DBPools() self.action = od.action self.orderid = od['orderid'] self.timestamp = timestampstr() self.action = od['action'] self.billid = getID() 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'] } 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 async def consume_accounting(sor, orderid, order_details): ods = [] billid = getID() env = ServerEnv() curdate = await env.get_business_date(sor) for od in order_details: od['billid'] = billid od['orderid'] = orderid od['curdate'] = curdate 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':curdate, 'bill_timestamp':self.timestamp } await sor.C('bill', bill.copy()) await ao.do_accounting(sor)