This commit is contained in:
yumoqing 2026-04-10 22:40:52 +08:00
parent 4882b1f8a1
commit cc8cb54a8a
2 changed files with 21 additions and 7 deletions

View File

@ -199,6 +199,13 @@ class Accounting:
async def leg_accounting(self, sor, leg):
# print(f'leg_accounting(), {leg=}')
accid = leg['accid']
sql = "select * from account where id=${accid}$ for update"
accounts = await sor.sqlExe(sql, {'accid': accid})
if len(accounts) == 0:
e = Exception(f'{accid} account not exist')
exception(f'{e}')
raise e
account = accounts[0]
if leg['amount'] < 0.00001:
return
subjects = await sor.R('subject', {'id': leg['subjectid']})
@ -255,6 +262,7 @@ where accountid=${accid}$
ns = {
'id':getID(),
'accountid':accid,
'acc_no': account.max_detailno + 1,
'acc_date':self.curdate,
'acc_timestamp':self.timestamp,
'acc_dir':leg['acc_dir'],
@ -264,5 +272,9 @@ where accountid=${accid}$
'acclogid':logid
}
await sor.C('acc_detail', ns.copy())
await sor.U('account', {'id': accid, 'balance': new_balance})
await sor.U('account', {
'id': accid,
'max_detailno': account.max_detailno + 1,
'balance': new_balance
})

View File

@ -21,11 +21,13 @@ async def get_orgid_by_username(sor, username):
async def accounting(username):
env = ServerEnv()
async with get_sor_context(env, 'accounting') as sor:
customerid = await get_orgid_by_username(sor, username)
customerid = None
for i in range(10):
resellerid = '0'
ais = []
for i in range(10):
async with get_sor_context(env, 'accounting') as sor:
ais = []
if customerid is None:
customerid = await get_orgid_by_username(sor, username)
d = DictObject()
d.customerid = customerid
d.resellerid = '0'
@ -40,8 +42,8 @@ async def accounting(username):
"交易手续费": 0
}
ais.append(d)
orderid = 'test_orderid'
await consume_accounting(sor, orderid, ais)
orderid = 'test_orderid'
await consume_accounting(sor, orderid, ais)
async def main():
if len(sys.argv) < 2: