async def add_weixpay(ns): """ 微信支付 total:金额 userid:客户id """ db = DBPools() async with db.sqlorContext('kboss') as sor: try: if float(ns['total']) < 100: return {'status': False, 'msg': '充值金额不能小于1块钱'} user = await sor.R('users', {'id': ns['userid']}) recharge_logdict = {} recharge_logdict['id'] = uuid() recharge_logdict['customerid'] = user[0]['orgid'] recharge_logdict['action'] = 'RECHARGE_ALIPAY' recharge_logdict['recharge_path'] = '1' totals = ns['total'] / 100 recharge_logdict['recharge_amt'] = totals await sor.C('recharge_log', recharge_logdict) out_trade_no = recharge_logdict['id'] subject = 'kboss-微信充值' url = await pay_wx(out_trade_no,ns.get('total'),subject) imgurl = entire_url("/idfile?path=" + url) data = {'imgurl':imgurl,'recharge_logdict_id':recharge_logdict['id']} return {'status': True, 'msg': '支付创建成功','data':data} except Exception as error: import traceback with open('weixin_pay_log.txt', 'a+') as f: f.write(time.strftime('%Y-%m-%d %H:%M:%S') + ' ' + str(error) + traceback.format_exc() + '\n') raise error return {'status': False, 'msg': '充值提交失败'} ret = await add_weixpay(params_kw) return ret