Feature: Referral-Rabattstufen — 10→20%, 20→30%, 50→50% lebenslang
- auth.py: _referral_tier() + _referral_next() Tier-Logik, GET /api/auth/referral gibt discount_pct + next_tier zurück - settings.js: Referral-UI komplett neu — Tier-Kacheln, Fortschrittsbalken, Zähler, Rabatt-Hinweis - SW by-v517, APP_VER 494
This commit is contained in:
parent
ab41af470d
commit
e7e4adaa70
4 changed files with 88 additions and 29 deletions
|
|
@ -149,6 +149,24 @@ async def logout(response: Response):
|
|||
return {"ok": True}
|
||||
|
||||
|
||||
_REFERRAL_TIERS = [
|
||||
(50, 50),
|
||||
(20, 30),
|
||||
(10, 20),
|
||||
]
|
||||
|
||||
def _referral_tier(count: int):
|
||||
for threshold, discount in _REFERRAL_TIERS:
|
||||
if count >= threshold:
|
||||
return discount
|
||||
return 0
|
||||
|
||||
def _referral_next(count: int):
|
||||
for threshold, discount in reversed(_REFERRAL_TIERS):
|
||||
if count < threshold:
|
||||
return {"count": threshold, "discount": discount}
|
||||
return None # Maximalstufe erreicht
|
||||
|
||||
@router.get("/referral")
|
||||
async def get_referral_info(user=Depends(get_current_user)):
|
||||
with db() as conn:
|
||||
|
|
@ -162,11 +180,14 @@ async def get_referral_info(user=Depends(get_current_user)):
|
|||
if not code:
|
||||
code = _gen_referral_code()
|
||||
conn.execute("UPDATE users SET referral_code=? WHERE id=?", (code, user['id']))
|
||||
base = os.getenv("APP_URL", "https://banyaro.app")
|
||||
count = row["count"] if row else 0
|
||||
base = os.getenv("APP_URL", "https://banyaro.app")
|
||||
return {
|
||||
"code": code,
|
||||
"count": row["count"] if row else 0,
|
||||
"link": f"{base}/?ref={code}",
|
||||
"code": code,
|
||||
"count": count,
|
||||
"link": f"{base}/?ref={code}",
|
||||
"discount_pct": _referral_tier(count),
|
||||
"next_tier": _referral_next(count),
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue