新增3张核心表: - platform_supply_relations: 平台内org-to-org供销关系(分销/代理/直供) - platform_supply_products: 供销产品明细(供货价/折扣/佣金) - product_supplier_mapping: 统一产品供应映射(内部+外部) 新增3个业务API: - query_platform_suppliers: 查询平台可用供应方机构 - query_platform_products: 查询供应方产品目录 - import_supplier_product: 引入供应方产品到需求方 更新: init/data.json(6组appcodes), load_path.py(RBAC权限), menu.ui(分组菜单)
183 lines
4.0 KiB
Plaintext
183 lines
4.0 KiB
Plaintext
|
|
ns = params_kw.copy()
|
|
|
|
|
|
userorgid = await get_userorgid()
|
|
if not userorgid:
|
|
return {
|
|
"widgettype":"Error",
|
|
"options":{
|
|
"title":"Authorization Error",
|
|
"timeout":3,
|
|
"cwidth":16,
|
|
"cheight":9,
|
|
"message":"Please login"
|
|
}
|
|
}
|
|
ns['resellerid'] = userorgid
|
|
ns['userorgid'] = userorgid
|
|
|
|
debug(f'get_sub_resellers.dspy:{ns=}')
|
|
if not ns.get('page'):
|
|
ns['page'] = 1
|
|
if not ns.get('sort'):
|
|
|
|
|
|
ns['sort'] = ["created_at desc"]
|
|
|
|
|
|
|
|
sql = '''select a.*, b.resellerid_text
|
|
from (select * from sub_resellers where 1=1 [[filterstr]]) a left join (select id as resellerid,
|
|
orgname as resellerid_text from organization where 1 = 1) b on a.resellerid = b.resellerid'''
|
|
|
|
filterjson = params_kw.get('data_filter')
|
|
if filterjson and isinstance(filterjson, str):
|
|
try:
|
|
filterjson = json.loads(filterjson)
|
|
except (json.JSONDecodeError, TypeError):
|
|
filterjson = None
|
|
fields_str=r'''[
|
|
{
|
|
"name": "id",
|
|
"title": "主键ID",
|
|
"type": "str",
|
|
"length": 32,
|
|
"nullable": "no"
|
|
},
|
|
{
|
|
"name": "resellerid",
|
|
"title": "所属分销商机构ID",
|
|
"type": "str",
|
|
"length": 32,
|
|
"nullable": "no"
|
|
},
|
|
{
|
|
"name": "sub_reseller_code",
|
|
"title": "二级分销商编号",
|
|
"type": "str",
|
|
"length": 64,
|
|
"nullable": "no"
|
|
},
|
|
{
|
|
"name": "sub_reseller_name",
|
|
"title": "二级分销商名称",
|
|
"type": "str",
|
|
"length": 255,
|
|
"nullable": "no"
|
|
},
|
|
{
|
|
"name": "contact_person",
|
|
"title": "联系人",
|
|
"type": "str",
|
|
"length": 100
|
|
},
|
|
{
|
|
"name": "contact_phone",
|
|
"title": "联系电话",
|
|
"type": "str",
|
|
"length": 50
|
|
},
|
|
{
|
|
"name": "contact_email",
|
|
"title": "联系邮箱",
|
|
"type": "str",
|
|
"length": 255
|
|
},
|
|
{
|
|
"name": "address",
|
|
"title": "地址",
|
|
"type": "str",
|
|
"length": 500
|
|
},
|
|
{
|
|
"name": "tax_number",
|
|
"title": "税号",
|
|
"type": "str",
|
|
"length": 64
|
|
},
|
|
{
|
|
"name": "bank_name",
|
|
"title": "开户银行",
|
|
"type": "str",
|
|
"length": 255
|
|
},
|
|
{
|
|
"name": "bank_account",
|
|
"title": "银行账号",
|
|
"type": "str",
|
|
"length": 64
|
|
},
|
|
{
|
|
"name": "status",
|
|
"title": "状态",
|
|
"type": "char",
|
|
"length": 1,
|
|
"nullable": "no",
|
|
"default": "1"
|
|
},
|
|
{
|
|
"name": "remark",
|
|
"title": "备注",
|
|
"type": "text"
|
|
},
|
|
{
|
|
"name": "created_by",
|
|
"title": "创建人",
|
|
"type": "str",
|
|
"length": 32
|
|
},
|
|
{
|
|
"name": "created_at",
|
|
"title": "创建时间",
|
|
"type": "datetime",
|
|
"nullable": "no"
|
|
},
|
|
{
|
|
"name": "updated_at",
|
|
"title": "更新时间",
|
|
"type": "datetime"
|
|
}
|
|
]'''
|
|
ori_fields = json.loads(fields_str)
|
|
if not filterjson:
|
|
fields = [ f['name'] for f in ori_fields ]
|
|
filterjson = default_filterjson(fields, ns)
|
|
|
|
# 确保 logined 过滤条件始终生效
|
|
if filterjson:
|
|
if not isinstance(filterjson, dict) or 'AND' not in filterjson:
|
|
filterjson = {'AND': [filterjson] if filterjson else []}
|
|
|
|
filterjson['AND'].append({'field': 'resellerid', 'op': '=', 'var': '__logined_orgid__'})
|
|
ns['__logined_orgid__'] = userorgid
|
|
|
|
|
|
|
|
filterdic = ns.copy()
|
|
filterdic['filterstr'] = ''
|
|
filterdic['userorgid'] = '${userorgid}$'
|
|
filterdic['userid'] = '${userid}$'
|
|
if filterjson:
|
|
dbf = DBFilter(filterjson)
|
|
conds = dbf.gen(ns)
|
|
if conds:
|
|
ns.update(dbf.consts)
|
|
conds = f' and {conds}'
|
|
filterdic['filterstr'] = conds
|
|
ac = ArgsConvert('[[', ']]')
|
|
vars = ac.findAllVariables(sql)
|
|
NameSpace = {v:'${' + v + '}$' for v in vars if v != 'filterstr' }
|
|
filterdic.update(NameSpace)
|
|
sql = ac.convert(sql, filterdic)
|
|
|
|
debug(f'{sql=}')
|
|
db = DBPools()
|
|
dbname = get_module_dbname('supplychain')
|
|
async with db.sqlorContext(dbname) as sor:
|
|
r = await sor.sqlPaging(sql, ns)
|
|
return r
|
|
return {
|
|
"total":0,
|
|
"rows":[]
|
|
} |