feat: grant signup bonus points

This commit is contained in:
QiuSW
2026-07-08 15:13:23 +08:00
parent 02aa12e8b9
commit ac8bec7b9c
29 changed files with 399 additions and 61 deletions
+30
View File
@@ -248,6 +248,7 @@ class PointsLedger(models.Model):
CONSUME = "consume", "消费"
ADJUST = "adjust", "调整"
REFUND = "refund", "退款"
SIGNUP_BONUS = "signup_bonus", "注册赠点"
user = models.ForeignKey(
settings.AUTH_USER_MODEL,
@@ -307,3 +308,32 @@ class PointsLedger(models.Model):
super().clean()
if self.change_type == self.ChangeType.ADJUST and not (self.reason or "").strip():
raise ValidationError({"reason": "Adjust ledger entries require a reason."})
class SignupBonusGrant(models.Model):
user = models.OneToOneField(
settings.AUTH_USER_MODEL,
verbose_name="用户",
on_delete=models.PROTECT,
related_name="signup_bonus_grant",
)
points_granted = models.BigIntegerField("赠送点数", default=100)
created_at = models.DateTimeField("创建时间", auto_now_add=True)
class Meta:
db_table = "signup_bonus_grant"
verbose_name = "注册赠点记录"
verbose_name_plural = "注册赠点记录"
ordering = ("-created_at", "-id")
constraints = [
models.CheckConstraint(
condition=Q(points_granted__gt=0),
name="signup_bonus_grant_points_positive",
),
]
indexes = [
models.Index(fields=("user", "created_at")),
]
def __str__(self) -> str:
return f"{self.user} signup bonus: {self.points_granted}"