import sqlite3
from datetime import datetime, timedelta
import random

conn = sqlite3.connect('E:/Code/sale/backend/sale.db')
cursor = conn.cursor()

articles = [
    ('新品上市：2024春季限定系列发布', '我们很高兴地宣布2024春季限定系列正式上线，包含多款精选商品，欢迎选购。', 'https://picsum.photos/seed/art1/800/400'),
    ('购物指南：如何选择适合自己的商品', '本文将为您详细介绍如何根据个人需求选择最合适的商品，帮助您做出明智的购买决策。', 'https://picsum.photos/seed/art2/800/400'),
    ('会员福利升级通知', '尊敬的用户，我们已全面升级会员福利体系，现在注册即可享受更多专属优惠。', 'https://picsum.photos/seed/art3/800/400'),
    ('物流配送说明', '为了提供更好的购物体验，我们优化了物流配送流程，现在下单可享受更快的配送服务。', 'https://picsum.photos/seed/art4/800/400'),
    ('售后服务政策更新', '我们更新了售后服务政策，现在支持7天无理由退换货，让您购物更放心。', 'https://picsum.photos/seed/art5/800/400'),
    ('限时优惠活动预告', '本周五将开启限时优惠活动，多款热门商品参与折扣，敬请期待。', 'https://picsum.photos/seed/art6/800/400'),
    ('品牌故事：我们的初心', '了解我们的品牌故事，感受我们对品质的追求和对客户的承诺。', 'https://picsum.photos/seed/art7/800/400'),
    ('用户评价精选：听听他们怎么说', '我们收集了用户的真实评价，看看大家对我们商品和服务的反馈。', 'https://picsum.photos/seed/art8/800/400'),
    ('安全购物须知', '网络购物安全指南，教您如何保护个人信息，安全购物。', 'https://picsum.photos/seed/art9/800/400'),
    ('节日特惠活动即将开始', '节日特惠活动即将开启，超多优惠等你来抢，不要错过！', 'https://picsum.photos/seed/art10/800/400'),
]

lotteries = [
    ('新年大抽奖', '参与新年抽奖，赢取丰厚奖品', '2024-01-01 00:00:00', '2024-12-31 23:59:59'),
    ('春季幸运抽奖', '春季限定抽奖活动，好礼送不停', '2024-03-01 00:00:00', '2024-05-31 23:59:59'),
    ('会员专属抽奖', '会员专属抽奖活动，更多惊喜等你来', '2024-04-01 00:00:00', '2024-06-30 23:59:59'),
]

prizes = [
    ('一等奖：iPhone 15 Pro', 'product', 1, 1, None),
    ('二等奖：AirPods Pro', 'product', 3, 2, None),
    ('三等奖：100积分', 'credits', 10, 3, 100),
    ('参与奖：10积分', 'credits', 50, 1, 10),
]

print('插入资讯数据...')
for i, (title, summary, cover) in enumerate(articles):
    content = f'<h2>{title}</h2><p>{summary}</p><p>这是文章的详细内容，包含了更多相关信息和说明。感谢您的阅读！</p>'
    created_at = datetime.now() - timedelta(days=random.randint(1, 30))
    is_pinned = 1 if i < 2 else 0
    cursor.execute('''
        INSERT INTO articles (title, summary, content, cover_image, is_pinned, author_id, created_at, updated_at)
        VALUES (?, ?, ?, ?, ?, 1, ?, ?)
    ''', (title, summary, content, cover, is_pinned, created_at.strftime('%Y-%m-%d %H:%M:%S'), created_at.strftime('%Y-%m-%d %H:%M:%S')))
print(f'已插入 {len(articles)} 条资讯')

print('插入抽奖数据...')
for name, description, start_time, end_time in lotteries:
    cursor.execute('''
        INSERT INTO lotteries (name, description, start_time, end_time, created_at, updated_at)
        VALUES (?, ?, ?, ?, datetime('now'), datetime('now'))
    ''', (name, description, start_time, end_time))
    lottery_id = cursor.lastrowid
    
    for prize_name, prize_type, quantity, weight, credit_reward in prizes:
        cursor.execute('''
            INSERT INTO lottery_prizes (lottery_id, name, type, quantity, weight, credit_reward)
            VALUES (?, ?, ?, ?, ?, ?)
        ''', (lottery_id, prize_name, prize_type, quantity, weight, credit_reward))
print(f'已插入 {len(lotteries)} 个抽奖活动')

conn.commit()
cursor.close()
conn.close()
print('完成！')
