Complete implementation of loyalty module Phase 2 features: Database & Models: - Add company_id to LoyaltyProgram for chain-wide loyalty - Add company_id to LoyaltyCard for multi-location support - Add CompanyLoyaltySettings model for admin-controlled settings - Add points expiration, welcome bonus, and minimum redemption fields - Add POINTS_EXPIRED, WELCOME_BONUS transaction types Services: - Update program_service for company-based queries - Update card_service with enrollment and welcome bonus - Update points_service with void_points for returns - Update stamp_service for company context - Update pin_service for company-wide operations API Endpoints: - Admin: Program listing with stats, company detail views - Vendor: Terminal operations, card management, settings - Storefront: Customer card/transactions, self-enrollment UI Templates: - Admin: Programs dashboard, company detail, settings - Vendor: Terminal, cards list, card detail, settings, stats, enrollment - Storefront: Dashboard, history, enrollment, success pages Background Tasks: - Point expiration task (daily, based on inactivity) - Wallet sync task (hourly) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
670 lines
22 KiB
Python
670 lines
22 KiB
Python
# app/modules/loyalty/services/program_service.py
|
|
"""
|
|
Loyalty program service.
|
|
|
|
Company-based program management:
|
|
- Programs belong to companies, not individual vendors
|
|
- All vendors under a company share the same loyalty program
|
|
- One program per company
|
|
|
|
Handles CRUD operations for loyalty programs including:
|
|
- Program creation and configuration
|
|
- Program updates
|
|
- Program activation/deactivation
|
|
- Statistics retrieval
|
|
"""
|
|
|
|
import logging
|
|
from datetime import UTC, datetime
|
|
|
|
from sqlalchemy.orm import Session
|
|
|
|
from app.modules.loyalty.exceptions import (
|
|
LoyaltyProgramAlreadyExistsException,
|
|
LoyaltyProgramNotFoundException,
|
|
)
|
|
from app.modules.loyalty.models import (
|
|
LoyaltyProgram,
|
|
LoyaltyType,
|
|
CompanyLoyaltySettings,
|
|
)
|
|
from app.modules.loyalty.schemas.program import (
|
|
ProgramCreate,
|
|
ProgramUpdate,
|
|
)
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
class ProgramService:
|
|
"""Service for loyalty program operations."""
|
|
|
|
# =========================================================================
|
|
# Read Operations
|
|
# =========================================================================
|
|
|
|
def get_program(self, db: Session, program_id: int) -> LoyaltyProgram | None:
|
|
"""Get a loyalty program by ID."""
|
|
return (
|
|
db.query(LoyaltyProgram)
|
|
.filter(LoyaltyProgram.id == program_id)
|
|
.first()
|
|
)
|
|
|
|
def get_program_by_company(self, db: Session, company_id: int) -> LoyaltyProgram | None:
|
|
"""Get a company's loyalty program."""
|
|
return (
|
|
db.query(LoyaltyProgram)
|
|
.filter(LoyaltyProgram.company_id == company_id)
|
|
.first()
|
|
)
|
|
|
|
def get_active_program_by_company(self, db: Session, company_id: int) -> LoyaltyProgram | None:
|
|
"""Get a company's active loyalty program."""
|
|
return (
|
|
db.query(LoyaltyProgram)
|
|
.filter(
|
|
LoyaltyProgram.company_id == company_id,
|
|
LoyaltyProgram.is_active == True,
|
|
)
|
|
.first()
|
|
)
|
|
|
|
def get_program_by_vendor(self, db: Session, vendor_id: int) -> LoyaltyProgram | None:
|
|
"""
|
|
Get the loyalty program for a vendor.
|
|
|
|
Looks up the vendor's company and returns the company's program.
|
|
"""
|
|
from app.modules.tenancy.models import Vendor
|
|
|
|
vendor = db.query(Vendor).filter(Vendor.id == vendor_id).first()
|
|
if not vendor:
|
|
return None
|
|
|
|
return self.get_program_by_company(db, vendor.company_id)
|
|
|
|
def get_active_program_by_vendor(self, db: Session, vendor_id: int) -> LoyaltyProgram | None:
|
|
"""
|
|
Get the active loyalty program for a vendor.
|
|
|
|
Looks up the vendor's company and returns the company's active program.
|
|
"""
|
|
from app.modules.tenancy.models import Vendor
|
|
|
|
vendor = db.query(Vendor).filter(Vendor.id == vendor_id).first()
|
|
if not vendor:
|
|
return None
|
|
|
|
return self.get_active_program_by_company(db, vendor.company_id)
|
|
|
|
def require_program(self, db: Session, program_id: int) -> LoyaltyProgram:
|
|
"""Get a program or raise exception if not found."""
|
|
program = self.get_program(db, program_id)
|
|
if not program:
|
|
raise LoyaltyProgramNotFoundException(str(program_id))
|
|
return program
|
|
|
|
def require_program_by_company(self, db: Session, company_id: int) -> LoyaltyProgram:
|
|
"""Get a company's program or raise exception if not found."""
|
|
program = self.get_program_by_company(db, company_id)
|
|
if not program:
|
|
raise LoyaltyProgramNotFoundException(f"company:{company_id}")
|
|
return program
|
|
|
|
def require_program_by_vendor(self, db: Session, vendor_id: int) -> LoyaltyProgram:
|
|
"""Get a vendor's program or raise exception if not found."""
|
|
program = self.get_program_by_vendor(db, vendor_id)
|
|
if not program:
|
|
raise LoyaltyProgramNotFoundException(f"vendor:{vendor_id}")
|
|
return program
|
|
|
|
def list_programs(
|
|
self,
|
|
db: Session,
|
|
*,
|
|
skip: int = 0,
|
|
limit: int = 100,
|
|
is_active: bool | None = None,
|
|
search: str | None = None,
|
|
) -> tuple[list[LoyaltyProgram], int]:
|
|
"""List all loyalty programs (admin).
|
|
|
|
Args:
|
|
db: Database session
|
|
skip: Number of records to skip
|
|
limit: Maximum records to return
|
|
is_active: Filter by active status
|
|
search: Search by company name (case-insensitive)
|
|
"""
|
|
from app.modules.tenancy.models import Company
|
|
|
|
query = db.query(LoyaltyProgram).join(
|
|
Company, LoyaltyProgram.company_id == Company.id
|
|
)
|
|
|
|
if is_active is not None:
|
|
query = query.filter(LoyaltyProgram.is_active == is_active)
|
|
|
|
if search:
|
|
search_pattern = f"%{search}%"
|
|
query = query.filter(Company.name.ilike(search_pattern))
|
|
|
|
total = query.count()
|
|
programs = query.order_by(LoyaltyProgram.created_at.desc()).offset(skip).limit(limit).all()
|
|
|
|
return programs, total
|
|
|
|
# =========================================================================
|
|
# Write Operations
|
|
# =========================================================================
|
|
|
|
def create_program(
|
|
self,
|
|
db: Session,
|
|
company_id: int,
|
|
data: ProgramCreate,
|
|
) -> LoyaltyProgram:
|
|
"""
|
|
Create a new loyalty program for a company.
|
|
|
|
Args:
|
|
db: Database session
|
|
company_id: Company ID
|
|
data: Program configuration
|
|
|
|
Returns:
|
|
Created program
|
|
|
|
Raises:
|
|
LoyaltyProgramAlreadyExistsException: If company already has a program
|
|
"""
|
|
# Check if company already has a program
|
|
existing = self.get_program_by_company(db, company_id)
|
|
if existing:
|
|
raise LoyaltyProgramAlreadyExistsException(company_id)
|
|
|
|
# Convert points_rewards to dict list for JSON storage
|
|
points_rewards_data = [r.model_dump() for r in data.points_rewards]
|
|
|
|
program = LoyaltyProgram(
|
|
company_id=company_id,
|
|
loyalty_type=data.loyalty_type,
|
|
# Stamps
|
|
stamps_target=data.stamps_target,
|
|
stamps_reward_description=data.stamps_reward_description,
|
|
stamps_reward_value_cents=data.stamps_reward_value_cents,
|
|
# Points
|
|
points_per_euro=data.points_per_euro,
|
|
points_rewards=points_rewards_data,
|
|
points_expiration_days=data.points_expiration_days,
|
|
welcome_bonus_points=data.welcome_bonus_points,
|
|
minimum_redemption_points=data.minimum_redemption_points,
|
|
minimum_purchase_cents=data.minimum_purchase_cents,
|
|
# Anti-fraud
|
|
cooldown_minutes=data.cooldown_minutes,
|
|
max_daily_stamps=data.max_daily_stamps,
|
|
require_staff_pin=data.require_staff_pin,
|
|
# Branding
|
|
card_name=data.card_name,
|
|
card_color=data.card_color,
|
|
card_secondary_color=data.card_secondary_color,
|
|
logo_url=data.logo_url,
|
|
hero_image_url=data.hero_image_url,
|
|
# Terms
|
|
terms_text=data.terms_text,
|
|
privacy_url=data.privacy_url,
|
|
# Status
|
|
is_active=True,
|
|
activated_at=datetime.now(UTC),
|
|
)
|
|
|
|
db.add(program)
|
|
db.flush()
|
|
|
|
# Create default company settings
|
|
settings = CompanyLoyaltySettings(
|
|
company_id=company_id,
|
|
)
|
|
db.add(settings)
|
|
|
|
db.commit()
|
|
db.refresh(program)
|
|
|
|
logger.info(
|
|
f"Created loyalty program {program.id} for company {company_id} "
|
|
f"(type: {program.loyalty_type})"
|
|
)
|
|
|
|
return program
|
|
|
|
def update_program(
|
|
self,
|
|
db: Session,
|
|
program_id: int,
|
|
data: ProgramUpdate,
|
|
) -> LoyaltyProgram:
|
|
"""
|
|
Update a loyalty program.
|
|
|
|
Args:
|
|
db: Database session
|
|
program_id: Program ID
|
|
data: Update data
|
|
|
|
Returns:
|
|
Updated program
|
|
"""
|
|
program = self.require_program(db, program_id)
|
|
|
|
update_data = data.model_dump(exclude_unset=True)
|
|
|
|
# Handle points_rewards specially (convert to dict list)
|
|
if "points_rewards" in update_data and update_data["points_rewards"] is not None:
|
|
update_data["points_rewards"] = [
|
|
r.model_dump() if hasattr(r, "model_dump") else r
|
|
for r in update_data["points_rewards"]
|
|
]
|
|
|
|
for field, value in update_data.items():
|
|
setattr(program, field, value)
|
|
|
|
db.commit()
|
|
db.refresh(program)
|
|
|
|
logger.info(f"Updated loyalty program {program_id}")
|
|
|
|
return program
|
|
|
|
def activate_program(self, db: Session, program_id: int) -> LoyaltyProgram:
|
|
"""Activate a loyalty program."""
|
|
program = self.require_program(db, program_id)
|
|
program.activate()
|
|
db.commit()
|
|
db.refresh(program)
|
|
logger.info(f"Activated loyalty program {program_id}")
|
|
return program
|
|
|
|
def deactivate_program(self, db: Session, program_id: int) -> LoyaltyProgram:
|
|
"""Deactivate a loyalty program."""
|
|
program = self.require_program(db, program_id)
|
|
program.deactivate()
|
|
db.commit()
|
|
db.refresh(program)
|
|
logger.info(f"Deactivated loyalty program {program_id}")
|
|
return program
|
|
|
|
def delete_program(self, db: Session, program_id: int) -> None:
|
|
"""Delete a loyalty program and all associated data."""
|
|
program = self.require_program(db, program_id)
|
|
company_id = program.company_id
|
|
|
|
# Also delete company settings
|
|
db.query(CompanyLoyaltySettings).filter(
|
|
CompanyLoyaltySettings.company_id == company_id
|
|
).delete()
|
|
|
|
db.delete(program)
|
|
db.commit()
|
|
|
|
logger.info(f"Deleted loyalty program {program_id} for company {company_id}")
|
|
|
|
# =========================================================================
|
|
# Company Settings
|
|
# =========================================================================
|
|
|
|
def get_company_settings(self, db: Session, company_id: int) -> CompanyLoyaltySettings | None:
|
|
"""Get company loyalty settings."""
|
|
return (
|
|
db.query(CompanyLoyaltySettings)
|
|
.filter(CompanyLoyaltySettings.company_id == company_id)
|
|
.first()
|
|
)
|
|
|
|
def get_or_create_company_settings(self, db: Session, company_id: int) -> CompanyLoyaltySettings:
|
|
"""Get or create company loyalty settings."""
|
|
settings = self.get_company_settings(db, company_id)
|
|
if not settings:
|
|
settings = CompanyLoyaltySettings(company_id=company_id)
|
|
db.add(settings)
|
|
db.commit()
|
|
db.refresh(settings)
|
|
return settings
|
|
|
|
# =========================================================================
|
|
# Statistics
|
|
# =========================================================================
|
|
|
|
def get_program_stats(self, db: Session, program_id: int) -> dict:
|
|
"""
|
|
Get statistics for a loyalty program.
|
|
|
|
Returns dict with:
|
|
- total_cards, active_cards
|
|
- total_stamps_issued, total_stamps_redeemed
|
|
- total_points_issued, total_points_redeemed
|
|
- etc.
|
|
"""
|
|
from datetime import timedelta
|
|
|
|
from sqlalchemy import func
|
|
|
|
from app.modules.loyalty.models import LoyaltyCard, LoyaltyTransaction
|
|
|
|
program = self.require_program(db, program_id)
|
|
|
|
# Card counts
|
|
total_cards = (
|
|
db.query(func.count(LoyaltyCard.id))
|
|
.filter(LoyaltyCard.program_id == program_id)
|
|
.scalar()
|
|
or 0
|
|
)
|
|
active_cards = (
|
|
db.query(func.count(LoyaltyCard.id))
|
|
.filter(
|
|
LoyaltyCard.program_id == program_id,
|
|
LoyaltyCard.is_active == True,
|
|
)
|
|
.scalar()
|
|
or 0
|
|
)
|
|
|
|
# Stamp totals from cards
|
|
stamp_stats = (
|
|
db.query(
|
|
func.sum(LoyaltyCard.total_stamps_earned),
|
|
func.sum(LoyaltyCard.stamps_redeemed),
|
|
)
|
|
.filter(LoyaltyCard.program_id == program_id)
|
|
.first()
|
|
)
|
|
total_stamps_issued = stamp_stats[0] or 0
|
|
total_stamps_redeemed = stamp_stats[1] or 0
|
|
|
|
# Points totals from cards
|
|
points_stats = (
|
|
db.query(
|
|
func.sum(LoyaltyCard.total_points_earned),
|
|
func.sum(LoyaltyCard.points_redeemed),
|
|
)
|
|
.filter(LoyaltyCard.program_id == program_id)
|
|
.first()
|
|
)
|
|
total_points_issued = points_stats[0] or 0
|
|
total_points_redeemed = points_stats[1] or 0
|
|
|
|
# This month's activity
|
|
month_start = datetime.now(UTC).replace(day=1, hour=0, minute=0, second=0, microsecond=0)
|
|
|
|
stamps_this_month = (
|
|
db.query(func.count(LoyaltyTransaction.id))
|
|
.join(LoyaltyCard)
|
|
.filter(
|
|
LoyaltyCard.program_id == program_id,
|
|
LoyaltyTransaction.transaction_type == "stamp_earned",
|
|
LoyaltyTransaction.transaction_at >= month_start,
|
|
)
|
|
.scalar()
|
|
or 0
|
|
)
|
|
|
|
redemptions_this_month = (
|
|
db.query(func.count(LoyaltyTransaction.id))
|
|
.join(LoyaltyCard)
|
|
.filter(
|
|
LoyaltyCard.program_id == program_id,
|
|
LoyaltyTransaction.transaction_type == "stamp_redeemed",
|
|
LoyaltyTransaction.transaction_at >= month_start,
|
|
)
|
|
.scalar()
|
|
or 0
|
|
)
|
|
|
|
# 30-day active cards
|
|
thirty_days_ago = datetime.now(UTC) - timedelta(days=30)
|
|
cards_with_activity_30d = (
|
|
db.query(func.count(func.distinct(LoyaltyTransaction.card_id)))
|
|
.join(LoyaltyCard)
|
|
.filter(
|
|
LoyaltyCard.program_id == program_id,
|
|
LoyaltyTransaction.transaction_at >= thirty_days_ago,
|
|
)
|
|
.scalar()
|
|
or 0
|
|
)
|
|
|
|
# Averages
|
|
avg_stamps = total_stamps_issued / total_cards if total_cards > 0 else 0
|
|
avg_points = total_points_issued / total_cards if total_cards > 0 else 0
|
|
|
|
# Estimated liability (unredeemed value)
|
|
current_stamps = (
|
|
db.query(func.sum(LoyaltyCard.stamp_count))
|
|
.filter(LoyaltyCard.program_id == program_id)
|
|
.scalar()
|
|
or 0
|
|
)
|
|
stamp_value = program.stamps_reward_value_cents or 0
|
|
current_points = (
|
|
db.query(func.sum(LoyaltyCard.points_balance))
|
|
.filter(LoyaltyCard.program_id == program_id)
|
|
.scalar()
|
|
or 0
|
|
)
|
|
# Rough estimate: assume 100 points = €1
|
|
points_value_cents = current_points // 100 * 100
|
|
|
|
estimated_liability = (
|
|
(current_stamps * stamp_value // program.stamps_target) + points_value_cents
|
|
)
|
|
|
|
return {
|
|
"total_cards": total_cards,
|
|
"active_cards": active_cards,
|
|
"total_stamps_issued": total_stamps_issued,
|
|
"total_stamps_redeemed": total_stamps_redeemed,
|
|
"stamps_this_month": stamps_this_month,
|
|
"redemptions_this_month": redemptions_this_month,
|
|
"total_points_issued": total_points_issued,
|
|
"total_points_redeemed": total_points_redeemed,
|
|
"cards_with_activity_30d": cards_with_activity_30d,
|
|
"average_stamps_per_card": round(avg_stamps, 2),
|
|
"average_points_per_card": round(avg_points, 2),
|
|
"estimated_liability_cents": estimated_liability,
|
|
}
|
|
|
|
def get_company_stats(self, db: Session, company_id: int) -> dict:
|
|
"""
|
|
Get statistics for a company's loyalty program across all locations.
|
|
|
|
Returns dict with per-vendor breakdown.
|
|
"""
|
|
from datetime import UTC, datetime, timedelta
|
|
|
|
from sqlalchemy import func
|
|
|
|
from app.modules.loyalty.models import LoyaltyCard, LoyaltyTransaction
|
|
from app.modules.tenancy.models import Vendor
|
|
|
|
program = self.get_program_by_company(db, company_id)
|
|
|
|
# Base stats dict
|
|
stats = {
|
|
"company_id": company_id,
|
|
"program_id": program.id if program else None,
|
|
"total_cards": 0,
|
|
"active_cards": 0,
|
|
"total_points_issued": 0,
|
|
"total_points_redeemed": 0,
|
|
"points_issued_30d": 0,
|
|
"points_redeemed_30d": 0,
|
|
"transactions_30d": 0,
|
|
"program": None,
|
|
"locations": [],
|
|
}
|
|
|
|
if not program:
|
|
return stats
|
|
|
|
# Add program info
|
|
stats["program"] = {
|
|
"id": program.id,
|
|
"display_name": program.display_name,
|
|
"card_name": program.card_name,
|
|
"loyalty_type": program.loyalty_type.value if hasattr(program.loyalty_type, 'value') else str(program.loyalty_type),
|
|
"points_per_euro": program.points_per_euro,
|
|
"welcome_bonus_points": program.welcome_bonus_points,
|
|
"minimum_redemption_points": program.minimum_redemption_points,
|
|
"points_expiration_days": program.points_expiration_days,
|
|
"is_active": program.is_active,
|
|
}
|
|
|
|
thirty_days_ago = datetime.now(UTC) - timedelta(days=30)
|
|
|
|
# Total cards
|
|
stats["total_cards"] = (
|
|
db.query(func.count(LoyaltyCard.id))
|
|
.filter(LoyaltyCard.company_id == company_id)
|
|
.scalar()
|
|
or 0
|
|
)
|
|
|
|
# Active cards
|
|
stats["active_cards"] = (
|
|
db.query(func.count(LoyaltyCard.id))
|
|
.filter(
|
|
LoyaltyCard.company_id == company_id,
|
|
LoyaltyCard.is_active == True,
|
|
)
|
|
.scalar()
|
|
or 0
|
|
)
|
|
|
|
# Total points issued (all time)
|
|
stats["total_points_issued"] = (
|
|
db.query(func.sum(LoyaltyTransaction.points_delta))
|
|
.filter(
|
|
LoyaltyTransaction.company_id == company_id,
|
|
LoyaltyTransaction.points_delta > 0,
|
|
)
|
|
.scalar()
|
|
or 0
|
|
)
|
|
|
|
# Total points redeemed (all time)
|
|
stats["total_points_redeemed"] = (
|
|
db.query(func.sum(func.abs(LoyaltyTransaction.points_delta)))
|
|
.filter(
|
|
LoyaltyTransaction.company_id == company_id,
|
|
LoyaltyTransaction.points_delta < 0,
|
|
)
|
|
.scalar()
|
|
or 0
|
|
)
|
|
|
|
# Points issued (30 days)
|
|
stats["points_issued_30d"] = (
|
|
db.query(func.sum(LoyaltyTransaction.points_delta))
|
|
.filter(
|
|
LoyaltyTransaction.company_id == company_id,
|
|
LoyaltyTransaction.points_delta > 0,
|
|
LoyaltyTransaction.transaction_at >= thirty_days_ago,
|
|
)
|
|
.scalar()
|
|
or 0
|
|
)
|
|
|
|
# Points redeemed (30 days)
|
|
stats["points_redeemed_30d"] = (
|
|
db.query(func.sum(func.abs(LoyaltyTransaction.points_delta)))
|
|
.filter(
|
|
LoyaltyTransaction.company_id == company_id,
|
|
LoyaltyTransaction.points_delta < 0,
|
|
LoyaltyTransaction.transaction_at >= thirty_days_ago,
|
|
)
|
|
.scalar()
|
|
or 0
|
|
)
|
|
|
|
# Transactions (30 days)
|
|
stats["transactions_30d"] = (
|
|
db.query(func.count(LoyaltyTransaction.id))
|
|
.filter(
|
|
LoyaltyTransaction.company_id == company_id,
|
|
LoyaltyTransaction.transaction_at >= thirty_days_ago,
|
|
)
|
|
.scalar()
|
|
or 0
|
|
)
|
|
|
|
# Get all vendors for this company for location breakdown
|
|
vendors = db.query(Vendor).filter(Vendor.company_id == company_id).all()
|
|
|
|
location_stats = []
|
|
for vendor in vendors:
|
|
# Cards enrolled at this vendor
|
|
enrolled_count = (
|
|
db.query(func.count(LoyaltyCard.id))
|
|
.filter(
|
|
LoyaltyCard.company_id == company_id,
|
|
LoyaltyCard.enrolled_at_vendor_id == vendor.id,
|
|
)
|
|
.scalar()
|
|
or 0
|
|
)
|
|
|
|
# Points earned at this vendor
|
|
points_earned = (
|
|
db.query(func.sum(LoyaltyTransaction.points_delta))
|
|
.filter(
|
|
LoyaltyTransaction.company_id == company_id,
|
|
LoyaltyTransaction.vendor_id == vendor.id,
|
|
LoyaltyTransaction.points_delta > 0,
|
|
)
|
|
.scalar()
|
|
or 0
|
|
)
|
|
|
|
# Points redeemed at this vendor
|
|
points_redeemed = (
|
|
db.query(func.sum(func.abs(LoyaltyTransaction.points_delta)))
|
|
.filter(
|
|
LoyaltyTransaction.company_id == company_id,
|
|
LoyaltyTransaction.vendor_id == vendor.id,
|
|
LoyaltyTransaction.points_delta < 0,
|
|
)
|
|
.scalar()
|
|
or 0
|
|
)
|
|
|
|
# Transactions (30 days) at this vendor
|
|
transactions_30d = (
|
|
db.query(func.count(LoyaltyTransaction.id))
|
|
.filter(
|
|
LoyaltyTransaction.company_id == company_id,
|
|
LoyaltyTransaction.vendor_id == vendor.id,
|
|
LoyaltyTransaction.transaction_at >= thirty_days_ago,
|
|
)
|
|
.scalar()
|
|
or 0
|
|
)
|
|
|
|
location_stats.append({
|
|
"vendor_id": vendor.id,
|
|
"vendor_name": vendor.name,
|
|
"vendor_code": vendor.vendor_code,
|
|
"enrolled_count": enrolled_count,
|
|
"points_earned": points_earned,
|
|
"points_redeemed": points_redeemed,
|
|
"transactions_30d": transactions_30d,
|
|
})
|
|
|
|
stats["locations"] = location_stats
|
|
|
|
return stats
|
|
|
|
|
|
# Singleton instance
|
|
program_service = ProgramService()
|