Spaces:
Running
Running
from pydantic import BaseModel,field_validator,Field | |
from fastapi import Query | |
from typing import List, Optional, Any | |
# 定义fastapi请求参数模型 | |
class signUp(BaseModel): | |
email: str | |
password: str | |
# 可选参数 | |
expiredAt: int = Query(default=0, alias="expiredAt") | |
balance: int = Query(default=0, alias="balance") | |
ec: int = Query(default=200, alias="ec") | |
#确保password不为'' | |
def check_email(cls, v): | |
if v == '': | |
raise ValueError('email cannot be an empty string') | |
return v | |
# 确保password不为'' | |
def check_password(cls, v): | |
if v == '': | |
raise ValueError('password cannot be an empty string') | |
return v | |
class signIn(BaseModel): | |
email: str | |
password: str | |
# 可选参数 | |
expiredAt: int = Query(default=0, alias="expiredAt") | |
balance: int = Query(default=0, alias="balance") | |
ec: int = Query(default=200, alias="ec") | |
# 确保password不为'' | |
def check_email(cls, v): | |
if v == '': | |
raise ValueError('email cannot be an empty string') | |
return v | |
# 确保password不为'' | |
def check_password(cls, v): | |
if v == '': | |
raise ValueError('password cannot be an empty string') | |
return v | |
class SKUDetail(BaseModel): | |
sku_id: str | |
price: str | |
count: int | |
name: str | |
album_id: Optional[str] = None | |
pic: Optional[str] = None | |
stock: Optional[str] = None | |
post_id: Optional[str] = None | |
class AfdianOrderDetail(BaseModel): | |
out_trade_no: str | |
user_id: str | |
plan_id: str | |
month: int | |
total_amount: Optional[int] = Field(default=None, alias="total_amount") # 这里自动转int了 | |
show_amount: str | |
status: int | |
remark: str | |
redeem_id: str | |
product_type: int | |
discount: str | |
# sku_detail: List[SKUDetail] # 更新为 SKUDetail 列表 | |
sku_detail: Optional[List[SKUDetail]] = Field(default=[], alias="sku_detail") | |
# create_time: int | |
create_time: Optional[int] = Field(default=None, alias="create_time") | |
# plan_title: str | |
plan_title: Optional[str] = Field(default=None, alias="plan_title") | |
# user_private_id: str | |
user_private_id: Optional[str] = Field(default=None, alias="user_private_id") | |
address_person: str | |
address_phone: str | |
address_address: str | |
custom_order_id: Optional[str] = Field(default=None, alias="custom_order_id") | |
class AfdianOrderData(BaseModel): | |
type: str | |
order: AfdianOrderDetail | |
class AfdianHookJson(BaseModel): | |
ec: int | |
em: str | |
data: AfdianOrderData | |
class AfdianResp(BaseModel): | |
ec: Any | |
#根据plan中的价格和时间相应减少balance和增加expiredAt | |
class userPlan(BaseModel): | |
price: int | |
duration_seconds: int | |
email: str #订阅plan的用户 | |
password: str #请求purchase接口用户的password,保证只有用户本身可以请求这个接口防止滥用 | |
# 确保password不为'' | |
def check_price(cls, v): | |
if v < 0: | |
raise ValueError('price can not < 0') | |
return v | |
# 确保password不为'' | |
def check_duration_seconds(cls, v): | |
if v < 0: | |
raise ValueError('duration_seconds can not < 0') | |
return v | |
# 确保password不为'' | |
def check_email(cls, v): | |
if v == '': | |
raise ValueError('email cannot be an empty string') | |
return v | |