From e4b746be5cbb9d57fc900ac7a993269b245784fb Mon Sep 17 00:00:00 2001 From: yumoqing Date: Tue, 14 Jul 2026 10:41:52 +0800 Subject: [PATCH] fix: init_free_customers allow owner org, use users.orgid as resellerid --- wwwroot/api/init_free_customers.dspy | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/wwwroot/api/init_free_customers.dspy b/wwwroot/api/init_free_customers.dspy index 96959d2..279fc91 100644 --- a/wwwroot/api/init_free_customers.dspy +++ b/wwwroot/api/init_free_customers.dspy @@ -1,16 +1,19 @@ -"""Initialize discount_customer_bind for all users in current org. -Users without a bind record get bind_type='3' (domain registration), sale_id=NULL.""" +"""Initialize discount_customer_bind for all users who don't have a bind record. +Each user is bound to their own org (users.orgid) as resellerid, bind_type='3'.""" userorgid = await get_userorgid() -if not userorgid or userorgid == '0': - return {'widgettype': 'Error', 'options': {'title': 'Error', 'message': '仅机构用户可执行', 'timeout': 3}} +if not userorgid: + return {'widgettype': 'Error', 'options': {'title': 'Error', 'message': '请先登录', 'timeout': 3}} count = 0 async with DBPools().sqlorContext('sage') as sor: - # Get all users in this org - users = await sor.sqlExe( - 'SELECT id, orgid FROM users WHERE orgid = ${oid}$', - {'oid': userorgid} - ) + # Get all users (filtered by org if not owner) + if userorgid == '0': + users = await sor.sqlExe('SELECT id, orgid FROM users', {}) + else: + users = await sor.sqlExe( + 'SELECT id, orgid FROM users WHERE orgid = ${oid}$', + {'oid': userorgid} + ) if not users: return {'widgettype': 'Message', 'options': {'title': '提示', 'message': '该机构下无用户', 'type': 'warning', 'timeout': 3}}