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