rogerxavier commited on
Commit
bcd4967
1 Parent(s): 7f4c5ee

Update server/notify.py

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