import sqlite3 from datetime import datetime # 连接数据库 conn = sqlite3.connect('../backend/cmd/server/sale.db') cursor = conn.cursor() # 轮播图测试数据 banners = [ { 'title': '新品上市', 'desc': '精选优质商品,限时特惠', 'image': 'https://images.unsplash.com/photo-1441986300917-64674bd600d8?w=1920&h=400&fit=crop', 'link': '/products', 'button': '立即选购', 'bg_color': 'linear-gradient(135deg, #4e6ef2 0%, #7c5cfc 100%)', 'sort_order': 1, 'is_active': 1 }, { 'title': '幸运抽奖', 'desc': '参与抽奖赢取好礼', 'image': 'https://images.unsplash.com/photo-1511895426328-dc8714191300?w=1920&h=400&fit=crop', 'link': '/lotteries', 'button': '参与活动', 'bg_color': 'linear-gradient(135deg, #f59e0b 0%, #f97316 100%)', 'sort_order': 2, 'is_active': 1 }, { 'title': '限时秒杀', 'desc': '每日精选,超值优惠', 'image': 'https://images.unsplash.com/photo-1607082348824-0a96f2a4b9da?w=1920&h=400&fit=crop', 'link': '/products', 'button': '查看详情', 'bg_color': 'linear-gradient(135deg, #10b981 0%, #059669 100%)', 'sort_order': 3, 'is_active': 1 }, { 'title': '会员专享', 'desc': '注册即送积分,享受更多优惠', 'image': 'https://images.unsplash.com/photo-1556742049-0cfed4f6a45d?w=1920&h=400&fit=crop', 'link': '/register', 'button': '立即注册', 'bg_color': 'linear-gradient(135deg, #8b5cf6 0%, #a78bfa 100%)', 'sort_order': 4, 'is_active': 1 } ] # 插入数据 for banner in banners: cursor.execute(''' INSERT INTO banners (title, desc, image, link, button, bg_color, sort_order, is_active, created_at, updated_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?) ''', ( banner['title'], banner['desc'], banner['image'], banner['link'], banner['button'], banner['bg_color'], banner['sort_order'], banner['is_active'], datetime.now().isoformat(), datetime.now().isoformat() )) conn.commit() # 查询验证 cursor.execute('SELECT id, title, link, is_active FROM banners ORDER BY sort_order') results = cursor.fetchall() print(f"✅ 成功插入 {len(banners)} 条轮播图数据:\n") for row in results: status = "启用" if row[3] else "禁用" print(f"ID: {row[0]}, 标题: {row[1]}, 链接: {row[2]}, 状态: {status}") conn.close()