discount/wwwroot/api/get_customer_sale_list.dspy

23 lines
654 B
Plaintext

# 获取当前机构下的客户及销售归属
userorgid = await get_userorgid()
if not userorgid:
return []
db = DBPools()
resellerid = userorgid
sql = """
select o.id as customerid, o.orgname as customer_name,
dcb.id as bind_id, dcb.sale_id,
u.nick_name as sale_name
from organization o
left join discount_customer_bind dcb on dcb.customerid = o.id and dcb.resellerid = ${resellerid}$
left join users u on u.id = dcb.sale_id
where o.org_type = 'customer' and o.parentid = ${resellerid}$
order by o.orgname
"""
async with db.sqlorContext('sage') as sor:
rows = await sor.sqlExe(sql, {'resellerid': resellerid})
return rows