1
📥
获取客户数据CRM points, spend, tier, 历史
2
🧮
计算等级与积分采购 → points conversion + auto-upgrade
4
📊
报告与分析互动 trends + redemption 历史
import requests, json, pandas as pd
CRM_API = "https://api.retail.com/v2/loyalty"
def fetch_customers():
resp = requests.get(CRM_API + "/customers")
return resp.json().get("customers", [])
def calculate_tier(points):
if points >= 5000: return "Platinum"
if points >= 2000: return "Gold"
if points >= 500: return "Silver"
return "Bronze"
def suggest_reward(customer):
if customer["tier"] == "Platinum": return "VIP access"
if customer["tier"] == "Gold": return "RM 50 reward"
if customer["tier"] == "Silver": return "20% voucher"
return "Welcome bonus"
def analyze_loyalty(customers):
for c in customers:
c["tier"] = calculate_tier(c["points"])
c["reward"] = suggest_reward(c)
return customers
report = analyze_loyalty(fetch_customers())
print(json.dumps(report, indent=2))