result = {'widgettype': 'Message', 'options': {'title': 'Error', 'message': 'Invalid', 'type': 'error'}} try: user_id = await get_user() user_orgid = (await get_userorgid()) or '0' dbname = get_module_dbname('supplychain') data = dict(params_kw) item_id = getID() data['id'] = item_id data['resellerid'] = user_orgid data['created_at'] = timestampstr() data['updated_at'] = timestampstr() product_id = data.get('productid') agreement_id = data.get('agreement_id') async with DBPools().sqlorContext(dbname) as sor: await sor.C('distribution_agreement_items', data) # Sync product_org_auth: sub_reseller's org gets product auth if product_id and agreement_id: async with DBPools().sqlorContext(dbname) as sor: ag_recs = await sor.sqlExe( 'SELECT sub_reseller_id FROM distribution_agreements WHERE id = ${aid}$', {'aid': agreement_id} ) if ag_recs: sub_id = ag_recs[0].sub_reseller_id async with DBPools().sqlorContext('sage') as sor_sage: await sor_sage.C('product_org_auth', { 'id': getID(), 'product_id': product_id, 'org_id': sub_id, 'auth_source': 'distribution_agreement', 'auth_source_id': item_id, }) result = {'widgettype': 'Message', 'options': {'title': 'Success', 'message': '分销协议项目创建成功', 'type': 'success'}} except Exception as e: result['options'] = {'title': 'Error', 'message': '创建失败: ' + str(e), 'type': 'error'} return result