async def addbz_order(ns): """ 生成订单 立即下单 userid : 用户id `goods`:'产品id', `spec_id`: '规格id', `quantity`:'数量', `transname` :'交易名称', `providerid` : '供应商id', `order_status` : '0:未支付,1:已交付;2:已关闭;3:已取消;4:后付费', """ db = DBPools() async with db.sqlorContext('kboss') as sor: if ns: try: user = await sor.R('users', {'id': await get_user()}) orgid = await sor.R('organization', {'id': user[0]['orgid']}) amountadll = 0 bz_ns = {} # bz_ns['id'] = UUID() bz_ns['id'] = uuid() bz_ns['order_status'] = '0' bz_ns['business_op'] = 'BUY' bz_ns['userid'] = await get_user() bz_ns['customerid'] = orgid[0]['id'] bz_ns['order_date'] = datetime.datetime.now().strftime("%Y-%m-%d") if ns.get('specdataid'): bz_ns['specdataid'] = ns['specdataid'] await sor.C('bz_order', bz_ns) # 添加账户表 nss = {} nss['id'] = uuid() # nss['id'] = UUID() nss['orderid'] = bz_ns['id'] nss['productid'] = ns.get('productid') nss['providerid'] = ns.get('providerid') nss['list_price'] = ns.get('list_price') nss['discount'] = ns.get('discount') nss['quantity'] = ns.get('quantity') nss['price'] = ns.get('amount') nss['spec_id'] = ns.get('spec_id') if int(ns.get('quantity')) > 1: nss['amount'] = float(ns['amount']) * int(ns['quantity']) amountadll += nss['amount'] else: nss['amount'] = ns['amount'] amountadll += float(nss['amount']) await sor.C('order_goods', nss) await sor.U('bz_order', {'id': bz_ns['id'], 'amount': amountadll}) return {'status': True, 'msg': '添加成功', 'bz_id': bz_ns['id']} except Exception as error: raise error return {'status': False, 'msg': '添加失败'} ret = await addbz_order(params_kw) return ret