File size: 5,116 Bytes
ee37dcf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ecc6c96
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ee37dcf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0fb576b
 
 
 
ee37dcf
 
 
 
 
 
 
0fb576b
 
 
7567f68
ecc6c96
 
0fb576b
 
 
 
 
 
7567f68
d5b0b2f
 
 
0fb576b
 
 
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
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 accountDelete(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: Optional[str] = None
    price: Optional[str] = None
    count: Optional[int] = None
    name: Optional[str] = None
    album_id: Optional[str] = None
    pic: Optional[str] = None
    stock: Optional[str] = None
    post_id: Optional[str] = None


class AfdianOrderDetail(BaseModel):
    out_trade_no: Optional[str] = Field(default=None, alias="out_trade_no")
    user_id: Optional[str] = Field(default=None, alias="user_id")
    plan_id: Optional[str] = Field(default=None, alias="plan_id")
    title: Optional[str] = Field(default=None, alias="title") #just afdian test have
    month: Optional[int] = Field(default=None, alias="month")
    total_amount: Optional[int] = Field(default=None, alias="total_amount")  # 这里精髓在于pydantic会在能转换下自动转int 但字符串 "6.60" 将无法转换为整数,因此会导致 422 错误 因此商品可以回调而兑换码422
    show_amount: Optional[str] = Field(default=None, alias="show_amount")
    status: Optional[int] = Field(default=None, alias="status")
    remark: Optional[str] = Field(default=None, alias="remark")
    redeem_id: Optional[str] = Field(default=None, alias="redeem_id")
    product_type: Optional[int] = Field(default=None, alias="product_type")
    discount: Optional[str] = Field(default=None, alias="discount")
    sku_detail: Optional[List[SKUDetail]] = Field(default=[], alias="sku_detail") #兼容afdian test 请求
    create_time: Optional[int] = Field(default=None, alias="create_time")
    plan_title: Optional[str] = Field(default=None, alias="plan_title")
    user_private_id: Optional[str] = Field(default=None, alias="user_private_id")
    address_person: Optional[str] = Field(default=None, alias="address_person")
    address_phone: Optional[str] = Field(default=None, alias="address_phone")
    address_address: Optional[str] = Field(default=None, alias="address_address")
    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