63 lines
2.2 KiB
Plaintext
63 lines
2.2 KiB
Plaintext
async def invoice_callback(ns={}):
|
||
"""
|
||
发票开票回调
|
||
:param ns:
|
||
:return:
|
||
"""
|
||
response = {"status": False, "msg": ""}
|
||
apv_callback_data = {}
|
||
try:
|
||
apv_callback_data['apv_id'] = ns['apv_id']
|
||
_ = ns['status']
|
||
except Exception as e:
|
||
response["msg"] = "args is error,please check:{}".format(e)
|
||
return response
|
||
|
||
state_map = {
|
||
"start": 1,
|
||
"agree": 2,
|
||
"refuse": 3,
|
||
"terminate": 4
|
||
}
|
||
# 1:审核中,2:同意,3:拒绝,4:撤销',
|
||
# 0:未开票,1:开票中,2:已开票',3:开票失败'
|
||
db = DBPools()
|
||
async with db.sqlorContext('kboss') as sor:
|
||
# 更新状态记录
|
||
apv_callback_data["update_time"] = datetime.datetime.now()
|
||
apv_callback_data['apv_status'] = state_map.get(ns['status'], -1)
|
||
sql = "update invoice_apv set apv_status = ${apv_status}$,update_time = ${update_time}$ where apv_id = ${apv_id}$"
|
||
d = await sor.sqlExe(sql, apv_callback_data)
|
||
if not d:
|
||
response["msg"] = "发票开票回调更新失败,请检查参数"
|
||
response['data'] = {
|
||
"table": "invoice_apv",
|
||
"apv_id": f"{apv_callback_data['apv_id']}"
|
||
}
|
||
return response
|
||
else:
|
||
t = "invoice_apv save ok"
|
||
response['msg'] += t
|
||
if apv_callback_data['apv_status'] == 1:
|
||
response['status'] = True
|
||
return response
|
||
elif apv_callback_data['apv_status'] == 4:
|
||
apv_callback_data['apv_status'] = 3
|
||
sql = "update invoice_status set status = ${apv_status}$,update_time = ${update_time}$ where apv_id = ${apv_id}$"
|
||
d = await sor.sqlExe(sql, apv_callback_data)
|
||
if not d:
|
||
response['msg'] += "发票开票回调更新失败,请检查参数"
|
||
response['data'] = {
|
||
"table": "invoice_status",
|
||
"apv_id": f"{apv_callback_data['apv_id']}"
|
||
}
|
||
return response
|
||
response['status'] = True
|
||
response['msg'] = "success"
|
||
return response
|
||
return {"status": False, "msg": "sql error"}
|
||
|
||
|
||
ret = await invoice_callback(params_kw)
|
||
return ret
|