基于Python实现的购物商城管理系统
程序员文章站
2022-06-27 11:46:47
完整项目地址:https://github.com/kongxiangchx/shopping-mall-management-system简介本项目使用python语言编写,实现了顾客端和商家端。功...
完整项目地址:
https://github.com/kongxiangchx/shopping-mall-management-system
简介
本项目使用python语言编写,实现了顾客端和商家端。
功能
- 店主功能:注册、登录、修改店铺信息、添加商品、删除商品、修改商品、查找商品、查看交易记录。
- 顾客功能:注册、登录、修改收货信息、查找商品、购买商品、查看交易记录、取消订单。
商家端
- shopmain.py:编写界面上组件的功能,并通过调用send_data.py向服务器发送相应的请求。
- shop :存放商家端的界面代码。
- ui1 :存放商家端的ui文件,使用qtdesigner设计。
- send_data.py 将数据封装成json之后发给服务器。
顾客端
- customermain.py:编写界面上组件的功能,并通过调用send_data.py向服务器发送相应的请求。
- customer :存放顾客端的界面代码。
- ui1 :存放顾客端的ui文件,使用qtdesigner设计。
- send_data.py 将数据封装成json之后发给服务器。
服务器端
- server.py:主要用来处理商家和顾客发来的请求,并调用mysql_op对数据库进行操作。
- mysql_op.py:处理商家和顾客对数据库的操作。
主要代码
shopmain.py
import sys from pyqt5.qtcore import * from pyqt5.qtwidgets import * from pyqt5.qtgui import * import shop.register_window from shop.register_window import * from shop.login_window import * from shop.shop_main import * from shop.add_goods import * from shop.view_goods import * from shop.change_goods import * from shop.update_goods import * from shop.view_trade import * from shop.shop_info import * from send_data import * class register(qmainwindow, ui_register_window): def __init__(self, parent=none): super(register, self).__init__(parent) self.setupui(self) self.reg_bt.clicked.connect(self.click1) self.tologin.clicked.connect(self.click2) def click1(self): username = self.username.text() pass1 = self.pass1.text() pass2 = self.pass2.text() shop_name = self.shop_name.text() phone = self.phone.text() addr = self.addr.currenttext() if username == '' or pass1 == '' or shop_name == '' or phone == '' or addr == '': qmessagebox.information(self, "注册", "店铺信息不能为空", qmessagebox.yes) return if pass1 != pass2: qmessagebox.information(self, "注册", "两次密码不同", qmessagebox.yes) return data = {'id': 'shop', 'type': 'register', 'user': username, 'passwd': pass1, 'shop_name': shop_name, 'phone': phone, 'addr': addr} s = send_data() recv = s.message(data) s.close() if recv['result'] == 'success': qmessagebox.information(self, "注册", "注册成功", qmessagebox.yes) else: qmessagebox.information(self, "注册", "注册失败", qmessagebox.yes) def click2(self): mywin1.hide() mywin2.show() class login(qmainwindow, ui_login_window): def __init__(self, parent=none): super(login, self).__init__(parent) self.setupui(self) self.login_bt.clicked.connect(self.click1) self.toreg.clicked.connect(self.click2) def click1(self): global user username = self.username.text() password = self.password.text() if username == '' or password == '': qmessagebox.information(self, "登录", "用户名和密码不能为空", qmessagebox.yes) return data = {'id': 'shop', 'type': 'login', 'user': username, 'passwd': password} s = send_data() recv = s.message(data) s.close() if recv['result'] == 'success': qmessagebox.information(self, "登录", "登录成功", qmessagebox.yes) user = username mywin2.hide() mywin3.show() else: qmessagebox.information(self, "登录", "登录失败", qmessagebox.yes) def click2(self): mywin2.hide() mywin1.show() class mainwin(qmainwindow, ui_shop_main): def __init__(self, parent=none): super(mainwin, self).__init__(parent) self.setupui(self) self.add_goods.clicked.connect(self.click1) self.view_goods.clicked.connect(self.click2) self.change_goods.clicked.connect(self.click3) self.view_trade.clicked.connect(self.click4) self.shop_info.clicked.connect(self.click5) def click1(self): mywin4.show() def click2(self): mywin5.load() mywin5.show() def click3(self): mywin6.load() mywin6.show() def click4(self): mywin7.show() def click5(self): mywin8.load() mywin8.show() class addgoods(qmainwindow, ui_add_goods): global user def __init__(self, parent=none): super(addgoods, self).__init__(parent) self.setupui(self) self.tomain.clicked.connect(self.click1) self.add_bt.clicked.connect(self.click2) def click1(self): self.hide() def click2(self): goods_name = self.goods_name.text() goods_type = self.goods_type.currenttext() goods_prices = float(self.goods_prices.text()) goods_rest = int(self.goods_rest.text()) data = {'id': 'shop', 'user': user, 'type': 'add_goods', 'goods_name': goods_name, 'goods_type': goods_type, 'goods_prices': goods_prices, 'goods_rest': goods_rest} s = send_data() recv = s.message(data) if recv['result'] == 'success': qmessagebox.information(self, "添加商品", "添加成功", qmessagebox.yes) else: qmessagebox.information(self, "添加商品", "添加失败", qmessagebox.yes) s.close() class viewgoods(qmainwindow, ui_view_goods): global user def __init__(self, parent=none): super(viewgoods, self).__init__(parent) self.setupui(self) self.tomain.clicked.connect(self.click1) self.ser_bt.clicked.connect(self.click2) def click1(self): self.hide() def click2(self): goods_name = self.goods_name.text() goods_type = self.goods_type.currenttext() data = {'id': 'shop', 'type': 'view_goods', 'user': user, 'goods_name': goods_name, 'goods_type': goods_type} s = send_data() recv = s.message(data) s.close() l1 = len(recv['result']) self.model = qstandarditemmodel(l1, 5) self.model.sethorizontalheaderlabels(['名称', '类型', '价格', '库存', '已售']) for i in range(l1): for j in range(5): item = qstandarditem('%s' % (recv['result'][i][j])) self.model.setitem(i, j, item) self.goods.setmodel(self.model) def load(self): self.model = qstandarditemmodel(0, 5) self.model.sethorizontalheaderlabels(['名称', '类型', '价格', '库存', '已售']) self.goods.setmodel(self.model) class changegoods(qmainwindow, ui_change_goods): def __init__(self, parent=none): super(changegoods, self).__init__(parent) self.setupui(self) self.tomain.clicked.connect(self.click1) self.delete_bt.clicked.connect(self.click2) self.toupdate.clicked.connect(self.click3) def click1(self): self.hide() def click2(self): goods_name = self.goods_name.currenttext() if goods_name == '': return data = {'id': 'shop', 'type': 'delete_goods', 'user': user, 'goods_name': goods_name} # print(json.dumps(data)) s = send_data() recv = s.message(data) s.close() if recv['result'] == 'success': self.load() qmessagebox.information(self, "删除商品", "删除成功", qmessagebox.yes) else: qmessagebox.information(self, "删除商品", "删除失败", qmessagebox.yes) def click3(self): goods_name = self.goods_name.currenttext() # print(goods_name) if goods_name != '': mywin9.load(goods_name) mywin9.show() def load(self): data = {'id': 'shop', 'type': 'select_goods', 'user': user} s = send_data() recv = s.message(data) s.close() # print(recv['result']) l1 = len(recv['result']) self.goods_name.clear() for i in range(l1): self.goods_name.additem(recv['result'][i][0]) class updategoods(qmainwindow, ui_update_goods): def __init__(self, parent=none): super(updategoods, self).__init__(parent) self.setupui(self) self.tofront.clicked.connect(self.click1) self.update_bt.clicked.connect(self.click2) def click1(self): self.hide() def click2(self): old_goods_name = self.old_goods_name goods_name = self.goods_name.text() goods_type = self.goods_type.currenttext() goods_prices = float(self.goods_prices.text()) goods_rest = int(self.goods_rest.text()) data = {'id': 'shop', 'type': 'update_goods', 'user': user, 'old_goods_name': old_goods_name, 'goods_name': goods_name, 'goods_type': goods_type, 'goods_prices': goods_prices, 'goods_rest': goods_rest} s = send_data() recv = s.message(data) s.close() if recv['result'] == 'success': self.hide() mywin6.load() qmessagebox.information(self, "修改商品", "修改成功", qmessagebox.yes) else: qmessagebox.information(self, "修改商品", "修改失败", qmessagebox.yes) def load(self, goods_name): self.old_goods_name = goods_name data = {'id': 'shop', 'type': 'select_goodsinfo', 'user': user, 'goods_name': goods_name} # print(json.dumps(data)) s = send_data() recv = s.message(data) s.close() # print(recv['result']) self.goods_name.settext(recv['result'][0]) self.goods_type.setcurrenttext(recv['result'][1]) self.goods_prices.setvalue(recv['result'][2]) self.goods_rest.setvalue(recv['result'][3]) class viewtrade(qmainwindow, ui_view_trade): def __init__(self, parent=none): super(viewtrade, self).__init__(parent) self.setupui(self) self.tomain.clicked.connect(self.click1) self.ser_bt.clicked.connect(self.click2) def click1(self): self.hide() def click2(self): goods_name = self.goods_name.text() goods_type = self.goods_type.currenttext() data = {'id': 'shop', 'type': 'view_trade', 'user': user, 'goods_name': goods_name, 'goods_type': goods_type} s = send_data() recv = s.message(data) s.close() # print(recv['result']) l1 = len(recv['result']) self.model = qstandarditemmodel(l1, 8) self.model.sethorizontalheaderlabels( ['商品名称', '商品类型', '交易数量', '交易金额', '交易时间', '顾客', '联系方式', '收货地址']) for i in range(l1): for j in range(8): item = qstandarditem('%s' % (recv['result'][i][j])) self.model.setitem(i, j, item) self.trade.setmodel(self.model) def load(self): self.model = qstandarditemmodel(0, 8) self.model.sethorizontalheaderlabels( ['商品名称', '商品类型', '交易数量', '交易金额', '交易时间', '顾客', '联系方式', '收货地址']) self.trade.setmodel(self.model) class shopinfo(qmainwindow, ui_shop_info): def __init__(self, parent=none): super(shopinfo, self).__init__(parent) self.setupui(self) self.tomain.clicked.connect(self.click1) self.change_bt.clicked.connect(self.click2) def click1(self): self.hide() def click2(self): pass1 = self.pass1.text() pass2 = self.pass2.text() shop_name = self.shop_name.text() phone = self.phone.text() addr = self.addr.currenttext() data = {'id': 'shop', 'type': 'update_shop', 'user': user, 'passwd': pass1, 'shop_name': shop_name, 'phone': phone, 'addr': addr} s = send_data() recv = s.message(data) s.close() if recv['result'] == 'success': qmessagebox.information(self, "修改店铺信息", "修改成功", qmessagebox.yes) else: qmessagebox.information(self, "修改店铺信息", "修改失败", qmessagebox.yes) self.load() def load(self): data = {'id': 'shop', 'type': 'shop_info', 'user': user} s = send_data() recv = s.message(data) s.close() self.username.settext(recv['result'][0]) self.username.setfocuspolicy(qtcore.qt.nofocus) self.pass1.settext(recv['result'][1]) self.pass2.settext(recv['result'][1]) self.shop_name.settext(recv['result'][2]) self.phone.settext(recv['result'][3]) self.addr.setcurrenttext(recv['result'][4]) self.shop_time.settext(recv['result'][5]) self.shop_time.setfocuspolicy(qtcore.qt.nofocus) if __name__ == '__main__': app = qapplication(sys.argv) user = "" mywin1 = register() mywin1.show() mywin2 = login() mywin3 = mainwin() mywin4 = addgoods() # mywin4.show() mywin5 = viewgoods() # mywin5.show() mywin6 = changegoods() # mywin6.show() mywin7 = viewtrade() # mywin7.show() mywin8 = shopinfo() # mywin8.show() mywin9 = updategoods() if app.exec_() == 0: sys.exit(0)
代码较多不便全部放出,请自行下载或克隆仓库。
以上就是基于python实现的购物商城管理系统的详细内容,更多关于python 购物商城管理系统的资料请关注其它相关文章!
上一篇: 微软官方确认 Win10平板即将全面弃用ARM芯片
下一篇: 成都最出名的小吃有哪些