Spaces:
Running
Running
File size: 2,595 Bytes
bcd4967 b85ee96 bcd4967 12a3c7d 2167d09 bcd4967 2167d09 bcd4967 2167d09 bcd4967 2167d09 bcd4967 2167d09 bcd4967 2167d09 bcd4967 2167d09 bcd4967 2167d09 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
from fastapi import APIRouter, HTTPException, Request
from fastapi.responses import JSONResponse
from .hook import *
from .pydanticModel import *
from .dao import tableStore
router = APIRouter()
@router.get('/',response_model=AfdianResp)
@router.post('/',response_model=AfdianResp)
async def update_balance(afdianHookjson: AfdianHookJson):
resp = {'ec': 200}
# 检查 ec 是否为 200
if afdianHookjson.ec != 200:
return {'ec': "afdian hook错误,ec 不是 200"}
# 提取订单详情和可选参数
order_details = afdianHookjson.data.order
custom_order_id = order_details.custom_order_id
total_amount = order_details.total_amount
table_store = tableStore(ots_client=router.ots_client, table_name=router.table_name)
if all([custom_order_id is not None, total_amount is not None]):
# 说明是余额类型
try:
# 先给mysql的数据库添加 - 这个毕竟久 稳定 但是不应该影响其他数据库添加(万一不用了)--------------------
updateBalance(email=custom_order_id, amount=total_amount)
# 先给mysql的数据库添加 - 这个毕竟久 稳定 但是不应该影响其他数据库添加(万一不用了)--------------------
except Exception as e:
print("updateBalance v2b digitalocean mysql failed",e)
try:
#应该改成从原来的余额基础上加total_amount的值
table_store.getUserInfo(email=custom_order_id)
cur_balance = table_store.balance
balance_new = cur_balance+ total_amount
# 更新余额列
update_balance_result = table_store.updateColumnByPrimaryKey(
key=router.key,
key_value=custom_order_id,
update_column='balance',
update_column_value=balance_new
)
if update_balance_result:
return resp #全部成功运行则返回爱发电要求的ec =200
else:
return {'ec': "updateBalance tablestore 结果失败"}
except Exception as e:
print(e)
return {'ec': "尝试 updateBalance tablestore 失败"}
else:
#这个直接返回200吧,反正测试接口的时候需要 ,平时也不用到
# return {'ec': "afdian hook custom_order_id 或者 total_amount 为 None"}
return resp
# test
# @router.post('/uu')
# async def prinf_test_json(request: Request):
# json_data = await request.json()
# print("收到afdian请求:", json_data)
# return {'ec': 200}
|