async def test_addusersxiaoshou(ns): """ 导入历史资料脚本 用户配置销售 """ db = DBPools() async with db.sqlorContext('kboss') as sor: """[{'name': '上海弼博信息技术有限公司', 'money': 333123.66, 'xiaoshou': '顾振华'},...]""" lists = ns.get('data') try: for i in lists: orgnaid = await sor.R('organization', {'orgname': i['name']}) if len(orgnaid) < 1: continue userid = '' users = await sor.R('users',{'username': i['xiaoshou']}) if len(users) >= 1: userid = users[0]['id'] else: userid = (await sor.R('users',{'username':'kyy_销售'}))[0]['id'] nss = {'customerid': orgnaid[0]['id'], 'salemanid': userid} sql = """ UPDATE customer SET salemanid = ${salemanid}$ WHERE customerid = ${customerid}$ """ await sor.sqlExe(sql, nss) return {'status': True, 'msg': '配置销售成功'} except Exception as error: raise error return {'status': False, 'msg': '配置销售失败'} ret = await test_addusersxiaoshou(params_kw) return ret