104 lines
3.8 KiB
Plaintext
104 lines
3.8 KiB
Plaintext
async def resellerOrgAdd(ns={}):
|
|
"""
|
|
`id` VARCHAR(32) comment '机构编码',
|
|
`orgname` VARCHAR(100) comment '机构名称',
|
|
`contactor` VARCHAR(32) comment '联系人',
|
|
`contactor_phone` VARCHAR(100) comment '联系人电话',
|
|
`province_id` VARCHAR(32) comment '所在省id',
|
|
`city_id` VARCHAR(32) comment '所在城市id',
|
|
`distinct_id` VARCHAR(32) comment '所在地区id',
|
|
`address` VARCHAR(400) comment '地址',
|
|
`main_business` VARCHAR(1000) comment '主营业务描述',
|
|
`orgcode` VARCHAR(100) comment '组织结构代码',
|
|
`license_img` VARCHAR(400) comment '营业执照',
|
|
`id_img` VARCHAR(400) comment '身份证',
|
|
`parentid` VARCHAR(32) comment '父机构id',
|
|
`org_type` VARCHAR(1) comment '机构类型',
|
|
`accountid` VARCHAR(32) comment '账号',
|
|
:param ns:
|
|
:return:
|
|
"""
|
|
ns_org = {
|
|
'id': uuid(),
|
|
'orgname': ns.get('orgname') or '',
|
|
'contactor': ns.get('contactor') or '',
|
|
'contactor_phone': ns.get('contactor_phone') or '',
|
|
'province_id': ns.get('province_id') or '',
|
|
'city_id': ns.get('city_id') or '',
|
|
'distinct_id': ns.get('distinct_id') or '',
|
|
'address': ns.get('address') or '',
|
|
'main_business': ns.get('main_business') or '',
|
|
'orgcode': ns.get('orgcode') or '',
|
|
'emailaddress': ns.get('emailaddress'),
|
|
'license_img': ns.get('license_img') or '',
|
|
'id_img': ns.get('id_img') or '',
|
|
'org_type': 1,
|
|
'accountid': ns.get('accountid') or '',
|
|
}
|
|
|
|
ns_reseller = {
|
|
'id': uuid(),
|
|
'orgid': ns_org['id'],
|
|
'settle_mode': ns.get('settle_mode') or '',
|
|
'settle_flow': ns.get('settle_flow') or '',
|
|
'settle_datep': ns.get('settle_datep') or '',
|
|
'salemanid': await get_user(),
|
|
}
|
|
if not ns:
|
|
return {
|
|
"status": False,
|
|
"message": "get no params..."
|
|
}
|
|
|
|
db = DBPools()
|
|
async with db.sqlorContext('kboss') as sor:
|
|
try:
|
|
org_code = ns.get('orgcode')
|
|
# bind the orgcode
|
|
if not org_code:
|
|
return {
|
|
'status': False,
|
|
'msg': 'reseller add failed, orgcode is empty'
|
|
}
|
|
# filter by orgcode
|
|
res = await sor.R('organization', {})
|
|
orgcodes = [orgc.get('orgcode') for orgc in res]
|
|
if org_code in orgcodes:
|
|
return {
|
|
'status': False,
|
|
'msg': 'reseller add failed, orgcode has already exist'
|
|
}
|
|
|
|
# get orgid from userid from users table
|
|
# if not await get_user():
|
|
# return {
|
|
# "status": False,
|
|
# "message": "reseller organization add failed, userid is empty"
|
|
# }
|
|
orgid_li = await sor.R('users', {'id': await get_user()})
|
|
orgid = orgid_li[0].get('orgid') if orgid_li else ''
|
|
if not orgid:
|
|
return {
|
|
"status": False,
|
|
"message": "reseller organization add failed, user's orgid can not find in users table"
|
|
}
|
|
# 父机构id
|
|
ns_org['parentid'] = orgid
|
|
await sor.C('organization', ns_org)
|
|
await sor.C('reseller', ns_reseller)
|
|
await openResellerAccounts(sor, orgid, ns_org['id'])
|
|
await openOwnerAccounts(sor, ns_org['id'])
|
|
return {
|
|
"status": True,
|
|
"msg": "reseller organization add success"
|
|
}
|
|
except Exception as e:
|
|
raise e
|
|
return {
|
|
"status": False,
|
|
"message": "reseller organization add failed"
|
|
}
|
|
|
|
|
|
ret = await resellerOrgAdd(params_kw)
|
|
return ret |