fix: remove ns['sort'] to avoid sqlPaging outer ORDER BY conflict

This commit is contained in:
yumoqing 2026-07-04 19:56:56 +08:00
parent 9c7a39e519
commit 9645d397b6

View File

@ -13,8 +13,6 @@ if not user_orgid:
ns = params_kw.copy() ns = params_kw.copy()
if not ns.get('page'): if not ns.get('page'):
ns['page'] = 1 ns['page'] = 1
if not ns.get('sort'):
ns['sort'] = 'pc_name, product_name'
ns['org_id'] = user_orgid ns['org_id'] = user_orgid
@ -30,9 +28,8 @@ async with db.sqlorContext(dbname) as sor:
sql = ''' sql = '''
SELECT SELECT
p.id as productid, p.id as productid,
pc.name as pc_name,
p.product_name,
p.product_code, p.product_code,
p.product_name,
p.category_id, p.category_id,
pc.name as category_name, pc.name as category_name,
dd.id as detail_id, dd.id as detail_id,
@ -46,10 +43,11 @@ LEFT JOIN discount_detail dd ON dd.productid = p.id
LEFT JOIN discount_detail base_dd ON base_dd.productid = p.id LEFT JOIN discount_detail base_dd ON base_dd.productid = p.id
AND base_dd.discountid = ${base_discountid}$ AND base_dd.discountid = ${base_discountid}$
WHERE p.org_id = ${org_id}$ AND p.status = '1' WHERE p.org_id = ${org_id}$ AND p.status = '1'
ORDER BY pc.name, p.product_name
''' '''
debug(f'get_products_with_discount: org_id={user_orgid}, discountid={discountid}, dbname={dbname}, base_discountid={ns["base_discountid"]}') debug(f'get_products_with_discount: org_id={user_orgid}, discountid={discountid}, dbname={dbname}, base_discountid={ns["base_discountid"]}')
async with db.sqlorContext(dbname) as sor: async with db.sqlorContext(dbname) as sor:
r = await sor.sqlPaging(sql, ns.copy()) r = await sor.sqlPaging(sql, ns.copy())
debug(f'{sql=}, {ns=},get_products_with_discount: returned {len(r.get("rows", []))} products') debug(f'{ns=},get_products_with_discount: returned {len(r.get("rows", []))} products')
return r return r