File size: 3,622 Bytes
ee37dcf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d5b0b2f
ee37dcf
 
 
 
 
 
d5b0b2f
 
 
 
 
 
 
 
ee37dcf
 
 
 
d5b0b2f
ee37dcf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
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")


    @field_validator('email')
    #确保password不为''
    def check_email(cls, v):
        if v == '':
            raise ValueError('email cannot be an empty string')
        return v

    @field_validator('password')
    # 确保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")


    @field_validator('email')
    # 确保password不为''
    def check_email(cls, v):
        if v == '':
            raise ValueError('email cannot be an empty string')
        return v

    @field_validator('password')
    # 确保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,保证只有用户本身可以请求这个接口防止滥用

    @field_validator('price')
    # 确保password不为''
    def check_price(cls, v):
        if v < 0:
            raise ValueError('price can not < 0')
        return v

    @field_validator('duration_seconds')
    # 确保password不为''
    def check_duration_seconds(cls, v):
        if v < 0:
            raise ValueError('duration_seconds can not < 0')
        return v

    @field_validator('email')
    # 确保password不为''
    def check_email(cls, v):
        if v == '':
            raise ValueError('email cannot be an empty string')
        return v