由收银员输入顾客的会员卡卡号(若有卡),所购买的货号。从数据库中取出有关价格信息,在把这些信息返回给收银台,同时把收银台的销售总量和有关种类商品的剩余量以及该持卡顾客的消费情况交数据库存储以供查询。 另外,对没有卡的消费不记录该顾客的消费情况扥个人信息,如果一个未持卡顾客一次购买满200元,可围棋发放一张会员卡,以后在该商场购物可享受9折优惠。 (1)会员信息的管理 (2)商品信息(库存)的管理。支持导入商品信息 (3)顾客购物 (4)顾客订单的管理 (5)超市销售情况汇总,支持导出销售情况。 代码实现
时间: 2024-03-29 21:38:10 浏览: 88
以下是一个简单的超市销售管理系统的代码实现,使用Python和SQLite数据库:
1. 首先创建一个名为supermarket.db的SQLite数据库,包含上述提到的6个表和对应的字段。
2. 编写Python程序,实现系统的各项功能,以下是程序的基本框架:
```python
import sqlite3
# 连接数据库
conn = sqlite3.connect('supermarket.db')
cursor = conn.cursor()
# 定义函数:查询会员信息
def query_member(member_id):
...
# 定义函数:查询商品信息
def query_product(product_id):
...
# 定义函数:新增会员
def add_member(member_id, member_name, member_phone):
...
# 定义函数:查询购物车
def query_cart(member_id):
...
# 定义函数:添加商品到购物车
def add_to_cart(member_id, product_id, quantity):
...
# 定义函数:从购物车删除商品
def delete_from_cart(member_id, product_id):
...
# 定义函数:结算购物车
def checkout(member_id, use_member_card):
...
# 定义函数:查询订单
def query_order(order_id):
...
# 定义函数:导出销售情况
def export_sales_summary(start_date, end_date):
...
# 关闭数据库连接
cursor.close()
conn.close()
```
3. 在各个函数中,使用SQL语句操作数据库,实现具体的功能。以下是一些示例:
```python
# 查询会员信息
def query_member(member_id):
sql = "SELECT * FROM member_info WHERE member_id = ?"
cursor.execute(sql, (member_id,))
return cursor.fetchone()
# 查询商品信息
def query_product(product_id):
sql = "SELECT * FROM product_info WHERE product_id = ?"
cursor.execute(sql, (product_id,))
return cursor.fetchone()
# 新增会员
def add_member(member_id, member_name, member_phone):
sql = "INSERT INTO member_info (member_id, member_name, member_phone, member_discount) VALUES (?, ?, ?, 1.0)"
cursor.execute(sql, (member_id, member_name, member_phone))
conn.commit()
# 查询购物车
def query_cart(member_id):
sql = "SELECT * FROM cart_info WHERE member_id = ?"
cursor.execute(sql, (member_id,))
return cursor.fetchall()
# 添加商品到购物车
def add_to_cart(member_id, product_id, quantity):
product = query_product(product_id)
if product and product[3] >= quantity: # 如果商品存在且库存充足
total_price = product[2] * quantity
sql = "INSERT INTO cart_info (member_id, product_id, quantity, total_price) VALUES (?, ?, ?, ?)"
cursor.execute(sql, (member_id, product_id, quantity, total_price))
conn.commit()
# 更新商品库存
sql = "UPDATE product_info SET product_quantity = product_quantity - ? WHERE product_id = ?"
cursor.execute(sql, (quantity, product_id))
conn.commit()
return True
else:
return False
# 从购物车删除商品
def delete_from_cart(member_id, product_id):
sql = "DELETE FROM cart_info WHERE member_id = ? AND product_id = ?"
cursor.execute(sql, (member_id, product_id))
conn.commit()
# 恢复商品库存
sql = "UPDATE product_info SET product_quantity = product_quantity + ? WHERE product_id = ?"
cursor.execute(sql, (quantity, product_id))
conn.commit()
# 结算购物车
def checkout(member_id, use_member_card):
# 查询购物车
cart = query_cart(member_id)
if cart:
# 计算总价
total_price = sum([item[3] for item in cart])
# 计算折扣
if use_member_card:
member = query_member(member_id)
if member:
total_price *= member[3]
# 生成订单
sql = "INSERT INTO order_info (member_id, order_time, payment, discount, is_member, status) VALUES (?, datetime('now'), ?, ?, ?, '已支付')"
cursor.execute(sql, (member_id, total_price, total_price, use_member_card))
conn.commit()
order_id = cursor.lastrowid
# 将购物车中的商品添加到订单明细中
for item in cart:
sql = "INSERT INTO order_detail (order_id, product_id, quantity, price) VALUES (?, ?, ?, ?)"
cursor.execute(sql, (order_id, item[1], item[2], item[3]))
conn.commit()
# 清空购物车
sql = "DELETE FROM cart_info WHERE member_id = ?"
cursor.execute(sql, (member_id,))
conn.commit()
return True
else:
return False
# 查询订单
def query_order(order_id):
sql = "SELECT * FROM order_info WHERE order_id = ?"
cursor.execute(sql, (order_id,))
order_info = cursor.fetchone()
if order_info:
sql = "SELECT * FROM order_detail WHERE order_id = ?"
cursor.execute(sql, (order_id,))
order_detail = cursor.fetchall()
return order_info, order_detail
else:
return None
# 导出销售情况
def export_sales_summary(start_date, end_date):
sql = "SELECT * FROM sales_summary WHERE summary_date >= ? AND summary_date <= ?"
cursor.execute(sql, (start_date, end_date))
sales_summary = cursor.fetchall()
# 将销售情况导出到Excel文件
...
```
以上仅为示例代码,具体实现还需根据需求进行适当调整和完善。
阅读全文