Spaces:
Running
Running
rogerxavier
commited on
Commit
•
fffc149
1
Parent(s):
e07a807
Update server/hook.py
Browse files- server/hook.py +29 -29
server/hook.py
CHANGED
@@ -1,29 +1,29 @@
|
|
1 |
-
#notify通知到后自动写入数据库的hook操作,只添加余额就行,连月都不用管
|
2 |
-
from .dao_pool import Database
|
3 |
-
def updateBalance(email,amount):
|
4 |
-
##通过传入用户email和回调中的金额修改balance
|
5 |
-
with Database.get_connection() as conn:
|
6 |
-
with conn.cursor() as cur:
|
7 |
-
print("链接数据库成功")
|
8 |
-
query = "SELECT balance FROM `v2_user` WHERE email = %(email)s"
|
9 |
-
params = {'email': email}
|
10 |
-
cur.execute(query, params)
|
11 |
-
result = cur.fetchone()
|
12 |
-
|
13 |
-
if result is not None:
|
14 |
-
# 如果email已经存在于数据库中,那么从数据库中获取balance,让balance加上新充值的金额就行
|
15 |
-
balance = result[0]
|
16 |
-
balance +=float(amount)*100
|
17 |
-
print(balance)
|
18 |
-
query = "UPDATE `v2_user` SET balance = %(balance)s WHERE email = %(email)s"
|
19 |
-
params = {'balance': str(balance), 'email': email}
|
20 |
-
cur.execute(query, params)
|
21 |
-
conn.commit()
|
22 |
-
else:
|
23 |
-
# 如果email不存在于数据库中,提示用户未注册(没必要,因为没法通知到app),所以不做处理
|
24 |
-
pass
|
25 |
-
print("
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
|
|
1 |
+
#notify通知到后自动写入数据库的hook操作,只添加余额就行,连月都不用管
|
2 |
+
from .dao_pool import Database
|
3 |
+
def updateBalance(email,amount):
|
4 |
+
##通过传入用户email和回调中的金额修改balance
|
5 |
+
with Database.get_connection() as conn:
|
6 |
+
with conn.cursor() as cur:
|
7 |
+
print("链接数据库成功")
|
8 |
+
query = "SELECT balance FROM `v2_user` WHERE email = %(email)s"
|
9 |
+
params = {'email': email}
|
10 |
+
cur.execute(query, params)
|
11 |
+
result = cur.fetchone()
|
12 |
+
|
13 |
+
if result is not None:
|
14 |
+
# 如果email已经存在于数据库中,那么从数据库中获取balance,让balance加上新充值的金额就行
|
15 |
+
balance = result[0]
|
16 |
+
balance +=float(amount)*100
|
17 |
+
print(balance)
|
18 |
+
query = "UPDATE `v2_user` SET balance = %(balance)s WHERE email = %(email)s"
|
19 |
+
params = {'balance': str(balance), 'email': email}
|
20 |
+
cur.execute(query, params)
|
21 |
+
conn.commit()
|
22 |
+
else:
|
23 |
+
# 如果email不存在于数据库中,提示用户未注册(没必要,因为没法通知到app),所以不做处理
|
24 |
+
pass
|
25 |
+
print("数据库操作完成,当前email: ",email)
|
26 |
+
|
27 |
+
|
28 |
+
|
29 |
+
|