Merge branch 'main' of git.opencomputing.cn:yumoqing/kboss

This commit is contained in:
hrx 2026-06-08 17:12:17 +08:00
commit 3c477ef593
3 changed files with 14 additions and 4 deletions

View File

@ -178,7 +178,7 @@ async def _query_model_usage_rows(sor, conditions, limit=None, offset=None):
sql = """
SELECT id, userid, llmid, original_price, orderid, bill_status, usage_content, created_at
FROM model_usage
WHERE %s
WHERE %s AND bill_status = '0'
ORDER BY created_at DESC
""" % where_clause
if limit is not None:
@ -188,7 +188,7 @@ async def _query_model_usage_rows(sor, conditions, limit=None, offset=None):
async def _count_model_usage(sor, conditions):
where_clause = ' AND '.join(conditions) if conditions else '1 = 1'
sql = 'SELECT COUNT(*) AS total_count FROM model_usage WHERE %s' % where_clause
sql = 'SELECT COUNT(*) AS total_count FROM model_usage WHERE %s AND bill_status = "0"' % where_clause
return (await sor.sqlExe(sql, {}))[0]['total_count']

View File

@ -95,7 +95,7 @@ def _normalize_usage_row(row, bill_amount_map=None):
'prompt_tokens': int(usage.get('prompt_tokens') or 0),
'completion_tokens': int(usage.get('completion_tokens') or 0),
'total_tokens': int(usage.get('total_tokens') or 0),
'amount': round(amount, 4),
'amount': round(amount, 2),
'bill_status': row.get('bill_status'),
'orderid': orderid,
'usage_time': row.get('created_at'),
@ -155,7 +155,7 @@ async def _query_model_usage_rows(sor, conditions, limit=None, offset=None):
sql = """
SELECT id, userid, llmid, original_price, orderid, bill_status, usage_content, created_at
FROM model_usage
WHERE %s
WHERE %s AND bill_status = '0'
ORDER BY created_at DESC
""" % where_clause
if limit is not None:

View File

@ -260,6 +260,13 @@ async def process_user_billing(ns={}):
'status': 'error',
'msg': 'llmid必传'
}
model_name = ns.get('model')
if not model_name:
debug(f"{userid} process_user_billing model必传")
return {
'status': 'error',
'msg': 'model必传'
}
try:
amount = round(float(amount), 12)
@ -275,6 +282,9 @@ async def process_user_billing(ns={}):
async with db.sqlorContext('kboss') as sor:
try:
product_li = await sor.R('product', {'providerpid': llmid, 'del_flg': '0'})
if not product_li:
product_li = await sor.R('product', {'product_code': model_name, 'del_flg': '0'})
if not product_li:
debug(f"{userid} process_user_billing 未找到对应产品,请确认")
return {