54 lines
1.3 KiB
Python
54 lines
1.3 KiB
Python
import sqlite3
|
|
|
|
def create_tables():
|
|
conn = sqlite3.connect('bot_data.db')
|
|
cursor = conn.cursor()
|
|
|
|
cursor.execute('''
|
|
CREATE TABLE IF NOT EXISTS orders (
|
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
name TEXT,
|
|
phone TEXT,
|
|
address TEXT,
|
|
cleaning_time TEXT,
|
|
cleaning_type TEXT,
|
|
payment_method TEXT
|
|
)
|
|
''')
|
|
|
|
cursor.execute('''
|
|
CREATE TABLE IF NOT EXISTS users (
|
|
user_id INTEGER PRIMARY KEY,
|
|
name TEXT,
|
|
phone TEXT,
|
|
address TEXT
|
|
)
|
|
''')
|
|
|
|
conn.commit()
|
|
conn.close()
|
|
|
|
def add_order(name, phone, address, cleaning_time, cleaning_type, payment_method):
|
|
conn = sqlite3.connect('bot_data.db')
|
|
cursor = conn.cursor()
|
|
|
|
cursor.execute('''
|
|
INSERT INTO orders (name, phone, address, cleaning_time, cleaning_type, payment_method)
|
|
VALUES (?, ?, ?, ?, ?, ?)
|
|
''', (name, phone, address, cleaning_time, cleaning_type, payment_method))
|
|
|
|
conn.commit()
|
|
conn.close()
|
|
|
|
def get_order_history(user_id):
|
|
conn = sqlite3.connect('bot_data.db')
|
|
cursor = conn.cursor()
|
|
|
|
cursor.execute('''
|
|
SELECT * FROM orders WHERE user_id = ?
|
|
''', (user_id,))
|
|
|
|
orders = cursor.fetchall()
|
|
conn.close()
|
|
return orders
|