import sqlite3 from datetime import datetime, timedelta # 连接数据库 conn = sqlite3.connect('e:/Code/sale/backend/cmd/server/sale.db') cursor = conn.cursor() # 插入抽奖活动 lotteries_data = [ ('新年大抽奖', '参与新年抽奖,赢取丰厚奖品!iPhone、iPad、AirPods等你来拿!', 'https://images.unsplash.com/photo-1513151233558-d860c5398176?w=400&h=300&fit=crop', 'daily', 100, 3000, 7), ('会员专属抽奖', '会员专属福利,积分抽奖赢好礼!', 'https://images.unsplash.com/photo-1511895426328-dc8714191300?w=400&h=300&fit=crop', 'weekly', 50, 1000, 14), ('春季特惠抽奖', '春季特惠活动,购物即可参与抽奖!', 'https://images.unsplash.com/photo-1492684223066-81342ee5ff30?w=400&h=300&fit=crop', 'monthly', 200, 5000, 30), ('限时秒杀抽奖', '限时秒杀活动,参与抽奖享更多优惠!', 'https://images.unsplash.com/photo-1607082348824-0a96f2a4b9da?w=400&h=300&fit=crop', 'daily', 150, 2000, 5), ('品牌联合抽奖', '多个品牌联合抽奖,奖品更丰厚!', 'https://images.unsplash.com/photo-1556742049-0cfed4f6a45d?w=400&h=300&fit=crop', 'weekly', 80, 1500, 10) ] for name, desc, image, cycle, daily_q, total_q, validity in lotteries_data: cursor.execute(''' INSERT INTO lotteries (name, description, image, start_time, end_time, cycle, daily_quota, total_quota, registration_validity, is_active, created_at, updated_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, 1, ?, ?) ''', (name, desc, image, datetime.now().isoformat(), (datetime.now() + timedelta(days=30)).isoformat(), cycle, daily_q, total_q, validity, datetime.now().isoformat(), datetime.now().isoformat())) # 插入资讯 articles_data = [ ('2024年电商行业发展趋势分析', '随着技术的不断发展,电商行业正在经历前所未有的变革。本文将深入分析2024年电商行业的发展趋势,包括人工智能、社交电商、直播带货等多个方面。', '深入分析2024年电商行业发展趋势', 'https://images.unsplash.com/photo-1556742049-0cfed4f6a45d?w=800&h=400&fit=crop', 1, 1), ('如何选择适合自己的商品', '在众多商品中选择适合自己的产品并不容易。本文将从价格、质量、品牌、用户评价等多个维度,为您提供详细的选购指南。', '从价格、质量、品牌等多维度提供商品选购指南', 'https://images.unsplash.com/photo-1441986300917-64674bd600d8?w=800&h=400&fit=crop', 1, 0), ('平台优惠活动全攻略', '想要在购物时获得更多优惠?本文为您详细介绍平台的各种优惠活动,包括满减、折扣、优惠券、积分兑换等多种方式。', '详细介绍平台满减、折扣、优惠券等各种优惠活动', 'https://images.unsplash.com/photo-1607082348824-0a96f2a4b9da?w=800&h=400&fit=crop', 1, 0), ('新品上市:春季系列商品推荐', '春季新品已经上市!本文为您推荐本季最热门的商品系列,包括服装、配饰、家居用品等多个品类。', '推荐春季最热门的新品系列', 'https://images.unsplash.com/photo-1492684223066-81342ee5ff30?w=800&h=400&fit=crop', 1, 1), ('用户购物安全指南', '在网上购物时,安全是最重要的。本文为您提供全面的购物安全指南,包括如何识别假冒商品、保护个人信息、安全支付等多个方面。', '提供全面的网购安全指南', 'https://images.unsplash.com/photo-1563013544-824ae1b704d3?w=800&h=400&fit=crop', 1, 0), ('积分使用技巧大公开', '积分是平台会员的重要福利,但很多人不知道如何高效使用积分。本文将为您详细介绍积分的获取方式和使用技巧。', '详细介绍积分获取方式和使用技巧', 'https://images.unsplash.com/photo-1556742111-a301076d9c18?w=800&h=400&fit=crop', 1, 0), ('售后服务政策详解', '了解平台的售后服务政策,让您购物更放心。本文详细介绍了退换货政策、质量保证、维修服务等多个方面。', '详细介绍平台退换货、质量保证等售后服务政策', 'https://images.unsplash.com/photo-1553877522-43269d4ea984?w=800&h=400&fit=crop', 1, 0), ('会员等级权益全解析', '平台会员分为多个等级,不同等级享受不同的权益。本文为您详细解析各个等级的权益,包括折扣力度、积分倍率、专属客服等。', '详细解析各等级会员权益和升级方式', 'https://images.unsplash.com/photo-1511895426328-dc8714191300?w=800&h=400&fit=crop', 1, 0) ] for i, (title, content, summary, cover, published, pinned) in enumerate(articles_data, 1): cursor.execute(''' INSERT INTO articles (title, content, summary, cover_image, is_published, is_pinned, sort_order, created_at, updated_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?) ''', (title, content, summary, cover, published, pinned, i, datetime.now().isoformat(), datetime.now().isoformat())) conn.commit() # 验证 cursor.execute('SELECT COUNT(*) FROM lotteries') lottery_count = cursor.fetchone()[0] cursor.execute('SELECT COUNT(*) FROM articles') article_count = cursor.fetchone()[0] print(f"✅ 成功插入 {lottery_count} 个抽奖活动") print(f"✅ 成功插入 {article_count} 篇资讯") conn.close()