kboss/b/invoice/invoice_callback.dspy
2025-07-16 14:27:17 +08:00

63 lines
2.2 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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