Spaces:
Runtime error
Runtime error
远兮
commited on
Commit
·
6969aea
1
Parent(s):
0f79443
修改套餐过期时间
Browse files- chatgpt-next-web/pay_package.py +10 -9
- chatgpt-next-web/service.py +18 -4
chatgpt-next-web/pay_package.py
CHANGED
@@ -2,19 +2,20 @@
|
|
2 |
packages = [
|
3 |
{
|
4 |
'id': '1',
|
5 |
-
'title': '
|
6 |
-
'basic_chat_limit':
|
7 |
-
'advanced_chat_limit':
|
8 |
-
'price':
|
9 |
-
'expiration':
|
10 |
},
|
11 |
{
|
12 |
'id': '2',
|
13 |
-
'title': '
|
14 |
'basic_chat_limit': -1, # -1 表示无限次
|
15 |
-
'advanced_chat_limit':
|
16 |
-
'price':
|
17 |
-
'expiration':
|
|
|
18 |
}
|
19 |
]
|
20 |
|
|
|
2 |
packages = [
|
3 |
{
|
4 |
'id': '1',
|
5 |
+
'title': '尝鲜套餐',
|
6 |
+
'basic_chat_limit': 50,
|
7 |
+
'advanced_chat_limit': 0,
|
8 |
+
'price': 100, # 以分计算
|
9 |
+
'expiration': 30 * 24 * 60 * 60 # 过期时间为30天(以秒为单位)
|
10 |
},
|
11 |
{
|
12 |
'id': '2',
|
13 |
+
'title': '无限制基础访问套餐',
|
14 |
'basic_chat_limit': -1, # -1 表示无限次
|
15 |
+
'advanced_chat_limit': 0,
|
16 |
+
'price': 60000, # 以分计算
|
17 |
+
'expiration': 30 * 24 * 60 * 60 # 过期时间为30天(以秒为单位)
|
18 |
+
|
19 |
}
|
20 |
]
|
21 |
|
chatgpt-next-web/service.py
CHANGED
@@ -97,7 +97,7 @@ def register():
|
|
97 |
|
98 |
# 清除验证码
|
99 |
redis.delete(email)
|
100 |
-
|
101 |
# 注册免费赠送12次
|
102 |
pick_up_free_chat_count(user_id, 12)
|
103 |
|
@@ -345,13 +345,27 @@ def get_user_profile():
|
|
345 |
basic_chat_limit = int(package.get(b'basic_chat_limit', 0))
|
346 |
advanced_chat_limit = int(package.get(b'advanced_chat_limit', 0))
|
347 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
348 |
return jsonify({
|
349 |
'code': 0,
|
350 |
'message': 'Success',
|
351 |
'data': {
|
352 |
'free_count': free_count,
|
353 |
'basic_chat_limit': basic_chat_limit,
|
354 |
-
'advanced_chat_limit': advanced_chat_limit
|
|
|
355 |
}
|
356 |
})
|
357 |
|
@@ -660,8 +674,8 @@ def store_user_package(user_id, package):
|
|
660 |
redis.hset(user_package_key, 'basic_chat_limit', basic_chat_limit)
|
661 |
redis.hset(user_package_key, 'advanced_chat_limit', advanced_chat_limit)
|
662 |
# 设置套餐过期时间
|
663 |
-
|
664 |
-
|
665 |
|
666 |
|
667 |
# 获取用户套餐信息
|
|
|
97 |
|
98 |
# 清除验证码
|
99 |
redis.delete(email)
|
100 |
+
|
101 |
# 注册免费赠送12次
|
102 |
pick_up_free_chat_count(user_id, 12)
|
103 |
|
|
|
345 |
basic_chat_limit = int(package.get(b'basic_chat_limit', 0))
|
346 |
advanced_chat_limit = int(package.get(b'advanced_chat_limit', 0))
|
347 |
|
348 |
+
user_package_key = f'user:{user_id}:package'
|
349 |
+
expiration_seconds = redis.ttl(user_package_key)
|
350 |
+
print("expiration_seconds = ", expiration_seconds, "is_package_expired = ", is_package_expired(user_id))
|
351 |
+
formatted_expiration = ""
|
352 |
+
if expiration_seconds > 0:
|
353 |
+
expiration_datetime = (
|
354 |
+
datetime.datetime.now()
|
355 |
+
+ datetime.timedelta(seconds=expiration_seconds)
|
356 |
+
)
|
357 |
+
formatted_expiration = expiration_datetime.strftime('%Y-%m-%d')
|
358 |
+
else:
|
359 |
+
formatted_expiration = '已过期'
|
360 |
+
|
361 |
return jsonify({
|
362 |
'code': 0,
|
363 |
'message': 'Success',
|
364 |
'data': {
|
365 |
'free_count': free_count,
|
366 |
'basic_chat_limit': basic_chat_limit,
|
367 |
+
'advanced_chat_limit': advanced_chat_limit,
|
368 |
+
'expiration': formatted_expiration
|
369 |
}
|
370 |
})
|
371 |
|
|
|
674 |
redis.hset(user_package_key, 'basic_chat_limit', basic_chat_limit)
|
675 |
redis.hset(user_package_key, 'advanced_chat_limit', advanced_chat_limit)
|
676 |
# 设置套餐过期时间
|
677 |
+
expiration = int(time.time()) + package['expiration']
|
678 |
+
redis.expireat(user_package_key, expiration)
|
679 |
|
680 |
|
681 |
# 获取用户套餐信息
|