rogerxavier commited on
Commit
2167d09
1 Parent(s): 0fb576b

Update server/notify.py

Browse files
Files changed (1) hide show
  1. server/notify.py +48 -48
server/notify.py CHANGED
@@ -7,59 +7,59 @@ from .dao import tableStore
7
 
8
  router = APIRouter()
9
  #afdian的回调是post huggingfaceb不知道抽什么风只能二级路由
10
- # @router.get('/uu',response_model=AfdianResp)
11
- # @router.post('/uu',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.post('/uu')
62
- async def prinf_test_json(request: Request):
63
- json_data = await request.json()
64
- print("收到afdian请求:", json_data)
65
- return {'ec': 200}
 
7
 
8
  router = APIRouter()
9
  #afdian的回调是post huggingfaceb不知道抽什么风只能二级路由
10
+ @router.get('/uu',response_model=AfdianResp)
11
+ @router.post('/uu',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.post('/uu')
62
+ # async def prinf_test_json(request: Request):
63
+ # json_data = await request.json()
64
+ # print("收到afdian请求:", json_data)
65
+ # return {'ec': 200}