feat: add portal recharge page
This commit is contained in:
@@ -1,4 +1,9 @@
|
||||
from decimal import Decimal
|
||||
|
||||
from django import forms
|
||||
from django.conf import settings
|
||||
|
||||
from apps.billing.models import RechargeOrder
|
||||
|
||||
|
||||
class ApiKeyCreateForm(forms.Form):
|
||||
@@ -14,3 +19,37 @@ class ApiKeyCreateForm(forms.Form):
|
||||
}
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
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, "微信"),
|
||||
(RechargeOrder.PayMethod.ALIPAY, "支付宝"),
|
||||
),
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user