diff --git a/app/services/bonus.py b/app/services/bonus.py index ff58340..6b0d761 100644 --- a/app/services/bonus.py +++ b/app/services/bonus.py @@ -83,29 +83,27 @@ class BonusService: return {"bonuses": [BonusType(**bonus) for bonus in bonuses]} async def get_user_bonuses(self, username: str): - """Получить активные бонусы пользователя""" + """Получить бонусы пользователя (активные и неактивные)""" from app.db.database import users_collection user = await users_collection.find_one({"username": username}) if not user: raise HTTPException(status_code=404, detail="Пользователь не найден") - # Находим активные бонусы с учетом бесконечных (expires_at = null) или действующих - active_bonuses = await user_bonuses_collection.find({ + user_bonuses = await user_bonuses_collection.find({ "user_id": str(user["_id"]), - "is_active": True, }).to_list(50) result = [] - for bonus in active_bonuses: + for bonus in user_bonuses: bonus_type = await bonus_types_collection.find_one({"id": bonus["bonus_type_id"]}) if bonus_type: - # Рассчитываем итоговое значение эффекта с учетом уровня level = bonus.get("level", 1) effect_value = bonus_type["base_effect_value"] + (level - 1) * bonus_type["effect_increment"] bonus_data = { "id": bonus["id"], + "bonus_type_id": bonus["bonus_type_id"], "name": bonus_type["name"], "description": bonus_type["description"], "effect_type": bonus_type["effect_type"], @@ -115,12 +113,13 @@ class BonusService: "can_upgrade": bonus_type["max_level"] == 0 or level < bonus_type["max_level"], "upgrade_price": bonus_type["upgrade_price"], "image_url": bonus_type.get("image_url"), + "is_active": bonus.get("is_active", True), } - # Для временных бонусов добавляем срок if bonus.get("expires_at"): bonus_data["expires_at"] = bonus["expires_at"].isoformat() bonus_data["time_left"] = (bonus["expires_at"] - datetime.utcnow()).total_seconds() + bonus_data["is_permanent"] = False else: bonus_data["is_permanent"] = True