Update
This commit is contained in:
parent
362b19e5b7
commit
16194547a9
@ -108,7 +108,7 @@ class UserSubscriptionManager:
|
||||
subscription = self.session.query(UserSubscription).filter(
|
||||
UserSubscription.user_id == user_id,
|
||||
UserSubscription.expire_time > datetime.now()
|
||||
).order_by(UserSubscription.expire_time.desc()).first()
|
||||
).order_by(UserSubscription.create_time.desc()).first()
|
||||
|
||||
if subscription:
|
||||
# 转换为字典
|
||||
|
||||
@ -210,15 +210,14 @@ async def chat(request: ChatRequest,
|
||||
current_user: dict = Depends(get_current_user),
|
||||
session: Session = Depends(get_db)):
|
||||
|
||||
# 检查用户积分
|
||||
if current_user["points"] < 1:
|
||||
raise HTTPException(status_code=400, detail="您的免费次数不足,你可以订阅会员。")
|
||||
|
||||
# 检查用户是否订阅
|
||||
user_subscription_manager = UserSubscriptionManager(session)
|
||||
user_subscription = user_subscription_manager.get_subscription_by_user_id(current_user["id"])
|
||||
if not user_subscription or user_subscription["expire_time"] < datetime.now():
|
||||
raise HTTPException(status_code=400, detail="您的会员已过期,请续订会员。")
|
||||
is_member = user_subscription and user_subscription["expire_time"] > datetime.now()
|
||||
user_points = current_user["points"]
|
||||
|
||||
if not is_member and user_points < 1:
|
||||
raise HTTPException(status_code=999, detail="你的免费次数不足,你可以订阅会员。")
|
||||
|
||||
payload = {
|
||||
"inputs" : {},
|
||||
|
||||
@ -12,7 +12,6 @@ from cryptoai.utils.db_manager import get_db
|
||||
from cryptoai.models.user_subscription import UserSubscriptionManager
|
||||
from datetime import timedelta
|
||||
import logging
|
||||
from fastapi import Request
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
@ -22,13 +21,18 @@ logger.setLevel(logging.DEBUG)
|
||||
class CreateOrderRequest(BaseModel):
|
||||
subscribe_type: int
|
||||
|
||||
pricing = {
|
||||
"price_month": 29,
|
||||
"price_year": 269
|
||||
}
|
||||
|
||||
@router.get('/pricing')
|
||||
async def pricing():
|
||||
async def pricing_info():
|
||||
return {
|
||||
"code": 200,
|
||||
"data": {
|
||||
"price_month": 29,
|
||||
"price_year": 219
|
||||
"price_month": pricing["price_month"],
|
||||
"price_year": pricing["price_year"]
|
||||
}
|
||||
}
|
||||
|
||||
@ -50,10 +54,10 @@ async def create_order(request: CreateOrderRequest,
|
||||
|
||||
## 1=包月,2=包年
|
||||
if request.subscribe_type == 1:
|
||||
fiat_amount = "29"
|
||||
fiat_amount = str(pricing["price_month"])
|
||||
product_name = "会员订阅:1个月"
|
||||
elif request.subscribe_type == 2:
|
||||
fiat_amount = "219"
|
||||
fiat_amount = str(pricing["price_year"])
|
||||
product_name = "会员订阅:1年"
|
||||
else:
|
||||
return {
|
||||
|
||||
@ -300,7 +300,7 @@ async def login(loginData: UserLogin, session: Session = Depends(get_db)) -> Tok
|
||||
user_subscription = user_subscription_manager.get_subscription_by_user_id(user["id"])
|
||||
|
||||
is_subscribed = False
|
||||
expire_time = None
|
||||
expire_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
||||
|
||||
if user_subscription:
|
||||
member_name = "VIP"
|
||||
|
||||
@ -4,10 +4,13 @@ from typing import Dict, Any, Optional
|
||||
|
||||
class Upay:
|
||||
def __init__(self):
|
||||
self.app_id="4NgfCm1e"
|
||||
self.app_secret="4gDTZDXfpKQBboT6"
|
||||
self.base_url = "https://api-test.upay.ink"
|
||||
# self.base_url = "https://api.upay.ink"
|
||||
# self.app_id="4NgfCm1e"
|
||||
# self.app_secret="4gDTZDXfpKQBboT6"
|
||||
# self.base_url = "https://api-test.upay.ink"
|
||||
|
||||
self.app_id="E7c4dss9"
|
||||
self.app_secret="Hwc56INsabRau2yn"
|
||||
self.base_url = "https://api.upay.ink"
|
||||
|
||||
def _generate_signature(self, params: Dict[str, Any]) -> str:
|
||||
"""
|
||||
|
||||
@ -29,7 +29,7 @@ services:
|
||||
cryptoai-api:
|
||||
build: .
|
||||
container_name: cryptoai-api
|
||||
image: cryptoai-api:0.2.3
|
||||
image: cryptoai-api:0.2.4
|
||||
restart: always
|
||||
ports:
|
||||
- "8000:8000"
|
||||
|
||||
Loading…
Reference in New Issue
Block a user