platformbiz/platformbiz/pb_acc.py
2025-01-11 19:40:06 +08:00

59 lines
1.7 KiB
Python

import time
from appPublic.timeUtils import timestampstr
from ahserver.serverenv import get_serverenv
from accounting.accounting_config import Accounting
from accounting.bill import write_bill
def get_owner_orgid(sor, orgid):
return '0'
class PlatformBizAcc:
async def get_orgid_by_trans_role(self, sor, orgtype):
if orgtype== 'customer':
return self.customerid
if orgtype== 'reseller':
return self.resellerid
if orgtype== 'provider':
return self.providerid
if orgtype == 'owner':
return '0'
return None
class PlatformBizAccRecharge(PlatformBizAcc):
def __init__(self, rlid):
self.rlid = rlid
async def accounting(self, sor):
sql = """select * from recharge_log where id=${rlid}$"""
recs = await sor.sqlExe(sql, {'rlid':self.rlid})
if len(recs) < 1:
e = Exception(f'get recharge log err by {rlid=}')
exception(f'{e=}')
raise e
self.recharge = recs[0]
self.customerid = self.recharge.customerid
self.orderid = self.recharge.orderid
self.userid = self.recharge.userid
get_business_date = get_serverenv('get_business_date')
self.curdate = await get_business_date(sor)
self.variable = {
"交易金额":self.recharge.recharge_amt,
"充值费率":self.recharge.fee_rate,
"充值费用":self.recharge.feemat
}
bill = await write_bill(sor, self.customerid, self.userid,
self.recharge.orderid,
self.recharge.action,
self.recharge.recharge_amt)
self.billid = bill.id
self.bill = bill
self.providerid = None
self.resellerid = None
self.action = self.recharge.action
self.productid = None
self.timestamp = timestampstr()
a = Accounting(self)
r = await a.do_accounting(sor)