基于Python实现的购物商城管理系统


Posted in Python onApril 27, 2021

完整项目地址:

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 购物商城管理系统的资料请关注三水点靠木其它相关文章!

Python 相关文章推荐
Python BeautifulSoup中文乱码问题的2种解决方法
Apr 22 Python
Python实现批量检测HTTP服务的状态
Oct 27 Python
python3使用pyqt5制作一个超简单浏览器的实例
Oct 19 Python
Python图片转换成矩阵,矩阵数据转换成图片的实例
Jul 02 Python
10 行 Python 代码教你自动发送短信(不想回复工作邮件妙招)
Oct 11 Python
Python实现八皇后问题示例代码
Dec 09 Python
浅谈python标准库--functools.partial
Mar 13 Python
Python将字符串常量转化为变量方法总结
Mar 17 Python
如何利用Anaconda配置简单的Python环境
Jun 24 Python
python正则-re的用法详解
Jul 28 Python
python KNN算法实现鸢尾花数据集分类
Oct 24 Python
python学习之使用Matplotlib画实时的动态折线图的示例代码
Feb 25 Python
详解用Python把PDF转为Word方法总结
python实现的web监控系统
python opencv人脸识别考勤系统的完整源码
Apr 26 #Python
python实现监听键盘
Apr 26 #Python
python如何做代码性能分析
Apr 26 #Python
Python字符串对齐方法使用(ljust()、rjust()和center())
Apr 26 #Python
python如何进行基准测试
Apr 26 #Python
You might like
适用于php-5.2 的 php.ini 中文版[金步国翻译]
2011/04/17 PHP
laravel异步监控定时调度器实例详解
2019/06/21 PHP
jQuery Mobile页面跳转后未加载外部JS原因分析及解决
2013/03/18 Javascript
关于原生js中bind函数的简单实现
2016/08/10 Javascript
jQuery与JS加载事件用法分析
2016/09/04 Javascript
如何判断出一个js对象是否一个dom对象
2016/11/24 Javascript
微信小程序模板和模块化用法实例分析
2017/11/28 Javascript
vue父组件向子组件(props)传递数据的方法
2018/01/02 Javascript
Vue中render函数的使用方法
2018/01/31 Javascript
vue单页开发父子组件传值思路详解
2018/05/18 Javascript
详解easyui 切换主题皮肤
2019/04/04 Javascript
构建大型 Vue.js 项目的10条建议(小结)
2019/11/14 Javascript
node使用mysql获取数据库数据中文乱码问题的解决
2019/12/02 Javascript
Vue实现base64编码图片间的切换功能
2019/12/04 Javascript
[39:32]2014 DOTA2国际邀请赛中国区预选赛 TongFu VS DT 第二场
2014/05/23 DOTA
python读写ini配置文件方法实例分析
2015/06/30 Python
在Ubuntu系统下安装使用Python的GUI工具wxPython
2016/02/18 Python
Python实现发送QQ邮件的封装
2017/07/14 Python
python模块之time模块(实例讲解)
2017/09/13 Python
分数霸榜! python助你微信跳一跳拿高分
2018/01/08 Python
tensorflow tf.train.batch之数据批量读取方式
2020/01/20 Python
使用darknet框架的imagenet数据分类预训练操作
2020/07/07 Python
css3动画 小球滚动 js控制动画暂停
2019/11/29 HTML / CSS
HTML5 Web Database 数据库的SQL语句的使用方法
2012/12/09 HTML / CSS
京东奢侈品:全球奢侈品牌
2018/03/17 全球购物
Craghoppers德国官网:户外和旅行服装
2020/02/14 全球购物
幼儿教师寄语集锦
2014/04/03 职场文书
运动会演讲稿50字
2014/08/25 职场文书
年度考核表个人总结
2015/03/06 职场文书
学习杨善洲同志先进事迹心得体会
2016/01/23 职场文书
2016年第十九届推普周活动总结
2016/04/06 职场文书
MySQL学习总结-基础架构概述
2021/04/05 MySQL
python实现网络五子棋
2021/04/11 Python
为什么MySQL分页用limit会越来越慢
2021/07/25 MySQL
Spring Data JPA框架的核心概念和Repository接口
2022/04/28 Java/Android
APP界面设计技巧和注意事项
2022/04/29 杂记