from datetime import datetime from appPublic.uniqueID import getID from appPublic.log import debug, exception from sqlor.dbpools import DBPools from appPublic.timeUtils import curDateString from appPublic.argsConvert import ArgsConvert from appbase.businessdate import get_business_date from .getdbname import get_dbname from .accounting_config import get_accounting_config, Accounting, PFBiz from .const import * from .excep import * from .getaccount import getAccountByName class RechargeBiz(PFBiz): def __init__(self, recharge_log): self.db = DBPools() self.recharge_log = recharge_log self.customerid = recharge_log['customerid'] self.resellerid = None 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 = { "交易金额":recharge_log['recharge_amt'], "充值费率":recharge_log['recharge_feerate'], } self.bill = { 'id':self.billid, 'customerid':self.recharge_log['customerid'], 'resellerid':None, 'orderid':recharge_log['orderid'], 'business_op':self.recharge_log['action'], 'amount':self.recharge_log['recharge_amt'], 'bill_date':self.curdate, 'bill_timestamp':self.timestamp } async def get_orgid_by_trans_role(self, sor, leg, role): if role == 'owner': return '0' if role == 'customer': return self.customerid if role is None or role == 'null': return None e = Exception(f'unknown role({role})') exception(f'Exception:{e}') raise e 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) await self.write_bill(sor) await ao.do_accounting(sor) 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, recharge_feerate): """ summary:recharge channe(handly, wechat, alipay) """ if action not in ['RECHARGE', 'RECHARGE_REVESE']: e = Exception(f'get a wrong recharge action({action})') exception(f'{e}') raise e recharge_log = { "customerid":customerid, "transdate":transdate, "orderid":orderid, "recharge_amt":recharge_amt, "recharge_feerate": recharge_feerate, "action":action, } ra = RechargeBiz(recharge_log) if sor: r = await ra.accounting(sor) return True db = DBPools() dbname = get_dbname() async with db.sqlorContext(dbname) as sor: r = await ra.accounting(sor) return True