update baidu order list
This commit is contained in:
parent
9e918d37e0
commit
9b4ea937f2
@ -197,6 +197,88 @@ async def baidu_order_cancel(ns={}):
|
||||
'status': True,
|
||||
'msg': 'order cancel success'
|
||||
}
|
||||
|
||||
async def baidu_confirm_refund_order(ns={}):
|
||||
db = DBPools()
|
||||
async with db.sqlorContext('kboss') as sor:
|
||||
refund_status_li = await sor.R('baidu_orders', {'orderid': ns.get('order_id')})
|
||||
refundstatus = refund_status_li[0]['refundstatus']
|
||||
refund_id = refund_status_li[0]['id']
|
||||
|
||||
if not refundstatus:
|
||||
# data_ = {}
|
||||
# 调用支付订单接口
|
||||
paydata = {'queryAccountId': ns.get('baidu_id'), 'orderId':ns.get('order_id')}
|
||||
ns_format = '&'.join(['%s=%s' % (k, v) for k, v in ns.items()])
|
||||
url = 'https://billing.baidubce.com/v1/order/pay?%s' % ns_format
|
||||
method = 'POST'
|
||||
header = {
|
||||
"Host": "billing.baidubce.com"
|
||||
}
|
||||
header = await get_auth_header(method=method, url=url, header=header)
|
||||
async with aiohttp_client.request(
|
||||
method=method,
|
||||
url=url,
|
||||
headers=header,
|
||||
json=paydata) as res:
|
||||
data_ = await res.json()
|
||||
if data_ == {'success': True}:
|
||||
# if True:
|
||||
ns_record = {
|
||||
'orderid': ns.get('order_id'),
|
||||
'ordertype': 'REFUND',
|
||||
'userid': ns.get('userid'),
|
||||
'reason': '远程退款成功'
|
||||
}
|
||||
await user_action_record(ns_record)
|
||||
db = DBPools()
|
||||
async with db.sqlorContext('kboss') as sor:
|
||||
await sor.U('baidu_orders', {'id': refund_id, 'refundstatus': '1'})
|
||||
|
||||
# 增加延迟
|
||||
import asyncio
|
||||
await asyncio.sleep(1)
|
||||
else:
|
||||
ns_record = {
|
||||
'orderid': ns.get('order_id'),
|
||||
'ordertype': 'REFUND',
|
||||
'userid': ns.get('userid'),
|
||||
'reason': '产品退费失败, %s' % str(data_)[:400]
|
||||
}
|
||||
await user_action_record(ns_record)
|
||||
return {
|
||||
'status': False,
|
||||
'msg': '产品退款出错!%s' % str(data_)[:400]
|
||||
}
|
||||
|
||||
if refundstatus == '2':
|
||||
return {
|
||||
'status': True,
|
||||
'msg': '已退款成功'
|
||||
}
|
||||
|
||||
# 获取created状态后再去退款
|
||||
local_refund_status = await get_baidu_orderlist({'order_id': ns.get('order_id'), 'userid': ns.get('user_id')})
|
||||
print('local_refund_status', local_refund_status)
|
||||
if local_refund_status.get('status'):
|
||||
db = DBPools()
|
||||
async with db.sqlorContext('kboss') as sor:
|
||||
await sor.U('baidu_orders', {'id': refund_id, 'refundstatus': '2'})
|
||||
|
||||
return {
|
||||
'status': True,
|
||||
'msg': '百度云给平台退款成功,平台给客户退款成功'
|
||||
}
|
||||
else:
|
||||
if local_refund_status.get('msg') == 'delay_order':
|
||||
return {
|
||||
'status': False,
|
||||
'msg': '百度远程订单还未生成, 请十秒后重试'
|
||||
}
|
||||
return {
|
||||
'status': False,
|
||||
'msg': '百度云退款成功,本机构给客户退款出错!'
|
||||
}
|
||||
|
||||
async def get_baidu_orderlist(ns={}):
|
||||
"""
|
||||
@ -207,7 +289,7 @@ async def get_baidu_orderlist(ns={}):
|
||||
"""
|
||||
# 增加延迟
|
||||
import asyncio
|
||||
await asyncio.sleep(2)
|
||||
await asyncio.sleep(1)
|
||||
db = DBPools()
|
||||
async with db.sqlorContext('kboss') as sor:
|
||||
baidu_users = await sor.R('baidu_users', {'user_id': ns.get('userid'),'del_flg':'0'})
|
||||
@ -235,10 +317,8 @@ async def get_baidu_orderlist(ns={}):
|
||||
|
||||
# 可能获取得到的是延迟订单
|
||||
if orders[0]['type'] == 'REFUND' and orders[0]['status'] != 'CREATED':
|
||||
return {
|
||||
'status': False,
|
||||
'msg': 'delay_order'
|
||||
}
|
||||
res_refund = await baidu_confirm_refund_order({'order_id': ns.get('order_id'), 'baidu_id': baidu_users[0]['baidu_id'], 'user_id': ns.get('userid')})
|
||||
return res_refund
|
||||
|
||||
# 避免重复退订
|
||||
if orders[0]['type'] == 'REFUND' and orders[0]['status'] == 'CREATED':
|
||||
|
||||
@ -4,12 +4,20 @@ async def get_unreadmsg(ns={}):
|
||||
:param ns:
|
||||
:return:
|
||||
"""
|
||||
# 处理userid
|
||||
if ns.get('userid'):
|
||||
ns['userid'] = ns.get('userid')
|
||||
else:
|
||||
ns['userid'] = await get_user()
|
||||
if not ns.get('userid'):
|
||||
server_error(401)
|
||||
|
||||
db = DBPools()
|
||||
async with db.sqlorContext('kboss') as sor:
|
||||
# if 'userid' not in ns or not ns['userid']:
|
||||
# return {'status': False, 'msg': '收件人 userid 未提供'}
|
||||
|
||||
mas = await sor.R('message', {'receiverid': await get_user(), 'del_flg': 0, 'msgstatus': 0})
|
||||
mas = await sor.R('message', {'receiverid': ns['userid'], 'del_flg': 0, 'msgstatus': 0})
|
||||
|
||||
if not mas:
|
||||
return {'status': True, 'count': 0}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user