main #34
@ -198,6 +198,88 @@ async def baidu_order_cancel(ns={}):
|
|||||||
'msg': 'order cancel success'
|
'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={}):
|
async def get_baidu_orderlist(ns={}):
|
||||||
"""
|
"""
|
||||||
百度支付
|
百度支付
|
||||||
@ -207,7 +289,7 @@ async def get_baidu_orderlist(ns={}):
|
|||||||
"""
|
"""
|
||||||
# 增加延迟
|
# 增加延迟
|
||||||
import asyncio
|
import asyncio
|
||||||
await asyncio.sleep(2)
|
await asyncio.sleep(1)
|
||||||
db = DBPools()
|
db = DBPools()
|
||||||
async with db.sqlorContext('kboss') as sor:
|
async with db.sqlorContext('kboss') as sor:
|
||||||
baidu_users = await sor.R('baidu_users', {'user_id': ns.get('userid'),'del_flg':'0'})
|
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':
|
if orders[0]['type'] == 'REFUND' and orders[0]['status'] != 'CREATED':
|
||||||
return {
|
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')})
|
||||||
'status': False,
|
return res_refund
|
||||||
'msg': 'delay_order'
|
|
||||||
}
|
|
||||||
|
|
||||||
# 避免重复退订
|
# 避免重复退订
|
||||||
if orders[0]['type'] == 'REFUND' and orders[0]['status'] == 'CREATED':
|
if orders[0]['type'] == 'REFUND' and orders[0]['status'] == 'CREATED':
|
||||||
|
|||||||
@ -4,12 +4,20 @@ async def get_unreadmsg(ns={}):
|
|||||||
:param ns:
|
:param ns:
|
||||||
:return:
|
: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()
|
db = DBPools()
|
||||||
async with db.sqlorContext('kboss') as sor:
|
async with db.sqlorContext('kboss') as sor:
|
||||||
# if 'userid' not in ns or not ns['userid']:
|
# if 'userid' not in ns or not ns['userid']:
|
||||||
# return {'status': False, 'msg': '收件人 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:
|
if not mas:
|
||||||
return {'status': True, 'count': 0}
|
return {'status': True, 'count': 0}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user