55 lines
1.5 KiB
Python
55 lines
1.5 KiB
Python
from decimal import Decimal
|
|
|
|
from django import forms
|
|
from django.conf import settings
|
|
|
|
from apps.billing.models import RechargeOrder
|
|
|
|
|
|
class ApiKeyCreateForm(forms.Form):
|
|
name = forms.CharField(
|
|
label="名称",
|
|
max_length=80,
|
|
required=False,
|
|
widget=forms.TextInput(
|
|
attrs={
|
|
"autocomplete": "off",
|
|
"class": "form-control",
|
|
"placeholder": "例如:桌面端",
|
|
}
|
|
),
|
|
)
|
|
|
|
|
|
class RechargeCreateForm(forms.Form):
|
|
amount = forms.DecimalField(
|
|
label="充值金额",
|
|
max_digits=12,
|
|
decimal_places=2,
|
|
min_value=Decimal("0.01"),
|
|
widget=forms.NumberInput(
|
|
attrs={
|
|
"class": "form-control",
|
|
"inputmode": "decimal",
|
|
"min": "0.01",
|
|
"step": "0.01",
|
|
"placeholder": "例如:100.00",
|
|
}
|
|
),
|
|
)
|
|
pay_method = forms.ChoiceField(
|
|
label="支付方式",
|
|
choices=(
|
|
(RechargeOrder.PayMethod.WEIXIN, "微信"),
|
|
),
|
|
initial=RechargeOrder.PayMethod.WEIXIN,
|
|
widget=forms.RadioSelect(attrs={"class": "form-check-input"}),
|
|
)
|
|
|
|
def clean_amount(self):
|
|
amount = self.cleaned_data["amount"]
|
|
max_amount = Decimal(str(settings.RECHARGE_MAX_AMOUNT_CNY))
|
|
if amount > max_amount:
|
|
raise forms.ValidationError(f"单笔充值金额不能超过 {max_amount:.2f} CNY")
|
|
return amount
|