accounting/accounting/test_accounting.py
2026-04-10 21:22:27 +08:00

67 lines
1.5 KiB
Python

import asyncio
import sys
from sqlor.dbpools import DBPools, get_sor_context
from appPublic.dictObject import DictObject
from appPublic.timeUtils import curDateString, timestampstr
from accounting.consume import consume_accounting
from ahserver.serverenv import ServerEnv
def get_module_dbname(m):
retrun 'sage'
async def get_orgid_by_username(sor, username):
recs = await sor.R('users', {'username': username})
if len(recs):
return recs[0].orgid
return None
async def accounting(username):
env = ServerEnv()
async with get_sor_context(env, 'accounting') as sor:
customerid = await get_orgid_by_username(sor, username)
resellerid = '0'
ais = []
for i in range(10):
d = DictObject()
d.customerid = customerid
d.resellerid = '0'
d.action = 'PAY_REVERSE' if i % 2 ==0 else 'PAY'
d.biz_date = curDateString()
d.timestamp = timstampstr()
d.productid = 'test_product'
d.transamt = 123.432
d.variable = {
"交易金额": 123.432,
"交易手续费": 0
}
ais.append(d)
orderid = 'test_orderid'
await consume_accounting(sor, orderid, ais)
async def main():
if len(sys.argv) < 2:
print(f'{sys.argv[0]} username')
sys.exit(1)
username = sys.argv[1]
await accounting(username)
if __name__ == '__main__':
databases = {
"sage":{
"driver":"mysql",
"kwargs":{
"user":"test",
"db":"sage",
"password":"SS+C1MDMJrslBwGzYIv3nQ==",
"charset": "utf8mb4",
"host":"db"
}
}
}
DBPools(databases)
env = ServerEnv()
env.get_module_dbname = get_module_dbname
asyncio.run(main())