93 lines
5.0 KiB
Plaintext
93 lines
5.0 KiB
Plaintext
async def affirmbz_order(ns):
|
|
"""确认支付"""
|
|
db = DBPools()
|
|
async with db.sqlorContext('kboss') as sor:
|
|
if ns:
|
|
# 查询产品说明是否是product_sync
|
|
order_productid_providerid = await sor.R('order_goods', {'orderid': ns['orderid']})
|
|
order_productid = order_productid_providerid[0]['productid']
|
|
order_providerid = order_productid_providerid[0]['providerid']
|
|
description = (await sor.R('product', {'id': order_productid}))[0]['description']
|
|
if description == 'product_sync':
|
|
# 根据orderid在order_goods里查询对应账单
|
|
# order_providerid = (await sor.R('order_goods', {'orderid': ns['orderid']}))[0]['providerid']
|
|
# 查询阿里云得id
|
|
ali_id_li = await sor.R('organization', {'orgname': '阿里云'})
|
|
if ali_id_li:
|
|
ali_id = ali_id_li[0]['id']
|
|
else:
|
|
ali_id = None
|
|
# 查询开元云得id
|
|
k_id_li = await sor.R('organization', {'orgname': '开元云'})
|
|
if k_id_li:
|
|
k_id = k_id_li[0]['id']
|
|
else:
|
|
k_id = None
|
|
|
|
target_id = None
|
|
if order_providerid == ali_id:
|
|
target_id = ali_id
|
|
if order_providerid == k_id:
|
|
target_id = k_id
|
|
if target_id:
|
|
# 查询业主机构针对所有客户的普通协议
|
|
protocolid = (await sor.R('saleprotocol', {'offer_orgid': 'mIWUHBeeDM8mwAFPIQ8pS', 'bid_orgid': '*', 'salemode': '2', 'del_flg': '0'}))[0]['id']
|
|
# 在产品价格表中更新价格配置
|
|
id_sql = """select id, price from product_salemode where protocolid = '%s' and providerid = '%s' and productid = '%s' order by price desc limit 1;""" % (protocolid, target_id, order_productid)
|
|
id_find = (await sor.sqlExe(id_sql, {}))[0]['id']
|
|
# 查询价格
|
|
current_price = (await sor.R('bz_order', {'id': ns['orderid']}))[0]['amount']
|
|
await sor.U('product_salemode', {'id': id_find, 'price': current_price})
|
|
|
|
orgid = await sor.R('bz_order', {'id': ns['orderid']})
|
|
date = await get_business_date(sor=None)
|
|
await sor.U('bz_order',{'id':ns['orderid'],'order_date': date})
|
|
count = await getCustomerBalance(sor, orgid[0]['customerid'])
|
|
if count == None:
|
|
count = 0
|
|
if count - float(orgid[0]['amount']) < 0:
|
|
pricedifference = count - round(orgid[0]['amount'],2)
|
|
return {'status': False, 'msg': '账户余额不足','pricedifference': round(pricedifference,2)}
|
|
await order2bill(ns['orderid'], sor)
|
|
bills = await sor.R('bill', {'orderid': ns['orderid'], 'del_flg': '0'})
|
|
try:
|
|
# 需要加事务
|
|
for i in bills:
|
|
ba = BillAccounting(i)
|
|
r = await ba.accounting(sor)
|
|
dates = datetime.datetime.now()
|
|
await sor.U('bz_order', {'id': ns['orderid'], 'order_status': '1','create_at':dates})
|
|
await sor.U('bill', {'id': ns['orderid'], 'bill_state': '1'})
|
|
order_goods = await sor.R('order_goods', {'orderid': ns['orderid']})
|
|
for j in order_goods:
|
|
product = await sor.R('product', {'id': j['productid']})
|
|
nss = {}
|
|
nss['id'] = uuid()
|
|
# nss['id'] = UUID()
|
|
nss['providerrid'] = product[0]['providerid']
|
|
nss['productname'] = product[0]['name']
|
|
nss['productdesc'] = product[0]['description']
|
|
nss['customerid'] = orgid[0]['customerid']
|
|
nss['productid'] = product[0]['id']
|
|
nss['specdataid'] = j['spec_id']
|
|
nss['orderid'] = orgid[0]['id']
|
|
nss['start_date'] = datetime.datetime.now().strftime("%Y-%m-%d")
|
|
if ns.get('product_url'):
|
|
nss['product_url'] = ns.get('product_url')
|
|
await sor.C('customer_goods', nss)
|
|
v = {}
|
|
v['orderid'] = orgid[0]['id']
|
|
v['customerid'] = orgid[0]['customerid']
|
|
v['providerid'] = product[0]['providerid']
|
|
v['productid'] = product[0]['id']
|
|
v['quantity'] = j['quantity']
|
|
await path_call('../pub/hpc_save_bill.dspy', v)
|
|
return {'status': True, 'msg': '支付成功'}
|
|
except Exception as error:
|
|
raise error
|
|
else:
|
|
return {'status': False, 'msg': '参数错误'}
|
|
return {'status': False, 'msg': '支付失败'}
|
|
|
|
ret = await affirmbz_order(params_kw)
|
|
return ret |