import sqlite3 import random from datetime import datetime, timedelta # 连接数据库 conn = sqlite3.connect('e:/Code/sale/backend/cmd/server/sale.db') cursor = conn.cursor() # 抽奖活动数据 lotteries = [ { 'name': '新年大抽奖', 'description': '参与新年抽奖,赢取丰厚奖品!iPhone、iPad、AirPods等你来拿!', 'image': 'https://images.unsplash.com/photo-1513151233558-d860c5398176?w=400&h=300&fit=crop', 'start_time': datetime.now().isoformat(), 'end_time': (datetime.now() + timedelta(days=30)).isoformat(), 'cycle': 'daily', 'daily_quota': 100, 'total_quota': 3000, 'registration_validity': 7, 'is_active': 1 }, { 'name': '会员专属抽奖', 'description': '会员专属福利,积分抽奖赢好礼!', 'image': 'https://images.unsplash.com/photo-1511895426328-dc8714191300?w=400&h=300&fit=crop', 'start_time': datetime.now().isoformat(), 'end_time': (datetime.now() + timedelta(days=60)).isoformat(), 'cycle': 'weekly', 'daily_quota': 50, 'total_quota': 1000, 'registration_validity': 14, 'is_active': 1 }, { 'name': '春季特惠抽奖', 'description': '春季特惠活动,购物即可参与抽奖!', 'image': 'https://images.unsplash.com/photo-1492684223066-81342ee5ff30?w=400&h=300&fit=crop', 'start_time': datetime.now().isoformat(), 'end_time': (datetime.now() + timedelta(days=45)).isoformat(), 'cycle': 'monthly', 'daily_quota': 200, 'total_quota': 5000, 'registration_validity': 30, 'is_active': 1 }, { 'name': '限时秒杀抽奖', 'description': '限时秒杀活动,参与抽奖享更多优惠!', 'image': 'https://images.unsplash.com/photo-1607082348824-0a96f2a4b9da?w=400&h=300&fit=crop', 'start_time': datetime.now().isoformat(), 'end_time': (datetime.now() + timedelta(days=15)).isoformat(), 'cycle': 'daily', 'daily_quota': 150, 'total_quota': 2000, 'registration_validity': 5, 'is_active': 1 }, { 'name': '品牌联合抽奖', 'description': '多个品牌联合抽奖,奖品更丰厚!', 'image': 'https://images.unsplash.com/photo-1556742049-0cfed4f6a45d?w=400&h=300&fit=crop', 'start_time': datetime.now().isoformat(), 'end_time': (datetime.now() + timedelta(days=90)).isoformat(), 'cycle': 'weekly', 'daily_quota': 80, 'total_quota': 1500, 'registration_validity': 10, 'is_active': 1 } ] # 插入抽奖活动 for lottery in lotteries: 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 (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) ''', ( lottery['name'], lottery['description'], lottery['image'], lottery['start_time'], lottery['end_time'], lottery['cycle'], lottery['daily_quota'], lottery['total_quota'], lottery['registration_validity'], lottery['is_active'], datetime.now().isoformat(), datetime.now().isoformat() )) print(f"✅ 成功插入 {len(lotteries)} 个抽奖活动") # 资讯数据 articles = [ { 'title': '2024年电商行业发展趋势分析', 'content': '随着技术的不断发展,电商行业正在经历前所未有的变革。本文将深入分析2024年电商行业的发展趋势,包括人工智能、社交电商、直播带货等多个方面。人工智能技术的应用让个性化推荐更加精准,社交电商正在改变传统的购物方式,直播带货已经成为品牌营销的重要渠道。', 'summary': '深入分析2024年电商行业发展趋势,涵盖AI、社交电商、直播带货等热门话题', 'cover_image': 'https://images.unsplash.com/photo-1556742049-0cfed4f6a45d?w=800&h=400&fit=crop', 'is_published': 1, 'is_pinned': 1, 'sort_order': 1 }, { 'title': '如何选择适合自己的商品', 'content': '在众多商品中选择适合自己的产品并不容易。本文将从价格、质量、品牌、用户评价等多个维度,为您提供详细的选购指南。首先,要明确自己的需求和预算;其次,要关注商品的质量和售后服务;最后,要参考其他用户的评价和建议。', 'summary': '从价格、质量、品牌等多维度提供商品选购指南', 'cover_image': 'https://images.unsplash.com/photo-1441986300917-64674bd600d8?w=800&h=400&fit=crop', 'is_published': 1, 'is_pinned': 0, 'sort_order': 2 }, { 'title': '平台优惠活动全攻略', 'content': '想要在购物时获得更多优惠?本文为您详细介绍平台的各种优惠活动,包括满减、折扣、优惠券、积分兑换等多种方式。了解这些优惠规则,让您在购物时省更多钱。满减活动通常在特定节日举行,折扣商品需要及时关注,优惠券可以通过多种渠道获取。', 'summary': '详细介绍平台满减、折扣、优惠券等各种优惠活动', 'cover_image': 'https://images.unsplash.com/photo-1607082348824-0a96f2a4b9da?w=800&h=400&fit=crop', 'is_published': 1, 'is_pinned': 0, 'sort_order': 3 }, { 'title': '新品上市:春季系列商品推荐', 'content': '春季新品已经上市!本文为您推荐本季最热门的商品系列,包括服装、配饰、家居用品等多个品类。春季系列以清新、活力为主题,采用最新的设计理念和优质材料,为您带来全新的使用体验。', 'summary': '推荐春季最热门的新品系列,涵盖多个品类', 'cover_image': 'https://images.unsplash.com/photo-1492684223066-81342ee5ff30?w=800&h=400&fit=crop', 'is_published': 1, 'is_pinned': 1, 'sort_order': 4 }, { 'title': '用户购物安全指南', 'content': '在网上购物时,安全是最重要的。本文为您提供全面的购物安全指南,包括如何识别假冒商品、保护个人信息、安全支付等多个方面。建议您选择官方渠道购买商品,注意查看商品评价和卖家信誉,使用安全的支付方式。', 'summary': '提供全面的网购安全指南,保护您的购物安全', 'cover_image': 'https://images.unsplash.com/photo-1563013544-824ae1b704d3?w=800&h=400&fit=crop', 'is_published': 1, 'is_pinned': 0, 'sort_order': 5 }, { 'title': '积分使用技巧大公开', 'content': '积分是平台会员的重要福利,但很多人不知道如何高效使用积分。本文将为您详细介绍积分的获取方式和使用技巧,让您在购物时获得更多实惠。积分可以通过购物、签到、参与活动等多种方式获取,可以用来兑换商品、抵扣现金等。', 'summary': '详细介绍积分获取方式和使用技巧', 'cover_image': 'https://images.unsplash.com/photo-1556742111-a301076d9c18?w=800&h=400&fit=crop', 'is_published': 1, 'is_pinned': 0, 'sort_order': 6 }, { 'title': '售后服务政策详解', 'content': '了解平台的售后服务政策,让您购物更放心。本文详细介绍了退换货政策、质量保证、维修服务等多个方面。我们承诺7天无理由退换货,30天质量问题包退,1年质量问题保修。让您购物无忧。', 'summary': '详细介绍平台退换货、质量保证等售后服务政策', 'cover_image': 'https://images.unsplash.com/photo-1553877522-43269d4ea984?w=800&h=400&fit=crop', 'is_published': 1, 'is_pinned': 0, 'sort_order': 7 }, { 'title': '会员等级权益全解析', 'content': '平台会员分为多个等级,不同等级享受不同的权益。本文为您详细解析各个等级的权益,包括折扣力度、积分倍率、专属客服等。等级越高,享受的权益越多。升级方式包括购物金额、积分数量、活跃度等多个维度。', 'summary': '详细解析各等级会员权益和升级方式', 'cover_image': 'https://images.unsplash.com/photo-1511895426328-dc8714191300?w=800&h=400&fit=crop', 'is_published': 1, 'is_pinned': 0, 'sort_order': 8 } ] # 插入资讯 for article in articles: cursor.execute(''' INSERT INTO articles (title, content, summary, cover_image, is_published, is_pinned, sort_order, created_at, updated_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?) ''', ( article['title'], article['content'], article['summary'], article['cover_image'], article['is_published'], article['is_pinned'], article['sort_order'], datetime.now().isoformat(), datetime.now().isoformat() )) print(f"✅ 成功插入 {len(articles)} 篇资讯") # 查询验证 cursor.execute('SELECT id, name, is_active FROM lotteries ORDER BY created_at DESC LIMIT 5') lottery_results = cursor.fetchall() cursor.execute('SELECT id, title, is_pinned FROM articles ORDER BY sort_order ASC LIMIT 5') article_results = cursor.fetchall() print("\n抽奖活动:") for row in lottery_results: status = "启用" if row[2] else "禁用" print(f"ID: {row[0]}, 名称: {row[1]}, 状态: {status}") print("\n资讯文章:") for row in article_results: pinned = "置顶" if row[2] else "普通" print(f"ID: {row[0]}, 标题: {row[1]}, 状态: {pinned}") conn.close()