kboss/b/account/settle_accounts.dspy
2025-07-16 14:27:17 +08:00

64 lines
3.6 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

async def settle_accounts(ns):
"""供应商结算统计 年、月、日、周、季
0实时结算1:日结2:周结3:月结4:季结5年结
参数id 用户id
"""
db = DBPools()
async with db.sqlorContext('kboss') as sor:
try:
orgid = await sor.R('users',ns)
account = await sor.R('account', {'id':orgid[0]['orgid']})
if len(account) >= 1:
newdate = await get_business_date(sor=None)
provider = await sor.R('provider',{'orgid':orgid[0]['orgid']})
if provider[0]['settle_mode'] == '1':
date = strdate_add(newdate,-1,0,0)
bill = await sor.R('bill',{'providerid':provider[0]['id'],'bill_date':date})
if len(bill) >= 1:
for i in bill:
org = await sor.R('organization',{'id':i['customerid']})
i['customerid'] = org[0]
elif provider[0]['settle_mode'] == '2':
date = strdate_add(newdate, -7, 0, 0)
nss = {'providerid': provider[0]['id'], 'bill_date': newdate, 'date': date}
sql = """select * from bill where bill_date > ${date}$ and bill_date < ${newdate}$ and providerid = ${providerid}$;"""
bill = await sor.sqlExe(sql,nss)
if len(bill) >= 1:
for i in bill:
org = await sor.R('organization', {'id': i['customerid']})
i['customerid'] = org[0]
elif provider[0]['settle_mode'] == '3':
date = strdate_add(newdate, 0, -1, 0)
nss = {'providerid': provider[0]['id'], 'bill_date': newdate, 'date': date}
sql = """select * from bill where bill_date > ${date}$ and bill_date < ${newdate}$ and providerid = ${providerid}$;"""
bill = await sor.sqlExe(sql, nss)
if len(bill) >= 1:
for i in bill:
org = await sor.R('organization', {'id': i['customerid']})
i['customerid'] = org[0]
elif provider[0]['settle_mode'] == '4':
date = strdate_add(newdate, 0, -3, 0)
nss = {'providerid': provider[0]['id'], 'bill_date': newdate, 'date': date}
sql = """select * from bill where bill_date > ${date}$ and bill_date < ${newdate}$ and providerid = ${providerid}$;"""
bill = await sor.sqlExe(sql, nss)
if len(bill) >= 1:
for i in bill:
org = await sor.R('organization', {'id': i['customerid']})
i['customerid'] = org[0]
elif provider[0]['settle_mode'] == '5':
date = strdate_add(newdate, 0, 0, -1)
nss = {'providerid': provider[0]['id'], 'bill_date': newdate, 'date': date}
sql = """select * from bill where bill_date > ${date}$ and bill_date < ${newdate}$ and providerid = ${providerid}$;"""
bill = await sor.sqlExe(sql, nss)
if len(bill) >= 1:
for i in bill:
org = await sor.R('organization', {'id': i['customerid']})
i['customerid'] = org[0]
return {'status': True, 'data': bill}
except Exception as e:
raise e
return {'status': False, 'msg': '获取失败'}
ret = await settle_accounts(params_kw)
return ret