Update WebApp
This commit is contained in:
12
database.py
12
database.py
@@ -180,6 +180,14 @@ class Database:
|
||||
now = datetime.now()
|
||||
await self.execute("UPDATE users SET last_traffic_reset = $1 WHERE user_id = $2", now, user_id)
|
||||
|
||||
async def get_referrals_count(self, user_id: int):
|
||||
return await self.fetchval("SELECT COUNT(*) FROM users WHERE invited_by = $1", user_id) or 0
|
||||
|
||||
async def get_user_payments_info(self, user_id: int):
|
||||
total_amount = await self.fetchval("SELECT SUM(amount) FROM payments WHERE user_id = $1", user_id) or 0
|
||||
total_count = await self.fetchval("SELECT COUNT(*) FROM payments WHERE user_id = $1", user_id) or 0
|
||||
return {"total_amount": total_amount, "total_count": total_count}
|
||||
|
||||
async def remove_subscription(self, user_id: int):
|
||||
await self.execute("UPDATE users SET subscription_until = NULL WHERE user_id = $1", user_id)
|
||||
|
||||
@@ -237,6 +245,9 @@ class Database:
|
||||
code, discount, uses, created_by, expires_at, is_unlimited, bonus_days, is_sticky
|
||||
)
|
||||
|
||||
async def delete_promo_code(self, code: str):
|
||||
await self.execute("DELETE FROM promo_codes WHERE code = $1", code)
|
||||
|
||||
async def set_user_discount(self, user_id: int, discount: int):
|
||||
await self.execute("UPDATE users SET personal_discount = $1 WHERE user_id = $2", discount, user_id)
|
||||
|
||||
@@ -281,6 +292,7 @@ class Database:
|
||||
|
||||
async def decrement_promo_usage(self, code: str):
|
||||
await self.execute("UPDATE promo_codes SET uses_left = uses_left - 1 WHERE code = $1", code)
|
||||
await self.execute("DELETE FROM promo_codes WHERE code = $1 AND uses_left <= 0", code)
|
||||
|
||||
async def add_payment(self, user_id: int, plan: str, amount: int, promo_code: str = None):
|
||||
await self.execute(
|
||||
|
||||
Reference in New Issue
Block a user