- supply_contract_items: revert — products already belong to reseller's own org - distribution_agreement_items: create → insert product_org_auth for sub_reseller - distribution_agreement_items: delete → remove product_org_auth - org_id in product_org_auth = sub_reseller_id (二级分销商)
45 lines
1.6 KiB
Plaintext
45 lines
1.6 KiB
Plaintext
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
|