async def update_user_orders_interval(ns={}): """ 更新用户订单列表 """ domain_name = ns.get('domain_name') db = DBPools() async with db.sqlorContext('kboss') as sor: sql = """select bo.orderid, bs.user_id from baidu_orders as bo inner join baidu_users as bs on bo.accountid = bs.baidu_id inner join users as u on bs.user_id = u.id inner join organization as o on o.id = u.orgid where o.parentid = '%s' and bo.ordertype = 'RENEW' and bo.status = 'NEED_CONFIRM' and bo.del_flg = '0';""" % ns.get('orgid') order_list = await sor.sqlExe(sql, {}) try: for order in order_list: orderid = order['orderid'] user_id = order['user_id'] url = 'https://%s/baiducloud/get_baidu_orderlist.dspy' % domain_name params = { 'order_id': orderid, 'userid': user_id } method = 'POST' async with aiohttp_client.request( method=method, url=url, json=params) as res: order_result = await res.text() with open('update_baidu_renew.log', 'a+') as f: # 行首添加时间 f.write(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ' ' + orderid + ':' + order_result + '\n') url_update = 'https://%s/baiduc/update_baidu_order_list.dspy' % domain_name params_update = { 'orgid': ns.get('orgid') } method = 'POST' async with aiohttp_client.request( method=method, url=url_update, json=params_update) as res: data_text = await res.text() with open('update_baidu_renew.log', 'a+') as f: # 行首添加时间 f.write(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ' ' + data_text + '\n') return { 'status': True, 'msg': '更新成功' } except Exception as e: import traceback with open('update_baidu_renew.log', 'a+') as f: f.write(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ' ' + str(e) + traceback.format_exc() + '\n') traceback.print_exc() ret = await update_user_orders_interval(params_kw) return ret