├── sdeam ├── README.md ├── config │ ├── prod.env.js │ ├── dev.env.js │ └── index.js ├── build │ ├── logo.png │ ├── vue-loader.conf.js │ ├── build.js │ ├── check-versions.js │ ├── webpack.base.conf.js │ ├── utils.js │ ├── webpack.dev.conf.js │ └── webpack.prod.conf.js ├── src │ ├── assets │ │ ├── add.png │ │ ├── gtc.png │ │ ├── tga.png │ │ ├── logo.png │ │ ├── QRcode.png │ │ ├── laisha.png │ │ ├── yuanshen.png │ │ └── cyberpunk.png │ ├── components │ │ ├── Setting.Vue │ │ ├── About.vue │ │ ├── WishListDetail.vue │ │ ├── adminLogin.vue │ │ ├── Store.Vue │ │ ├── Library.vue │ │ ├── WishList.vue │ │ ├── Login.vue │ │ ├── Register.vue │ │ ├── UploadGame.vue │ │ ├── User.vue │ │ └── GameDetail.vue │ ├── main.js │ ├── router │ │ └── index.js │ └── App.vue ├── index.html └── package.json ├── Project Document.docx ├── Project Document.pdf ├── code_back-end ├── __pycache__ │ ├── app.cpython-37.pyc │ ├── app.cpython-38.pyc │ ├── Main.cpython-38.pyc │ ├── Mysql.cpython-37.pyc │ ├── Mysql.cpython-38.pyc │ ├── Commend.cpython-38.pyc │ ├── Common.cpython-38.pyc │ └── Trigger.cpython-38.pyc ├── Class │ ├── __pycache__ │ │ ├── Buy.cpython-37.pyc │ │ ├── Buy.cpython-38.pyc │ │ ├── Game.cpython-37.pyc │ │ ├── Game.cpython-38.pyc │ │ ├── User.cpython-37.pyc │ │ ├── User.cpython-38.pyc │ │ ├── Comment.cpython-37.pyc │ │ ├── Comment.cpython-38.pyc │ │ ├── Father.cpython-37.pyc │ │ ├── Father.cpython-38.pyc │ │ ├── Developer.cpython-37.pyc │ │ ├── Developer.cpython-38.pyc │ │ ├── Favorite.cpython-37.pyc │ │ ├── Favorite.cpython-38.pyc │ │ ├── User2Game.cpython-37.pyc │ │ ├── User2Game.cpython-38.pyc │ │ └── Favorite2Game.cpython-38.pyc │ ├── Favorite.py │ ├── User2Game.py │ ├── Father.py │ ├── Favorite2Game.py │ ├── Comment.py │ ├── Developer.py │ ├── Buy.py │ ├── User.py │ └── Game.py ├── Main.py ├── Mysql.py ├── Common.py ├── Commend.py ├── 表.md ├── Trigger.py ├── 接口.md └── app.py └── README.md /sdeam/README.md: -------------------------------------------------------------------------------- 1 | 前端 2 | -------------------------------------------------------------------------------- /sdeam/config/prod.env.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | module.exports = { 3 | NODE_ENV: '"production"' 4 | } 5 | -------------------------------------------------------------------------------- /Project Document.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gottfriede/BUAA-Database-2018/HEAD/Project Document.docx -------------------------------------------------------------------------------- /Project Document.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gottfriede/BUAA-Database-2018/HEAD/Project Document.pdf -------------------------------------------------------------------------------- /sdeam/build/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gottfriede/BUAA-Database-2018/HEAD/sdeam/build/logo.png -------------------------------------------------------------------------------- /sdeam/src/assets/add.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gottfriede/BUAA-Database-2018/HEAD/sdeam/src/assets/add.png -------------------------------------------------------------------------------- /sdeam/src/assets/gtc.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gottfriede/BUAA-Database-2018/HEAD/sdeam/src/assets/gtc.png -------------------------------------------------------------------------------- /sdeam/src/assets/tga.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gottfriede/BUAA-Database-2018/HEAD/sdeam/src/assets/tga.png -------------------------------------------------------------------------------- /sdeam/src/assets/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gottfriede/BUAA-Database-2018/HEAD/sdeam/src/assets/logo.png -------------------------------------------------------------------------------- /sdeam/src/assets/QRcode.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gottfriede/BUAA-Database-2018/HEAD/sdeam/src/assets/QRcode.png -------------------------------------------------------------------------------- /sdeam/src/assets/laisha.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gottfriede/BUAA-Database-2018/HEAD/sdeam/src/assets/laisha.png -------------------------------------------------------------------------------- /sdeam/src/assets/yuanshen.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gottfriede/BUAA-Database-2018/HEAD/sdeam/src/assets/yuanshen.png -------------------------------------------------------------------------------- /sdeam/src/assets/cyberpunk.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gottfriede/BUAA-Database-2018/HEAD/sdeam/src/assets/cyberpunk.png -------------------------------------------------------------------------------- /code_back-end/__pycache__/app.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gottfriede/BUAA-Database-2018/HEAD/code_back-end/__pycache__/app.cpython-37.pyc -------------------------------------------------------------------------------- /code_back-end/__pycache__/app.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gottfriede/BUAA-Database-2018/HEAD/code_back-end/__pycache__/app.cpython-38.pyc -------------------------------------------------------------------------------- /code_back-end/__pycache__/Main.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gottfriede/BUAA-Database-2018/HEAD/code_back-end/__pycache__/Main.cpython-38.pyc -------------------------------------------------------------------------------- /code_back-end/__pycache__/Mysql.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gottfriede/BUAA-Database-2018/HEAD/code_back-end/__pycache__/Mysql.cpython-37.pyc -------------------------------------------------------------------------------- /code_back-end/__pycache__/Mysql.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gottfriede/BUAA-Database-2018/HEAD/code_back-end/__pycache__/Mysql.cpython-38.pyc -------------------------------------------------------------------------------- /code_back-end/__pycache__/Commend.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gottfriede/BUAA-Database-2018/HEAD/code_back-end/__pycache__/Commend.cpython-38.pyc -------------------------------------------------------------------------------- /code_back-end/__pycache__/Common.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gottfriede/BUAA-Database-2018/HEAD/code_back-end/__pycache__/Common.cpython-38.pyc -------------------------------------------------------------------------------- /code_back-end/__pycache__/Trigger.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gottfriede/BUAA-Database-2018/HEAD/code_back-end/__pycache__/Trigger.cpython-38.pyc -------------------------------------------------------------------------------- /code_back-end/Class/__pycache__/Buy.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gottfriede/BUAA-Database-2018/HEAD/code_back-end/Class/__pycache__/Buy.cpython-37.pyc -------------------------------------------------------------------------------- /code_back-end/Class/__pycache__/Buy.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gottfriede/BUAA-Database-2018/HEAD/code_back-end/Class/__pycache__/Buy.cpython-38.pyc -------------------------------------------------------------------------------- /code_back-end/Class/__pycache__/Game.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gottfriede/BUAA-Database-2018/HEAD/code_back-end/Class/__pycache__/Game.cpython-37.pyc -------------------------------------------------------------------------------- /code_back-end/Class/__pycache__/Game.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gottfriede/BUAA-Database-2018/HEAD/code_back-end/Class/__pycache__/Game.cpython-38.pyc -------------------------------------------------------------------------------- /code_back-end/Class/__pycache__/User.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gottfriede/BUAA-Database-2018/HEAD/code_back-end/Class/__pycache__/User.cpython-37.pyc -------------------------------------------------------------------------------- /code_back-end/Class/__pycache__/User.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gottfriede/BUAA-Database-2018/HEAD/code_back-end/Class/__pycache__/User.cpython-38.pyc -------------------------------------------------------------------------------- /code_back-end/Class/__pycache__/Comment.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gottfriede/BUAA-Database-2018/HEAD/code_back-end/Class/__pycache__/Comment.cpython-37.pyc -------------------------------------------------------------------------------- /code_back-end/Class/__pycache__/Comment.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gottfriede/BUAA-Database-2018/HEAD/code_back-end/Class/__pycache__/Comment.cpython-38.pyc -------------------------------------------------------------------------------- /code_back-end/Class/__pycache__/Father.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gottfriede/BUAA-Database-2018/HEAD/code_back-end/Class/__pycache__/Father.cpython-37.pyc -------------------------------------------------------------------------------- /code_back-end/Class/__pycache__/Father.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gottfriede/BUAA-Database-2018/HEAD/code_back-end/Class/__pycache__/Father.cpython-38.pyc -------------------------------------------------------------------------------- /code_back-end/Class/__pycache__/Developer.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gottfriede/BUAA-Database-2018/HEAD/code_back-end/Class/__pycache__/Developer.cpython-37.pyc -------------------------------------------------------------------------------- /code_back-end/Class/__pycache__/Developer.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gottfriede/BUAA-Database-2018/HEAD/code_back-end/Class/__pycache__/Developer.cpython-38.pyc -------------------------------------------------------------------------------- /code_back-end/Class/__pycache__/Favorite.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gottfriede/BUAA-Database-2018/HEAD/code_back-end/Class/__pycache__/Favorite.cpython-37.pyc -------------------------------------------------------------------------------- /code_back-end/Class/__pycache__/Favorite.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gottfriede/BUAA-Database-2018/HEAD/code_back-end/Class/__pycache__/Favorite.cpython-38.pyc -------------------------------------------------------------------------------- /code_back-end/Class/__pycache__/User2Game.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gottfriede/BUAA-Database-2018/HEAD/code_back-end/Class/__pycache__/User2Game.cpython-37.pyc -------------------------------------------------------------------------------- /code_back-end/Class/__pycache__/User2Game.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gottfriede/BUAA-Database-2018/HEAD/code_back-end/Class/__pycache__/User2Game.cpython-38.pyc -------------------------------------------------------------------------------- /code_back-end/Class/__pycache__/Favorite2Game.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gottfriede/BUAA-Database-2018/HEAD/code_back-end/Class/__pycache__/Favorite2Game.cpython-38.pyc -------------------------------------------------------------------------------- /sdeam/config/dev.env.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | const merge = require('webpack-merge') 3 | const prodEnv = require('./prod.env') 4 | 5 | module.exports = merge(prodEnv, { 6 | NODE_ENV: '"development"' 7 | }) 8 | -------------------------------------------------------------------------------- /sdeam/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | sdeam 7 | 8 | 9 |
10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /code_back-end/Class/Favorite.py: -------------------------------------------------------------------------------- 1 | from sqlalchemy import Column, Integer, String, VARCHAR, Enum 2 | 3 | from Class.Father import Father 4 | 5 | 6 | class Favorite(Father): 7 | __tablename__ = "Favorite" 8 | favoriteID = Column(Integer, primary_key=True, autoincrement=True) # 默认不可为空 9 | favoriteName = Column(VARCHAR(50)) 10 | userID = Column(Integer) 11 | -------------------------------------------------------------------------------- /code_back-end/Class/User2Game.py: -------------------------------------------------------------------------------- 1 | from sqlalchemy import Column, Integer, String, VARCHAR, Enum 2 | 3 | from Class.Father import Father 4 | 5 | 6 | class User2Game(Father): 7 | __tablename__ = "User2Game" 8 | # includeID = Column(Integer, primary_key=True, autoincrement=True) # 默认不可为空 9 | 10 | userID = Column(Integer, primary_key=True) 11 | gameID = Column(Integer, primary_key=True) 12 | -------------------------------------------------------------------------------- /code_back-end/Class/Father.py: -------------------------------------------------------------------------------- 1 | from Mysql import Base, session 2 | 3 | 4 | class Father(Base): 5 | __abstract__ = True 6 | 7 | def save(self): 8 | # 保存对象 9 | session.add(self) 10 | # 提交事务 11 | session.commit() 12 | 13 | def update(self): 14 | session.commit() 15 | 16 | def delete(self): 17 | # 删除对象 18 | session.delete(self) 19 | # 提交事务 20 | session.commit() -------------------------------------------------------------------------------- /code_back-end/Class/Favorite2Game.py: -------------------------------------------------------------------------------- 1 | from sqlalchemy import Column, Integer, String, VARCHAR, Enum 2 | 3 | from Class.Father import Father 4 | 5 | 6 | class Favorite2Game(Father): #包罗,从收藏夹到游戏 7 | __tablename__ = "Favorite2Game" 8 | # includeID = Column(Integer, primary_key=True, autoincrement=True) # 默认不可为空 9 | 10 | favoriteID = Column(Integer, primary_key=True) #收藏夹ID 11 | gameID = Column(Integer, primary_key=True) #游戏ID 12 | -------------------------------------------------------------------------------- /sdeam/src/components/Setting.Vue: -------------------------------------------------------------------------------- 1 | 7 | 8 | 22 | 23 | 25 | -------------------------------------------------------------------------------- /code_back-end/Main.py: -------------------------------------------------------------------------------- 1 | from Mysql import * 2 | from Trigger import * 3 | from app import app 4 | from Commend import * 5 | 6 | com = Commend() # 单例模式 7 | 8 | 9 | def init(): 10 | # 创建表 11 | Base.metadata.create_all(engine) 12 | 13 | # 创建触发器 14 | afterDeleteBuy() 15 | afterDeleteGame() 16 | afterDeleteUser() 17 | afterDeleteDeveloper() 18 | confirmBuy() 19 | 20 | 21 | if __name__ == "__main__": 22 | init() 23 | app.run(debug='true') 24 | -------------------------------------------------------------------------------- /code_back-end/Class/Comment.py: -------------------------------------------------------------------------------- 1 | from sqlalchemy import Column, Integer, String, VARCHAR, Enum 2 | 3 | from Class.Father import Father 4 | 5 | 6 | class Comment(Father): 7 | __tablename__ = "Comment" 8 | commentID = Column(Integer, primary_key=True, autoincrement=True) # 默认不可为空 9 | commentContents = Column(VARCHAR(251)) 10 | commentTime = Column(VARCHAR(30)) 11 | userID = Column(Integer) 12 | gameID = Column(Integer) 13 | grade = Column(Enum('1', '2', '3', '4', '5')) 14 | -------------------------------------------------------------------------------- /code_back-end/Class/Developer.py: -------------------------------------------------------------------------------- 1 | from sqlalchemy import Column, Integer, String, VARCHAR, Enum 2 | 3 | from Class.Father import Father 4 | 5 | 6 | class Developer(Father): 7 | __tablename__ = "Developer" 8 | developerID = Column(Integer, primary_key=True, autoincrement=True) # 默认不可为空 9 | developerName = Column(VARCHAR(50)) 10 | developerPassword = Column(VARCHAR(50)) 11 | developerTel = Column(VARCHAR(20), nullable=True) 12 | developerGraph = Column(VARCHAR(300), nullable=True) 13 | -------------------------------------------------------------------------------- /code_back-end/Class/Buy.py: -------------------------------------------------------------------------------- 1 | from sqlalchemy import Column, Integer, String, VARCHAR, Enum, and_ 2 | 3 | from Class.User2Game import User2Game 4 | from Mysql import session 5 | from Class.Father import Father 6 | 7 | 8 | class Buy(Father): 9 | __tablename__ = "Buy" 10 | buyID = Column(Integer, primary_key=True, autoincrement=True) # 默认不可为空 11 | buyTime = Column(VARCHAR(30)) 12 | userID = Column(Integer) 13 | gameID = Column(Integer) 14 | status = Column(Enum("confirmed", "unconfirmed")) 15 | 16 | -------------------------------------------------------------------------------- /code_back-end/Class/User.py: -------------------------------------------------------------------------------- 1 | from sqlalchemy import Column, Integer, String, VARCHAR 2 | 3 | from Class.Father import Father 4 | 5 | 6 | class User(Father): 7 | __tablename__ = "User" 8 | userID = Column(Integer, primary_key=True, autoincrement=True) # 默认不可为空 9 | userName = Column(String(50)) 10 | userPassword = Column(String(50)) 11 | email = Column(VARCHAR(30), nullable=True) 12 | userTel = Column(VARCHAR(20), nullable=True) 13 | userGraph = Column(VARCHAR(300), nullable=True) # 地址 14 | -------------------------------------------------------------------------------- /sdeam/build/vue-loader.conf.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | const utils = require('./utils') 3 | const config = require('../config') 4 | const isProduction = process.env.NODE_ENV === 'production' 5 | const sourceMapEnabled = isProduction 6 | ? config.build.productionSourceMap 7 | : config.dev.cssSourceMap 8 | 9 | module.exports = { 10 | loaders: utils.cssLoaders({ 11 | sourceMap: sourceMapEnabled, 12 | extract: isProduction 13 | }), 14 | cssSourceMap: sourceMapEnabled, 15 | cacheBusting: config.dev.cacheBusting, 16 | transformToRequire: { 17 | video: ['src', 'poster'], 18 | source: 'src', 19 | img: 'src', 20 | image: 'xlink:href' 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /code_back-end/Class/Game.py: -------------------------------------------------------------------------------- 1 | from sqlalchemy import Column, Integer, String, VARCHAR, Enum, Float 2 | 3 | from Class.Father import Father 4 | 5 | 6 | class Game(Father): 7 | __tablename__ = "Game" 8 | gameID = Column(Integer, primary_key=True, autoincrement=True) # 默认不可为空 9 | gameName = Column(VARCHAR(50)) 10 | gamePrice = Column(Integer) 11 | introduction = Column(VARCHAR(50), nullable=True) 12 | gradeAvg = Column(Float, nullable=True) #总评分 13 | gameType = Column(Enum('action', 'adventure', 'cosplay', 'simulation', 'relaxation', 'else')) 14 | developerID = Column(Integer) 15 | gameGraph = Column(VARCHAR(300),nullable=True)#地址 16 | gameDetailGraph = Column(VARCHAR(300),nullable=True) #详细地址 -------------------------------------------------------------------------------- /code_back-end/Mysql.py: -------------------------------------------------------------------------------- 1 | import sqlalchemy 2 | from sqlalchemy import create_engine 3 | from sqlalchemy.ext.declarative import declarative_base 4 | from sqlalchemy.orm import sessionmaker, scoped_session 5 | 6 | HOSTNAME = "127.0.0.1" 7 | PORT = "3306" 8 | DATABASE = "HomeWork2" 9 | USERNAME = "root" 10 | PASSWORD = "cuijianbin123" 11 | 12 | DB_URI = "mysql+pymysql://{username}:{password}@{host}:{port}/{db}?charset=utf8". \ 13 | format(username=USERNAME, password=PASSWORD, host=HOSTNAME, port=PORT, db=DATABASE) #Connect 14 | 15 | engine = create_engine(DB_URI, echo=False) # 引擎 16 | 17 | Session = scoped_session(sessionmaker(bind=engine) )# 会话 18 | 19 | session = Session() # 实例化 20 | 21 | Base = declarative_base() # Base 22 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # BUAA-Database-2018 2 | 3 | **introduction** 4 | 5 | This is a project for course 'Database', 2020, BUAA. 6 | 7 | + We designed and developed an online game mall where game developers could let the games on/off the shelf. Users could review games, add the game to their favorite list, purchase games and make comments. Administrators could delete comments, block illegal users and game developers. 8 | 9 | + Used the dataset triggers to improve the efficiency and token-based authentication to improve security 10 | + Used SQL-Alchemy to build the database, which contained nine tables and ten entities. 11 | 12 | + We used Flask and Python for back-end, and Vue for front-end. 13 | 14 | 15 | 16 | **中文版:** 17 | 18 | 北航2018级数据库课程设计 SDEAM游戏平台 19 | -------------------------------------------------------------------------------- /code_back-end/Common.py: -------------------------------------------------------------------------------- 1 | from flask import request, jsonify, current_app 2 | from itsdangerous import TimedJSONWebSignatureSerializer as Serializer 3 | 4 | secret_key = 'pbyyds996' 5 | 6 | 7 | def create_token(api_user): 8 | # 第一个参数是内部的私钥,这里写在共用的配置信息里了,如果只是测试可以写死 9 | # 第二个参数是有效期(秒) 10 | s = Serializer(secret_key, expires_in=3600) 11 | # 接收用户id转换与编码 12 | api_user = int(api_user) 13 | token = s.dumps({"id": api_user}).decode("utf-8") 14 | return token 15 | 16 | 17 | def verify_token(token): 18 | # 参数为私有秘钥,跟上面方法的秘钥保持一致 19 | s = Serializer(secret_key) 20 | try: 21 | # 转换为字典 22 | data = s.loads(token) 23 | except Exception: 24 | return None 25 | # 拿到转换后的数据,根据模型类去数据库查询用户信息 26 | return int(data['id']) 27 | -------------------------------------------------------------------------------- /code_back-end/Commend.py: -------------------------------------------------------------------------------- 1 | # 推荐算法 2 | class Commend(): 3 | def __init__(self): 4 | self.User2Map = {} 5 | self.Game2Time = {} 6 | self.commentList = [] # 放gameID 7 | 8 | def deleteGame(self, id): 9 | if id in self.Game2Time.keys(): 10 | self.Game2Time.pop(id) # 移除 11 | if id in self.commentList: 12 | self.commentList.remove(id) 13 | 14 | def getCommentList(self): 15 | print(self.Game2Time) 16 | self.commentList = self.sort_by_value(self.Game2Time) 17 | return self.commentList 18 | 19 | def sort_by_value(self, d): 20 | items = d.items() 21 | backitems = [[v[1], v[0]] for v in items] 22 | backitems.sort(reverse=True)#从大到小排序 23 | return [backitems[i][1] for i in range(0, len(backitems))] # 返回key 24 | -------------------------------------------------------------------------------- /sdeam/src/components/About.vue: -------------------------------------------------------------------------------- 1 | 11 | 12 | 42 | 43 | 45 | -------------------------------------------------------------------------------- /sdeam/src/main.js: -------------------------------------------------------------------------------- 1 | // The Vue build version to load with the `import` command 2 | // (runtime-only or standalone) has been set in webpack.base.conf with an alias. 3 | import Vue from 'vue' 4 | import App from './App' 5 | import router from './router' 6 | 7 | import Antd from 'ant-design-vue' 8 | import 'ant-design-vue/dist/antd.css' 9 | 10 | import axios from 'axios' 11 | import Vuex from 'vuex' 12 | 13 | Vue.use(Antd) 14 | Vue.use(Vuex) 15 | axios.defaults.withCredentials = true 16 | Vue.prototype.$axios = axios 17 | 18 | Vue.config.productionTip = false 19 | 20 | const store = new Vuex.Store({ 21 | state: { 22 | logged: false, 23 | userID: '', 24 | username: '', 25 | usertype: '', 26 | avatarSrc: '' 27 | }, 28 | mutations: { 29 | changeUser (state, newValue) { 30 | state.username = newValue.username 31 | state.logged = true 32 | state.usertype = newValue.usertype 33 | state.userID = newValue.userID 34 | state.avatarSrc = newValue.avatarSrc 35 | }, 36 | changeAvatar (state, newValue) { 37 | state.avatarSrc = newValue.avatarSrc 38 | } 39 | } 40 | }) 41 | 42 | /* eslint-disable no-new */ 43 | new Vue({ 44 | el: '#app', 45 | router, 46 | store, 47 | components: { App }, 48 | template: '' 49 | }) 50 | -------------------------------------------------------------------------------- /sdeam/build/build.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | require('./check-versions')() 3 | 4 | process.env.NODE_ENV = 'production' 5 | 6 | const ora = require('ora') 7 | const rm = require('rimraf') 8 | const path = require('path') 9 | const chalk = require('chalk') 10 | const webpack = require('webpack') 11 | const config = require('../config') 12 | const webpackConfig = require('./webpack.prod.conf') 13 | 14 | const spinner = ora('building for production...') 15 | spinner.start() 16 | 17 | rm(path.join(config.build.assetsRoot, config.build.assetsSubDirectory), err => { 18 | if (err) throw err 19 | webpack(webpackConfig, (err, stats) => { 20 | spinner.stop() 21 | if (err) throw err 22 | process.stdout.write(stats.toString({ 23 | colors: true, 24 | modules: false, 25 | children: false, // If you are using ts-loader, setting this to true will make TypeScript errors show up during build. 26 | chunks: false, 27 | chunkModules: false 28 | }) + '\n\n') 29 | 30 | if (stats.hasErrors()) { 31 | console.log(chalk.red(' Build failed with errors.\n')) 32 | process.exit(1) 33 | } 34 | 35 | console.log(chalk.cyan(' Build complete.\n')) 36 | console.log(chalk.yellow( 37 | ' Tip: built files are meant to be served over an HTTP server.\n' + 38 | ' Opening index.html over file:// won\'t work.\n' 39 | )) 40 | }) 41 | }) 42 | -------------------------------------------------------------------------------- /sdeam/build/check-versions.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | const chalk = require('chalk') 3 | const semver = require('semver') 4 | const packageConfig = require('../package.json') 5 | const shell = require('shelljs') 6 | 7 | function exec (cmd) { 8 | return require('child_process').execSync(cmd).toString().trim() 9 | } 10 | 11 | const versionRequirements = [ 12 | { 13 | name: 'node', 14 | currentVersion: semver.clean(process.version), 15 | versionRequirement: packageConfig.engines.node 16 | } 17 | ] 18 | 19 | if (shell.which('npm')) { 20 | versionRequirements.push({ 21 | name: 'npm', 22 | currentVersion: exec('npm --version'), 23 | versionRequirement: packageConfig.engines.npm 24 | }) 25 | } 26 | 27 | module.exports = function () { 28 | const warnings = [] 29 | 30 | for (let i = 0; i < versionRequirements.length; i++) { 31 | const mod = versionRequirements[i] 32 | 33 | if (!semver.satisfies(mod.currentVersion, mod.versionRequirement)) { 34 | warnings.push(mod.name + ': ' + 35 | chalk.red(mod.currentVersion) + ' should be ' + 36 | chalk.green(mod.versionRequirement) 37 | ) 38 | } 39 | } 40 | 41 | if (warnings.length) { 42 | console.log('') 43 | console.log(chalk.yellow('To use this template, you must update following to modules:')) 44 | console.log() 45 | 46 | for (let i = 0; i < warnings.length; i++) { 47 | const warning = warnings[i] 48 | console.log(' ' + warning) 49 | } 50 | 51 | console.log() 52 | process.exit(1) 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /sdeam/src/router/index.js: -------------------------------------------------------------------------------- 1 | import Vue from 'vue' 2 | import Router from 'vue-router' 3 | import Store from '../components/Store' 4 | import About from '../components/About' 5 | import Login from '../components/Login' 6 | import Register from '../components/Register' 7 | import Setting from '../components/Setting' 8 | import User from '../components/User' 9 | import UploadGame from '../components/UploadGame' 10 | import Library from '../components/Library' 11 | import WishList from '../components/WishList' 12 | import GameDetail from '../components/GameDetail' 13 | import WishListDetail from '../components/WishListDetail' 14 | import AdminLogin from '../components/AdminLogin' 15 | 16 | Vue.use(Router) 17 | 18 | export default new Router({ 19 | mode: 'history', 20 | routes: [ 21 | { 22 | path: '/About', 23 | component: About 24 | }, 25 | { 26 | path: '/Login', 27 | component: Login 28 | }, 29 | { 30 | path: '/AdminLogin', 31 | component: AdminLogin 32 | }, 33 | { 34 | path: '/Register', 35 | component: Register 36 | }, 37 | { 38 | path: '/Store', 39 | component: Store 40 | }, 41 | { 42 | path: '/Setting', 43 | component: Setting 44 | }, 45 | { 46 | path: '/User/:type/:id', 47 | component: User 48 | }, 49 | { 50 | path: '/UploadGame', 51 | component: UploadGame 52 | }, 53 | { 54 | path: '/Library', 55 | component: Library 56 | }, 57 | { 58 | path: '/WishList', 59 | component: WishList 60 | }, 61 | { 62 | path: '/WishListDetail/:userID/:wishListID', 63 | component: WishListDetail 64 | }, 65 | { 66 | path: '/GameDetail/:gameID', 67 | component: GameDetail 68 | } 69 | ] 70 | }) 71 | -------------------------------------------------------------------------------- /code_back-end/表.md: -------------------------------------------------------------------------------- 1 | 1.User(用户表) 2 | 3 | userID : Int NOTNULL 4 | 5 | userName: VARCHAR(50) NOTNULL 6 | 7 | userPassword: VARCHAR(50) NOTNULL 8 | 9 | email: VARCHAR(30) 10 | 11 | userTel:VARCHAR(20) 12 | 13 | userGraph: VARCHAR(30) 图片地址 14 | 15 | 16 | 17 | 2.Game(游戏表) 18 | 19 | gameID:int NOTNULL 20 | 21 | gameName: VARCHAR(50) NOTNULL 22 | 23 | gamePrice : INT NOTNULL 24 | 25 | introduction: VARCHAR(502) 26 | 27 | gameType : enum NOTNULL('action','adventure','cosplay','simulation',relaxation','else') 28 | 29 | developerID: INT NOTNULL 30 | 31 | gameGraph: VARCHAR(300) NOTNULL (图片地址) 32 | 33 | gameDetailGraph: VARCHAR(300) NOTNULL(详情图片地址) 34 | 35 | gradeAvg: float 总评分 36 | 37 | 38 | 39 | 3.Developer(厂商) 40 | 41 | developerID:int NOTNULL 42 | 43 | developerName: VARCHAR(50) NOTNULL 44 | 45 | developerPassword: VARCHAR(50) NOTNULL 46 | 47 | developerTel: VARCHAR(20) 48 | 49 | developerGraph:VARCHAR(300) NOTNULL (图片地址) 50 | 51 | 52 | 53 | 5.Buy(订单/用户游戏关系) 54 | 55 | buyID: int NOTNULL 56 | 57 | buyTime: VARCHAR(30) NOTNULL 58 | 59 | userID: INT NOTNULL 60 | 61 | gameID: INT NOTNULL 62 | 63 | status: ENUM ("confirmed","unconfirmed") 64 | 65 | 66 | 67 | 6.Favorite(收藏夹) 68 | 69 | favoriteID: int NOTNULL 70 | 71 | favoriteName: VARCHAR(50) NOTNULL 72 | 73 | userID: int NOTNULL 74 | 75 | 76 | 77 | 7.Comment(评论): 78 | 79 | commentID: int NOTNULL 80 | 81 | commentContents: VARCHAR(251) NOTNULL 82 | 83 | commentTime: VARCHAR(30) NOTNULL 84 | 85 | userID: INT NOTNULL 86 | 87 | gameID: INT NOTNULL 88 | 89 | grade: ENUM(1,2,3,4,5) 90 | 91 | 92 | 93 | 94 | 95 | 9.User2Game(游戏与用户的关系) 96 | 97 | userID: int notNUll 98 | 99 | gameID:int notnull 100 | 101 | 102 | 103 | 10. Favorite2Game(收藏夹与游戏) 104 | 105 | favoriteID: int notnull 106 | 107 | gameID:int notnull -------------------------------------------------------------------------------- /sdeam/src/components/WishListDetail.vue: -------------------------------------------------------------------------------- 1 | 24 | 25 | 62 | 63 | 65 | -------------------------------------------------------------------------------- /sdeam/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "sdeam", 3 | "version": "1.0.0", 4 | "description": "database project", 5 | "author": "甘天淳 <18373584@buaa.edu.cn>", 6 | "private": true, 7 | "scripts": { 8 | "dev": "webpack-dev-server --inline --progress --config build/webpack.dev.conf.js", 9 | "start": "npm run dev", 10 | "lint": "eslint --ext .js,.vue src", 11 | "build": "node build/build.js" 12 | }, 13 | "dependencies": { 14 | "ant-design-vue": "^1.6.5", 15 | "vue": "^2.5.2", 16 | "vue-router": "^3.0.1", 17 | "vuex": "^3.5.1" 18 | }, 19 | "devDependencies": { 20 | "autoprefixer": "^7.1.2", 21 | "babel-core": "^6.22.1", 22 | "babel-eslint": "^8.2.1", 23 | "babel-helper-vue-jsx-merge-props": "^2.0.3", 24 | "babel-loader": "^7.1.1", 25 | "babel-plugin-syntax-jsx": "^6.18.0", 26 | "babel-plugin-transform-runtime": "^6.22.0", 27 | "babel-plugin-transform-vue-jsx": "^3.5.0", 28 | "babel-preset-env": "^1.3.2", 29 | "babel-preset-stage-2": "^6.22.0", 30 | "chalk": "^2.0.1", 31 | "copy-webpack-plugin": "^4.0.1", 32 | "css-loader": "^0.28.0", 33 | "eslint": "^4.15.0", 34 | "eslint-config-standard": "^10.2.1", 35 | "eslint-friendly-formatter": "^3.0.0", 36 | "eslint-loader": "^1.7.1", 37 | "eslint-plugin-import": "^2.7.0", 38 | "eslint-plugin-node": "^5.2.0", 39 | "eslint-plugin-promise": "^3.4.0", 40 | "eslint-plugin-standard": "^3.0.1", 41 | "eslint-plugin-vue": "^4.0.0", 42 | "extract-text-webpack-plugin": "^3.0.0", 43 | "file-loader": "^1.1.4", 44 | "friendly-errors-webpack-plugin": "^1.6.1", 45 | "html-webpack-plugin": "^2.30.1", 46 | "node-notifier": "^5.1.2", 47 | "optimize-css-assets-webpack-plugin": "^3.2.0", 48 | "ora": "^1.2.0", 49 | "portfinder": "^1.0.13", 50 | "postcss-import": "^11.0.0", 51 | "postcss-loader": "^2.0.8", 52 | "postcss-url": "^7.2.1", 53 | "rimraf": "^2.6.0", 54 | "semver": "^5.3.0", 55 | "shelljs": "^0.7.6", 56 | "uglifyjs-webpack-plugin": "^1.1.1", 57 | "url-loader": "^0.5.8", 58 | "vue-loader": "^13.3.0", 59 | "vue-style-loader": "^3.0.1", 60 | "vue-template-compiler": "^2.5.2", 61 | "webpack": "^3.6.0", 62 | "webpack-bundle-analyzer": "^2.9.0", 63 | "webpack-dev-server": "^2.9.1", 64 | "webpack-merge": "^4.1.0" 65 | }, 66 | "engines": { 67 | "node": ">= 6.0.0", 68 | "npm": ">= 3.0.0" 69 | }, 70 | "browserslist": [ 71 | "> 1%", 72 | "last 2 versions", 73 | "not ie <= 8" 74 | ] 75 | } 76 | -------------------------------------------------------------------------------- /sdeam/config/index.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | // Template version: 1.3.1 3 | // see http://vuejs-templates.github.io/webpack for documentation. 4 | 5 | const path = require('path') 6 | 7 | module.exports = { 8 | dev: { 9 | 10 | // Paths 11 | assetsSubDirectory: 'static', 12 | assetsPublicPath: '/', 13 | proxyTable: { 14 | '/': { 15 | target: 'http://127.0.0.1:5000', 16 | changeOrigin: true, 17 | } 18 | }, 19 | 20 | // Various Dev Server settings 21 | host: 'localhost', // can be overwritten by process.env.HOST 22 | port: 8080, // can be overwritten by process.env.PORT, if port is in use, a free one will be determined 23 | autoOpenBrowser: false, 24 | errorOverlay: true, 25 | notifyOnErrors: true, 26 | poll: false, // https://webpack.js.org/configuration/dev-server/#devserver-watchoptions- 27 | 28 | // Use Eslint Loader? 29 | // If true, your code will be linted during bundling and 30 | // linting errors and warnings will be shown in the console. 31 | useEslint: true, 32 | // If true, eslint errors and warnings will also be shown in the error overlay 33 | // in the browser. 34 | showEslintErrorsInOverlay: false, 35 | 36 | /** 37 | * Source Maps 38 | */ 39 | 40 | // https://webpack.js.org/configuration/devtool/#development 41 | devtool: 'cheap-module-eval-source-map', 42 | 43 | // If you have problems debugging vue-files in devtools, 44 | // set this to false - it *may* help 45 | // https://vue-loader.vuejs.org/en/options.html#cachebusting 46 | cacheBusting: true, 47 | 48 | cssSourceMap: true 49 | }, 50 | 51 | build: { 52 | // Template for index.html 53 | index: path.resolve(__dirname, '../dist/index.html'), 54 | 55 | // Paths 56 | assetsRoot: path.resolve(__dirname, '../dist'), 57 | assetsSubDirectory: 'static', 58 | assetsPublicPath: '/', 59 | 60 | /** 61 | * Source Maps 62 | */ 63 | 64 | productionSourceMap: true, 65 | // https://webpack.js.org/configuration/devtool/#production 66 | devtool: '#source-map', 67 | 68 | // Gzip off by default as many popular static hosts such as 69 | // Surge or Netlify already gzip all static assets for you. 70 | // Before setting to `true`, make sure to: 71 | // npm install --save-dev compression-webpack-plugin 72 | productionGzip: false, 73 | productionGzipExtensions: ['js', 'css'], 74 | 75 | // Run the build command with an extra argument to 76 | // View the bundle analyzer report after build finishes: 77 | // `npm run build --report` 78 | // Set to `true` or `false` to always turn it on or off 79 | bundleAnalyzerReport: process.env.npm_config_report 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /sdeam/build/webpack.base.conf.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | const path = require('path') 3 | const utils = require('./utils') 4 | const config = require('../config') 5 | const vueLoaderConfig = require('./vue-loader.conf') 6 | 7 | function resolve (dir) { 8 | return path.join(__dirname, '..', dir) 9 | } 10 | 11 | const createLintingRule = () => ({ 12 | test: /\.(js|vue)$/, 13 | loader: 'eslint-loader', 14 | enforce: 'pre', 15 | include: [resolve('src'), resolve('test')], 16 | options: { 17 | formatter: require('eslint-friendly-formatter'), 18 | emitWarning: !config.dev.showEslintErrorsInOverlay 19 | } 20 | }) 21 | 22 | module.exports = { 23 | context: path.resolve(__dirname, '../'), 24 | entry: { 25 | app: './src/main.js' 26 | }, 27 | output: { 28 | path: config.build.assetsRoot, 29 | filename: '[name].js', 30 | publicPath: process.env.NODE_ENV === 'production' 31 | ? config.build.assetsPublicPath 32 | : config.dev.assetsPublicPath 33 | }, 34 | resolve: { 35 | extensions: ['.js', '.vue', '.json'], 36 | alias: { 37 | 'vue$': 'vue/dist/vue.esm.js', 38 | '@': resolve('src'), 39 | } 40 | }, 41 | module: { 42 | rules: [ 43 | ...(config.dev.useEslint ? [createLintingRule()] : []), 44 | { 45 | test: /\.vue$/, 46 | loader: 'vue-loader', 47 | options: vueLoaderConfig 48 | }, 49 | { 50 | test: /\.js$/, 51 | loader: 'babel-loader', 52 | include: [resolve('src'), resolve('test'), resolve('node_modules/webpack-dev-server/client')] 53 | }, 54 | { 55 | test: /\.(png|jpe?g|gif|svg)(\?.*)?$/, 56 | loader: 'url-loader', 57 | options: { 58 | limit: 10000, 59 | name: utils.assetsPath('img/[name].[hash:7].[ext]') 60 | } 61 | }, 62 | { 63 | test: /\.(mp4|webm|ogg|mp3|wav|flac|aac)(\?.*)?$/, 64 | loader: 'url-loader', 65 | options: { 66 | limit: 10000, 67 | name: utils.assetsPath('media/[name].[hash:7].[ext]') 68 | } 69 | }, 70 | { 71 | test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/, 72 | loader: 'url-loader', 73 | options: { 74 | limit: 10000, 75 | name: utils.assetsPath('fonts/[name].[hash:7].[ext]') 76 | } 77 | } 78 | ] 79 | }, 80 | node: { 81 | // prevent webpack from injecting useless setImmediate polyfill because Vue 82 | // source contains it (although only uses it if it's native). 83 | setImmediate: false, 84 | // prevent webpack from injecting mocks to Node native modules 85 | // that does not make sense for the client 86 | dgram: 'empty', 87 | fs: 'empty', 88 | net: 'empty', 89 | tls: 'empty', 90 | child_process: 'empty' 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /sdeam/src/components/adminLogin.vue: -------------------------------------------------------------------------------- 1 | 44 | 45 | 87 | 88 | 99 | -------------------------------------------------------------------------------- /sdeam/build/utils.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | const path = require('path') 3 | const config = require('../config') 4 | const ExtractTextPlugin = require('extract-text-webpack-plugin') 5 | const packageConfig = require('../package.json') 6 | 7 | exports.assetsPath = function (_path) { 8 | const assetsSubDirectory = process.env.NODE_ENV === 'production' 9 | ? config.build.assetsSubDirectory 10 | : config.dev.assetsSubDirectory 11 | 12 | return path.posix.join(assetsSubDirectory, _path) 13 | } 14 | 15 | exports.cssLoaders = function (options) { 16 | options = options || {} 17 | 18 | const cssLoader = { 19 | loader: 'css-loader', 20 | options: { 21 | sourceMap: options.sourceMap 22 | } 23 | } 24 | 25 | const postcssLoader = { 26 | loader: 'postcss-loader', 27 | options: { 28 | sourceMap: options.sourceMap 29 | } 30 | } 31 | 32 | // generate loader string to be used with extract text plugin 33 | function generateLoaders (loader, loaderOptions) { 34 | const loaders = options.usePostCSS ? [cssLoader, postcssLoader] : [cssLoader] 35 | 36 | if (loader) { 37 | loaders.push({ 38 | loader: loader + '-loader', 39 | options: Object.assign({}, loaderOptions, { 40 | sourceMap: options.sourceMap 41 | }) 42 | }) 43 | } 44 | 45 | // Extract CSS when that option is specified 46 | // (which is the case during production build) 47 | if (options.extract) { 48 | return ExtractTextPlugin.extract({ 49 | use: loaders, 50 | fallback: 'vue-style-loader' 51 | }) 52 | } else { 53 | return ['vue-style-loader'].concat(loaders) 54 | } 55 | } 56 | 57 | // https://vue-loader.vuejs.org/en/configurations/extract-css.html 58 | return { 59 | css: generateLoaders(), 60 | postcss: generateLoaders(), 61 | less: generateLoaders('less'), 62 | sass: generateLoaders('sass', { indentedSyntax: true }), 63 | scss: generateLoaders('sass'), 64 | stylus: generateLoaders('stylus'), 65 | styl: generateLoaders('stylus') 66 | } 67 | } 68 | 69 | // Generate loaders for standalone style files (outside of .vue) 70 | exports.styleLoaders = function (options) { 71 | const output = [] 72 | const loaders = exports.cssLoaders(options) 73 | 74 | for (const extension in loaders) { 75 | const loader = loaders[extension] 76 | output.push({ 77 | test: new RegExp('\\.' + extension + '$'), 78 | use: loader 79 | }) 80 | } 81 | 82 | return output 83 | } 84 | 85 | exports.createNotifierCallback = () => { 86 | const notifier = require('node-notifier') 87 | 88 | return (severity, errors) => { 89 | if (severity !== 'error') return 90 | 91 | const error = errors[0] 92 | const filename = error.file && error.file.split('!').pop() 93 | 94 | notifier.notify({ 95 | title: packageConfig.name, 96 | message: severity + ': ' + error.name, 97 | subtitle: filename || '', 98 | icon: path.join(__dirname, 'logo.png') 99 | }) 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /code_back-end/Trigger.py: -------------------------------------------------------------------------------- 1 | from Mysql import session 2 | 3 | 4 | ############## 触发器 ################## 5 | def afterDeleteBuy(): 6 | session.execute("DROP TRIGGER IF EXISTS afterDeleteBuy") 7 | session.commit() 8 | afterDeleteBuy = "CREATE TRIGGER afterDeleteBuy before DELETE " \ 9 | "ON Buy FOR EACH ROW " \ 10 | "BEGIN " \ 11 | "DELETE FROM User2Game WHERE gameID = old.gameID and userID = old.userID; " \ 12 | "END;" 13 | 14 | session.execute(afterDeleteBuy) 15 | session.commit() 16 | 17 | 18 | def afterDeleteGame(): 19 | session.execute("DROP TRIGGER IF EXISTS afterDeleteGame") 20 | session.commit() 21 | afterDeleteGame = "CREATE TRIGGER afterDeleteGame before DELETE " \ 22 | "ON Game FOR EACH ROW " \ 23 | "BEGIN " \ 24 | "DELETE FROM Buy WHERE gameID = old.gameID ; " \ 25 | "DELETE FROM Comment WHERE gameID = old.gameID ; " \ 26 | "DELETE FROM Favorite2Game WHERE gameID = old.gameID ; " \ 27 | "DELETE FROM User2Game WHERE gameID = old.gameID ; " \ 28 | "END;" 29 | 30 | session.execute(afterDeleteGame) 31 | session.commit() 32 | 33 | # 34 | def afterDeleteUser(): 35 | session.execute("DROP TRIGGER IF EXISTS afterDeleteUser") 36 | session.commit() 37 | afterDeleteUser = "CREATE TRIGGER afterDeleteUser before DELETE " \ 38 | "ON User FOR EACH ROW " \ 39 | "BEGIN " \ 40 | "DELETE FROM Buy WHERE userID = old.userID ; " \ 41 | "DELETE FROM Comment WHERE userID = old.userID ; " \ 42 | "DELETE FROM Favorite WHERE userID = old.userID ; " \ 43 | "DELETE FROM User2Game WHERE userID = old.userID ; " \ 44 | "END;" 45 | 46 | session.execute(afterDeleteUser) 47 | session.commit() 48 | 49 | 50 | def afterDeleteDeveloper(): 51 | session.execute("DROP TRIGGER IF EXISTS afterDeleteDeveloper") 52 | session.commit() 53 | afterDeleteDeveloper = "CREATE TRIGGER afterDeleteDeveloper before DELETE " \ 54 | "ON Developer FOR EACH ROW " \ 55 | "BEGIN " \ 56 | "DELETE FROM Game WHERE developerID = old.developerID ; " \ 57 | "END;" 58 | 59 | session.execute(afterDeleteDeveloper) 60 | session.commit() 61 | 62 | 63 | def confirmBuy(): # 再confirmGame之后增加关系到user2Game中: 64 | session.execute("DROP TRIGGER IF EXISTS confirmBuy") 65 | session.commit() 66 | confirmBuy = "CREATE TRIGGER confirmBuy after UPDATE " \ 67 | "ON buy FOR EACH ROW " \ 68 | "BEGIN " \ 69 | "IF new.status = 'confirmed' AND NOT EXISTS(SELECT * FROM user2game" \ 70 | " WHERE userID = new.userID AND gameID = new.gameID) THEN " \ 71 | "INSERT INTO user2game(userID,gameID) " \ 72 | "VALUES (new.userID,new.gameID) ;" \ 73 | "end if; " \ 74 | "END;" 75 | 76 | session.execute(confirmBuy) 77 | session.commit() 78 | -------------------------------------------------------------------------------- /sdeam/build/webpack.dev.conf.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | const utils = require('./utils') 3 | const webpack = require('webpack') 4 | const config = require('../config') 5 | const merge = require('webpack-merge') 6 | const path = require('path') 7 | const baseWebpackConfig = require('./webpack.base.conf') 8 | const CopyWebpackPlugin = require('copy-webpack-plugin') 9 | const HtmlWebpackPlugin = require('html-webpack-plugin') 10 | const FriendlyErrorsPlugin = require('friendly-errors-webpack-plugin') 11 | const portfinder = require('portfinder') 12 | 13 | const HOST = process.env.HOST 14 | const PORT = process.env.PORT && Number(process.env.PORT) 15 | 16 | const devWebpackConfig = merge(baseWebpackConfig, { 17 | module: { 18 | rules: utils.styleLoaders({ sourceMap: config.dev.cssSourceMap, usePostCSS: true }) 19 | }, 20 | // cheap-module-eval-source-map is faster for development 21 | devtool: config.dev.devtool, 22 | 23 | // these devServer options should be customized in /config/index.js 24 | devServer: { 25 | clientLogLevel: 'warning', 26 | historyApiFallback: { 27 | rewrites: [ 28 | { from: /.*/, to: path.posix.join(config.dev.assetsPublicPath, 'index.html') }, 29 | ], 30 | }, 31 | hot: true, 32 | contentBase: false, // since we use CopyWebpackPlugin. 33 | compress: true, 34 | host: HOST || config.dev.host, 35 | port: PORT || config.dev.port, 36 | open: config.dev.autoOpenBrowser, 37 | overlay: config.dev.errorOverlay 38 | ? { warnings: false, errors: true } 39 | : false, 40 | publicPath: config.dev.assetsPublicPath, 41 | proxy: config.dev.proxyTable, 42 | quiet: true, // necessary for FriendlyErrorsPlugin 43 | watchOptions: { 44 | poll: config.dev.poll, 45 | } 46 | }, 47 | plugins: [ 48 | new webpack.DefinePlugin({ 49 | 'process.env': require('../config/dev.env') 50 | }), 51 | new webpack.HotModuleReplacementPlugin(), 52 | new webpack.NamedModulesPlugin(), // HMR shows correct file names in console on update. 53 | new webpack.NoEmitOnErrorsPlugin(), 54 | // https://github.com/ampedandwired/html-webpack-plugin 55 | new HtmlWebpackPlugin({ 56 | filename: 'index.html', 57 | template: 'index.html', 58 | inject: true 59 | }), 60 | // copy custom static assets 61 | new CopyWebpackPlugin([ 62 | { 63 | from: path.resolve(__dirname, '../static'), 64 | to: config.dev.assetsSubDirectory, 65 | ignore: ['.*'] 66 | } 67 | ]) 68 | ] 69 | }) 70 | 71 | module.exports = new Promise((resolve, reject) => { 72 | portfinder.basePort = process.env.PORT || config.dev.port 73 | portfinder.getPort((err, port) => { 74 | if (err) { 75 | reject(err) 76 | } else { 77 | // publish the new Port, necessary for e2e tests 78 | process.env.PORT = port 79 | // add port to devServer config 80 | devWebpackConfig.devServer.port = port 81 | 82 | // Add FriendlyErrorsPlugin 83 | devWebpackConfig.plugins.push(new FriendlyErrorsPlugin({ 84 | compilationSuccessInfo: { 85 | messages: [`Your application is running here: http://${devWebpackConfig.devServer.host}:${port}`], 86 | }, 87 | onErrors: config.dev.notifyOnErrors 88 | ? utils.createNotifierCallback() 89 | : undefined 90 | })) 91 | 92 | resolve(devWebpackConfig) 93 | } 94 | }) 95 | }) 96 | -------------------------------------------------------------------------------- /sdeam/src/App.vue: -------------------------------------------------------------------------------- 1 | 84 | 85 | 118 | 119 | 130 | -------------------------------------------------------------------------------- /sdeam/src/components/Store.Vue: -------------------------------------------------------------------------------- 1 | 38 | 39 | 129 | 130 | 162 | -------------------------------------------------------------------------------- /sdeam/src/components/Library.vue: -------------------------------------------------------------------------------- 1 | 48 | 49 | 145 | 146 | 148 | -------------------------------------------------------------------------------- /sdeam/src/components/WishList.vue: -------------------------------------------------------------------------------- 1 | 64 | 65 | 146 | 147 | 149 | -------------------------------------------------------------------------------- /sdeam/src/components/Login.vue: -------------------------------------------------------------------------------- 1 | 61 | 62 | 143 | 144 | 155 | -------------------------------------------------------------------------------- /sdeam/build/webpack.prod.conf.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | const path = require('path') 3 | const utils = require('./utils') 4 | const webpack = require('webpack') 5 | const config = require('../config') 6 | const merge = require('webpack-merge') 7 | const baseWebpackConfig = require('./webpack.base.conf') 8 | const CopyWebpackPlugin = require('copy-webpack-plugin') 9 | const HtmlWebpackPlugin = require('html-webpack-plugin') 10 | const ExtractTextPlugin = require('extract-text-webpack-plugin') 11 | const OptimizeCSSPlugin = require('optimize-css-assets-webpack-plugin') 12 | const UglifyJsPlugin = require('uglifyjs-webpack-plugin') 13 | 14 | const env = require('../config/prod.env') 15 | 16 | const webpackConfig = merge(baseWebpackConfig, { 17 | module: { 18 | rules: utils.styleLoaders({ 19 | sourceMap: config.build.productionSourceMap, 20 | extract: true, 21 | usePostCSS: true 22 | }) 23 | }, 24 | devtool: config.build.productionSourceMap ? config.build.devtool : false, 25 | output: { 26 | path: config.build.assetsRoot, 27 | filename: utils.assetsPath('js/[name].[chunkhash].js'), 28 | chunkFilename: utils.assetsPath('js/[id].[chunkhash].js') 29 | }, 30 | plugins: [ 31 | // http://vuejs.github.io/vue-loader/en/workflow/production.html 32 | new webpack.DefinePlugin({ 33 | 'process.env': env 34 | }), 35 | new UglifyJsPlugin({ 36 | uglifyOptions: { 37 | compress: { 38 | warnings: false 39 | } 40 | }, 41 | sourceMap: config.build.productionSourceMap, 42 | parallel: true 43 | }), 44 | // extract css into its own file 45 | new ExtractTextPlugin({ 46 | filename: utils.assetsPath('css/[name].[contenthash].css'), 47 | // Setting the following option to `false` will not extract CSS from codesplit chunks. 48 | // Their CSS will instead be inserted dynamically with style-loader when the codesplit chunk has been loaded by webpack. 49 | // It's currently set to `true` because we are seeing that sourcemaps are included in the codesplit bundle as well when it's `false`, 50 | // increasing file size: https://github.com/vuejs-templates/webpack/issues/1110 51 | allChunks: true, 52 | }), 53 | // Compress extracted CSS. We are using this plugin so that possible 54 | // duplicated CSS from different components can be deduped. 55 | new OptimizeCSSPlugin({ 56 | cssProcessorOptions: config.build.productionSourceMap 57 | ? { safe: true, map: { inline: false } } 58 | : { safe: true } 59 | }), 60 | // generate dist index.html with correct asset hash for caching. 61 | // you can customize output by editing /index.html 62 | // see https://github.com/ampedandwired/html-webpack-plugin 63 | new HtmlWebpackPlugin({ 64 | filename: config.build.index, 65 | template: 'index.html', 66 | inject: true, 67 | minify: { 68 | removeComments: true, 69 | collapseWhitespace: true, 70 | removeAttributeQuotes: true 71 | // more options: 72 | // https://github.com/kangax/html-minifier#options-quick-reference 73 | }, 74 | // necessary to consistently work with multiple chunks via CommonsChunkPlugin 75 | chunksSortMode: 'dependency' 76 | }), 77 | // keep module.id stable when vendor modules does not change 78 | new webpack.HashedModuleIdsPlugin(), 79 | // enable scope hoisting 80 | new webpack.optimize.ModuleConcatenationPlugin(), 81 | // split vendor js into its own file 82 | new webpack.optimize.CommonsChunkPlugin({ 83 | name: 'vendor', 84 | minChunks (module) { 85 | // any required modules inside node_modules are extracted to vendor 86 | return ( 87 | module.resource && 88 | /\.js$/.test(module.resource) && 89 | module.resource.indexOf( 90 | path.join(__dirname, '../node_modules') 91 | ) === 0 92 | ) 93 | } 94 | }), 95 | // extract webpack runtime and module manifest to its own file in order to 96 | // prevent vendor hash from being updated whenever app bundle is updated 97 | new webpack.optimize.CommonsChunkPlugin({ 98 | name: 'manifest', 99 | minChunks: Infinity 100 | }), 101 | // This instance extracts shared chunks from code splitted chunks and bundles them 102 | // in a separate chunk, similar to the vendor chunk 103 | // see: https://webpack.js.org/plugins/commons-chunk-plugin/#extra-async-commons-chunk 104 | new webpack.optimize.CommonsChunkPlugin({ 105 | name: 'app', 106 | async: 'vendor-async', 107 | children: true, 108 | minChunks: 3 109 | }), 110 | 111 | // copy custom static assets 112 | new CopyWebpackPlugin([ 113 | { 114 | from: path.resolve(__dirname, '../static'), 115 | to: config.build.assetsSubDirectory, 116 | ignore: ['.*'] 117 | } 118 | ]) 119 | ] 120 | }) 121 | 122 | if (config.build.productionGzip) { 123 | const CompressionWebpackPlugin = require('compression-webpack-plugin') 124 | 125 | webpackConfig.plugins.push( 126 | new CompressionWebpackPlugin({ 127 | asset: '[path].gz[query]', 128 | algorithm: 'gzip', 129 | test: new RegExp( 130 | '\\.(' + 131 | config.build.productionGzipExtensions.join('|') + 132 | ')$' 133 | ), 134 | threshold: 10240, 135 | minRatio: 0.8 136 | }) 137 | ) 138 | } 139 | 140 | if (config.build.bundleAnalyzerReport) { 141 | const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin 142 | webpackConfig.plugins.push(new BundleAnalyzerPlugin()) 143 | } 144 | 145 | module.exports = webpackConfig 146 | -------------------------------------------------------------------------------- /sdeam/src/components/Register.vue: -------------------------------------------------------------------------------- 1 | 103 | 104 | 218 | 219 | 221 | -------------------------------------------------------------------------------- /sdeam/src/components/UploadGame.vue: -------------------------------------------------------------------------------- 1 | 113 | 114 | 260 | 261 | 263 | -------------------------------------------------------------------------------- /code_back-end/接口.md: -------------------------------------------------------------------------------- 1 | **全部均为Post** 2 | 3 | 1./userRegister 用户注册 4 | 5 | **Need:** 6 | 7 | userName: string 8 | 9 | password: string 10 | 11 | email: string (可有可无) 12 | 13 | userTel: string(可有可无) 14 | 15 | **return** 16 | 17 | { 18 | 19 | ​ "userID": int 20 | 21 | } 22 | 23 | RepeatName 400 24 | 25 | 26 | 27 | 1.5 /developerRegister 商户注册 28 | 29 | **Need:** 30 | 31 | developerName: string 32 | 33 | password: string 34 | 35 | developerTel: string (可有可无) 36 | 37 | **return** 38 | 39 | { 40 | 41 | ​ "developerID": int 42 | 43 | } 44 | 45 | RepeatName 400 46 | 47 | 48 | 49 | 2./userLogin用户登录 50 | 51 | **Need:** 52 | 53 | userName: string 54 | 55 | userPassword: string 56 | 57 | **return:** 58 | 59 | 成功{ 60 | 61 | userId(int) 62 | 63 | } 64 | 65 | 失败 66 | 67 | NotRegister 400 68 | 69 | WrongPassword 400 70 | 71 | 72 | 73 | 3./developerLogin 用户登录 74 | 75 | **Need:** 76 | 77 | developerName: string 78 | 79 | developerPassword: string 80 | 81 | **return:** 82 | 83 | { 84 | 85 | ​ "developerID": int 86 | 87 | } 88 | 89 | NotRegister 400 90 | 91 | WrongPassword 400 92 | 93 | 94 | 95 | 4./getUserTable 根据用户名返回用户信息 (没有了userType) 96 | 97 | **Need** 98 | 99 | userID cookie 100 | 101 | **return ** json{ 102 | 103 | userName:string 104 | 105 | email: String 106 | 107 | userTel: String, 108 | 109 | userGraph:string 110 | 111 | } 112 | 113 | 114 | 115 | 5./queryUserGames 根据用户名返回用户拥有的游戏信息 116 | 117 | **Need** 118 | 119 | userID: cookie 120 | 121 | **Return** list[ { 122 | 123 | gameName:String 124 | 125 | gamePrice:String 126 | 127 | introduction:String 128 | 129 | gameType:String, 130 | 131 | gameGraph: string, 路径, 132 | 133 | gameID:int, 134 | 135 | gameDetailGraph:string,路径 136 | 137 | }] 138 | 139 | 140 | 141 | 6./uploadGame 开发者上传游戏 142 | 143 | **Need** 144 | 145 | gameName: string 146 | 147 | gamePrice : Int 148 | 149 | introduction: String(可以无) 150 | 151 | gameType: ENUM STRING('action','adventure','cosplay','simulation',relaxation','else') 152 | 153 | gameGraph:str(可以无)图片地址 154 | 155 | gameDetailGraph:str(可以无) 图片地址 156 | 157 | **Return** 158 | 159 | { 160 | 161 | "gameID": int 162 | 163 | } 164 | DeveloperNotExists 400 165 | TypeError 400 166 | 167 | RepeatName 400 168 | 169 | 170 | 171 | 7./createFavorite 添加收藏夹 172 | 173 | **Need** 174 | 175 | favoriteName: string 176 | 177 | userID: cookie 178 | 179 | **Return** 180 | 181 | { 182 | 183 | "favoriteID": int 184 | 185 | } 186 | 187 | RepeatName 400 188 | 189 | 190 | 191 | 8./deleteFavorite 收藏夹删除 192 | 193 | **Need** 194 | 195 | userID:cookie 196 | 197 | favoriteName: String 198 | 199 | **Return**: 200 | 201 | SUCCESS:string 200 202 | 203 | NOT EXIST : 400 204 | 205 | 206 | 207 | 9./ buyGame 添加订单 208 | 209 | **Need** 210 | 211 | userID:cookie 212 | 213 | gameName: String 214 | 215 | **Return** 216 | 217 | 如果成功返回: 218 | 219 | json{ 220 | 221 | "buyID":int , 222 | 223 | "buyTime":str 224 | 225 | } 226 | 227 | 如果不成功返回: 228 | 229 | GAME NOT EXIST ,400 230 | 231 | ALREADY HAVE,400 232 | 233 | 234 | 235 | 10./confirmGame 确认订单 236 | 237 | **Need** 238 | 239 | userID:cookie 240 | 241 | buyID:int 242 | 243 | **return** 244 | 245 | 成功返回: 246 | 247 | "SUCCESS" str 248 | 249 | 失败返回: 250 | 251 | "BUY NOT EIXST":订单不存在 252 | 253 | 254 | 255 | 256 | 257 | 11./deleteBuy 玩家删除订单 258 | 259 | **need:** 260 | 261 | userID:cookie 262 | 263 | gameName: str 264 | 265 | **return** 266 | 267 | success 200 268 | 269 | 270 | 271 | 12./deleteGame 下架游戏 272 | 273 | **need** 274 | 275 | adminID: 可有可无 276 | 277 | gameName: string 278 | 279 | developerID:int 280 | 281 | **return** 282 | 283 | success 200 284 | 285 | 286 | 287 | 13./adminLogin 管理者登录 288 | 289 | **need** 290 | 291 | adminCount string 292 | 293 | adminPassword string 294 | 295 | **return** 296 | 297 | WrongPassword 400 298 | 299 | SUCCESS 200 300 | 301 | 302 | 303 | 304 | 305 | 14./addComment : 添加评论 306 | 307 | **Need** 308 | 309 | grade (Enum int 1,2,3,4,5) 310 | 311 | userID cookies 312 | 313 | gameName str 314 | 315 | commentContents string 316 | 317 | **return** 318 | 319 | **成功返回:** 320 | 321 | { 322 | 323 | ​ “commentID”:int 324 | 325 | } 326 | 327 | REPEAT COMMENT 400(一个用户对一个游戏不能多次评分) 328 | 329 | GameNotExists 400 330 | 331 | UserNotExists 400 332 | 333 | 334 | 335 | 15 /deleteComment :删除评论 336 | 337 | **need** 338 | 339 | userID cookies 340 | 341 | gameName str 342 | 343 | **return** 344 | 345 | success str 346 | 347 | 348 | 349 | 16 /addFavorite: 往favorite里加游戏 350 | 351 | **Need** 352 | 353 | userID cookies 354 | 355 | favoriteName:str 356 | 357 | gameName: string 358 | 359 | **return** 360 | 361 | 成功返回 362 | 363 | "SUCCESS": str 364 | 365 | 失败返回: 366 | ALREADY HAVE,400 367 | 368 | 369 | 370 | 17 /deleteGameFromFavorite: 从收藏夹中删除游戏 371 | 372 | **need** 373 | 374 | userID cookies 375 | 376 | favoriteName:str 377 | 378 | gameName: string 379 | 380 | **return** 381 | 382 | "SUCCESS" 383 | 384 | 385 | 386 | 18 /querySingleFavorite: 查询单个收藏夹 387 | 388 | **need** 389 | 390 | userID cookies 391 | 392 | favoriteName:str 393 | 394 | **return** 395 | 396 | list[{ 397 | 398 | ​ "gameName":, 399 | 400 | ​ "introduction":, 401 | 402 | ​ "gameType":, 403 | 404 | ​ "gamePrice":, 405 | 406 | ​ "gameGraph" 407 | 408 | }] 409 | 410 | 411 | 412 | 19./queryUserFavorite : 根据用户ID查询收藏夹, 413 | 414 | **NEED** 415 | 416 | cookie userID 417 | 418 | **return**: 419 | 420 | list[{ 421 | 422 | ​ “favoriteID”:, 423 | 424 | ​ "favoriteName": 425 | 426 | }] 427 | 428 | 429 | 430 | 20./queryAllGame : 查询所有游戏 431 | 432 | **NEED** 433 | 434 | **RETURN** 435 | 436 | list[{ 437 | 438 | ​ "gameID" : 439 | 440 | ​ "gameName": 441 | 442 | ​ "gameType": 443 | 444 | ​ "gamePrice": 445 | 446 | ​ 'gameGraph': 447 | 448 | }] 449 | 450 | 451 | 452 | 21./developerLogout:开发者登出 453 | 454 | **NEED** 455 | 456 | **RETURN** 457 | 458 | "DELETE SUCCESS" 459 | 460 | 461 | 462 | 22./UserLogout: 用户登出 463 | 464 | **NEED** 465 | 466 | **RETURN** 467 | 468 | "DELETE SUCCESS" 469 | 470 | 471 | 472 | 23./ queryBuy 查询用户订单页面 473 | 474 | **NEED** 475 | 476 | userID: cookie 477 | 478 | **RETURN** 479 | 480 | list[{ 481 | 482 | ​ "gameName":str, 483 | 484 | ​ "gameStatus":str, 485 | 486 | ​ "buyTime":str 487 | 488 | }] 489 | 490 | 491 | 492 | 24./queryGame 查询某个游戏的详情 493 | 494 | **NEED** 495 | 496 | userID:cookie 497 | 498 | gameID: int 499 | 500 | **RETURN** 501 | 502 | 成功: 503 | 504 | { 505 | 506 | ​ "gameName":str, 507 | 508 | ​ "gamePrice":int, 509 | 510 | ​ "introduction":str, 511 | 512 | ​ "gameType":str, 513 | 514 | ​ "developerID": int, 515 | 516 | ​ "gradeAvg":float(平均得分) 517 | 518 | ​ "comments":list[{ 519 | 520 | ​ "comment"str 521 | 522 | ​ "userGraph":str 523 | 524 | ​ "userName":str 525 | 526 | ​ }] 527 | 528 | ​ "gameGraph":str 529 | 530 | } 531 | 532 | 失败: 533 | 534 | "GAME NOT EXIST" 535 | 536 | 537 | 538 | 25./adminLogout: 管理员登出 539 | 540 | **NEED** 541 | 542 | **RETURN** 543 | 544 | "DELETE SUCCESS" 545 | 546 | 547 | 548 | 26./changeUserInfor:改变用户信息: 549 | 550 | **NEED** 551 | 552 | cookie userID 553 | 554 | "userTel" :str可以无 555 | 556 | "userGraph":str,可以无 (图片地址) 557 | 558 | "userPassword":str,可以无 559 | 560 | "email":str,可以无 561 | 562 | "userName":str,可以无 563 | 564 | (建议以上全部返回,如果无则返回给我初始值) 565 | 566 | **RETURN**: 567 | 568 | "SUCCESS",200 569 | 570 | 571 | 572 | 27. /uploadUserGraph:上传用户头像 573 | 574 | **NEED ** 575 | 576 | FileName 'userGraph' 577 | 578 | **RETURN** 579 | 580 | { 581 | 582 | 'userGraphPath':绝对地址 583 | 584 | } 585 | 586 | 587 | 588 | 28/changeGameInfor:改变用户信息: 589 | 590 | **NEED** 591 | 592 | cookie developerID 593 | 594 | "gameID" :int 必有 595 | 596 | "gameName" :str可以无 597 | 598 | "gamePrice":int 可以无 599 | 600 | "introduction":str,可以无 601 | 602 | "gameType":str,可以无 603 | 604 | "gameGraph":str,可以无,游戏图片地址 605 | 606 | (建议以上全部返回,如果无则返回给我初始值) 607 | 608 | **RETURN**: 609 | 610 | SUCCESS : 200 611 | 612 | 613 | 614 | 28.5/uploadGameGraph : 上传游戏图片 615 | 616 | **NEED ** 617 | 618 | FileName 'gameGraph' 619 | 620 | **RETURN** 621 | 622 | { 623 | 624 | 'gameGraphPath':绝对地址 625 | 626 | } 627 | 628 | 629 | 630 | 28.75/uploadGameDetailGraph : 上传游戏图片 631 | 632 | **NEED ** 633 | 634 | FileName 'gameDetailGraph' 635 | 636 | **RETURN** 637 | 638 | { 639 | 640 | 'gameDetailGraphPath':绝对地址 641 | 642 | } 643 | 644 | 645 | 646 | 29./changeDevleoperInfor:改变厂商信息: 647 | 648 | **NEED** 649 | 650 | cookie developerID 651 | 652 | "developerName" :str 可以无 653 | 654 | "developerPassword" :str可以无 655 | 656 | "developerTel":str 可以无 657 | 658 | "developerGraph":str,可以无,图片路径 659 | 660 | (建议以上全部返回,如果无则返回给我初始值) 661 | 662 | **RETURN**: 663 | 664 | developerGraphPath: str,200 665 | 666 | 667 | 668 | 29.5/uploadDeveloperGraph : 上传游戏图片 669 | 670 | **NEED ** 671 | 672 | FileName 'developerGraph' 673 | 674 | **RETURN** 675 | 676 | { 677 | 678 | 'developerGraphPath':绝对地址 679 | 680 | } 681 | 682 | 683 | 684 | 30./deleteUser :管理员删除用户信息 685 | 686 | **NEED** 687 | 688 | cookie adminID 689 | 690 | “userID” int 691 | 692 | **RETURN**: 693 | 694 | "SUCCESS",200 695 | 696 | "USER NOT EXISTS",400 697 | 698 | 699 | 700 | 31./deleteDeveloper:管理员删除开发商信息 701 | 702 | **NEED** 703 | 704 | cookie adminID 705 | 706 | “developerID” int 707 | 708 | **RETURN**: 709 | 710 | "SUCCESS",200 711 | 712 | "DEVELOPER NOT EXISTS",400 713 | 714 | 715 | 716 | 32./adminDeleteComment:管理员删除评论 717 | 718 | **NEED** 719 | 720 | cookie adminID 721 | 722 | “commentID” int 723 | 724 | **RETURN**: 725 | 726 | "SUCCESS",200 727 | 728 | "COMMENT NOT EXISTS",400 729 | 730 | 731 | 732 | 33./queryDeveloperGame:查看开发者上传的所有游戏 733 | 734 | **NEED** 735 | 736 | cookie developerID 737 | 738 | **RETURN**: 739 | 740 | list[ { 741 | 742 | gameName:String 743 | 744 | gamePrice:String 745 | 746 | introduction:String 747 | 748 | gameType:String, 749 | 750 | gameGraph: string, 路径 751 | 752 | }] 753 | 754 | 755 | 756 | 34./queryDeveloper: 查看开发者信息 757 | 758 | **NEED** 759 | 760 | cookie developerID 761 | 762 | **RETURN** 763 | 764 | { 765 | 766 | ​ developerName: 767 | 768 | ​ developerGraph: 769 | 770 | ​ developerTel: 771 | 772 | } -------------------------------------------------------------------------------- /sdeam/src/components/User.vue: -------------------------------------------------------------------------------- 1 | 134 | 135 | 384 | 385 | 387 | -------------------------------------------------------------------------------- /sdeam/src/components/GameDetail.vue: -------------------------------------------------------------------------------- 1 | 184 | 185 | 441 | 442 | 444 | -------------------------------------------------------------------------------- /code_back-end/app.py: -------------------------------------------------------------------------------- 1 | from __future__ import unicode_literals 2 | import os 3 | import time 4 | 5 | from flask import * 6 | from flask_cors import * 7 | from sqlalchemy import and_, event 8 | 9 | from Class.Comment import Comment 10 | from Class.Developer import Developer 11 | from Class.Favorite import Favorite 12 | from Class.Favorite2Game import Favorite2Game 13 | from Class.Game import Game 14 | from Class.User import User 15 | from Class.Buy import Buy 16 | from Class.User2Game import User2Game 17 | from Common import create_token, verify_token 18 | from Mysql import session 19 | from Main import com 20 | 21 | # 配置 22 | app = Flask(__name__) 23 | app.config.from_object(__name__) 24 | CORS(app, supports_credentials=True) 25 | userGraphPath = os.path.join('static', 'User') 26 | gameGraphPath = os.path.join('static', 'Game') 27 | developerGraphPath = os.path.join('static', 'Developer') 28 | 29 | # basepath = os.path.dirname(__file__) 30 | basepath = '../sdeam' 31 | adminCount = "cjbgtcyzm" 32 | adminPassword = "wpbyyds" 33 | 34 | 35 | @app.after_request 36 | def af_request(resp): 37 | """ 38 | #请求钩子,在所有的请求发生后执行,加入headers。 39 | :param resp: 40 | :return: 41 | """ 42 | resp.headers['Access-Control-Allow-Origin'] = 'http://localhost:8080' 43 | resp.headers['Access-Control-Allow-Methods'] = 'GET,POST' 44 | resp.headers['Access-Control-Allow-Headers'] = 'x-requested-with,content-type' 45 | resp.headers['Access-Control-Allow-Credentials'] = 'true' 46 | return resp 47 | 48 | 49 | def getUserID(userName): # 获取用户ID 50 | ans = session.query(User.userID).filter(User.userName == userName).first() 51 | return int(ans[0]) 52 | 53 | 54 | def getDeveloperID(developerName): # 获取DeveloperID 55 | ans = session.query(Developer.developerID).filter(Developer.developerName == developerName).first()[ 56 | 0] 57 | return int(ans) 58 | 59 | 60 | def getGameID(gameName): # 获取GameIqueD 61 | ans = session.query(Game.gameID).filter(Game.gameName == gameName).first()[0] 62 | return int(ans) 63 | 64 | 65 | def gameGradeUpdate(gameID): 66 | commentList = session.query(Comment.grade).filter(Comment.gameID == gameID).all() 67 | gradeSum = 0 68 | number = 0 69 | for i in commentList: 70 | number += 1 71 | gradeSum += float(i[0]) 72 | # 更新平均分 73 | if number == 0: 74 | gradeAvg = 0 75 | else: 76 | gradeAvg = round(float(gradeSum / number), 2) 77 | game = session.query(Game).filter(Game.gameID == gameID).first() # 获取game 78 | game.gradeAvg = gradeAvg 79 | game.update() # 更新游戏评分 80 | 81 | 82 | @app.route('/userRegister', methods=['POST', 'GET']) # 用户注册 done3 83 | def UserRegister(): 84 | if request.method == 'POST': 85 | postForm = json.loads(request.get_data(as_text=True)) 86 | userName = postForm['userName'] 87 | password = postForm['password'] 88 | email = postForm['email'] if 'email' in postForm else None 89 | userTel = postForm['userTel'] if 'userTel' in postForm else None 90 | if not session.query(User).filter(User.userName == userName).all(): # 未注册 91 | user = User(userName=userName, userPassword=password) 92 | if email: 93 | user.email = email 94 | if userTel: 95 | user.userTel = userTel 96 | user.save() 97 | userID = str(user.userID) 98 | return json.dumps({ # 返回json 99 | "userID": int(userID) 100 | }, ensure_ascii=False) 101 | else: 102 | print("name repeat") 103 | return "RepeatName", 400 104 | 105 | 106 | @app.route('/developerRegister', methods=['POST', 'GET']) # 商户注册 done3 107 | def DeveloperRegister(): 108 | if request.method == 'POST': 109 | postForm = json.loads(request.get_data(as_text=True)) 110 | developerName = postForm['developerName'] 111 | password = postForm['password'] 112 | developerTel = postForm['developerTel'] if 'developerTel' in postForm else None 113 | if not session.query(Developer).filter(Developer.developerName == developerName).all(): # 未注册 114 | developer = Developer(developerName=developerName, developerPassword=password) 115 | if developerTel: 116 | developer.developerTel = developerTel 117 | developer.save() 118 | developerID = str(developer.developerID) 119 | return json.dumps({ # 返回json 120 | "developerID": int(developerID) 121 | }, ensure_ascii=False) 122 | else: 123 | print("name repeat") 124 | return "RepeatName", 400 125 | 126 | 127 | @app.route('/userLogin', methods=['POST', 'GET']) # 查询用户表的某个用户 done3 128 | def UserLogin(): 129 | if request.method == 'POST': 130 | postForm = json.loads(request.get_data(as_text=True)) 131 | userName = postForm['userName'] 132 | userPassword = postForm['userPassword'] 133 | if not session.query(User).filter(User.userName == userName).all(): # 未注册 134 | print("NOT REGISTER") 135 | return "NotRegister", 400 # 还未注册 136 | else: 137 | ans = session.query(User.userPassword).filter(User.userName == userName).first() 138 | if ans[0] == userPassword: 139 | userID = getUserID(userName) 140 | if userID not in com.User2Map: 141 | com.Game2Time.clear() 142 | com.User2Map[userID] = com.Game2Time 143 | else: 144 | com.Game2Time = com.User2Map[userID] 145 | # 设置返回 146 | token = create_token(userID) 147 | return json.dumps({ 148 | 'userID': token 149 | }, ensure_ascii=False) 150 | else: 151 | print("WRONG PASSWORD") 152 | return "WrongPassWord", 400 153 | 154 | 155 | @app.route('/changeUserInfor', methods=['POST', 'GET']) # 用户信息更改 done3 156 | def ChangeUserInfor(): 157 | if request.method == 'POST': 158 | # 获取信息 159 | postForm = json.loads(request.get_data(as_text=True)) 160 | userID = postForm['userID'] if 'userID' in postForm else None 161 | if not userID: 162 | "WITHOUT COOKIES", 400 163 | userID = verify_token(userID) 164 | userGraph = postForm['userGraph'] if 'userGraph' in postForm else None 165 | userTel = postForm['userTel'] if 'userTel' in postForm else None 166 | userPassword = postForm['userPassword'] if 'userPassword' in postForm else None 167 | email = postForm['email'] if 'email' in postForm else None 168 | userName = postForm['userName'] if 'userName' in postForm else None 169 | # 图片 170 | user = session.query(User).filter(User.userID == userID).first() 171 | if userGraph: 172 | user.userGraph = userGraph 173 | if userTel: 174 | user.userTel = userTel 175 | if userPassword: 176 | user.userPassword = userPassword 177 | if email: 178 | user.email = email 179 | if userName: 180 | user.userName = userName 181 | user.save() 182 | return "SUCCESS" 183 | 184 | 185 | @app.route('/uploadUserGraph', methods=['POST', 'GET']) # 用户信息更改 done3 186 | def UploadUserGraph(): 187 | if request.method == 'POST': 188 | img = request.files.get('userGraph') 189 | if img: 190 | if not os.path.exists(userGraphPath): 191 | os.makedirs(userGraphPath) 192 | uploadPath = os.path.join(basepath, userGraphPath, (img.filename)) 193 | if os.path.exists(uploadPath): 194 | tmp = (img.filename).split('.') 195 | ticks = time.time() 196 | img.filename = tmp[0] + str(int(ticks)) + '.' + tmp[1] 197 | uploadPath = os.path.join(basepath, userGraphPath, (img.filename)) 198 | img.save(uploadPath) 199 | uploadPath = '.' + uploadPath[8:] 200 | return json.dumps({ 201 | 'userGraphPath': uploadPath 202 | }, ensure_ascii=False) 203 | else: 204 | return "NO GRAPH", 400 205 | 206 | 207 | @app.route('/changeGameInfor', methods=['POST', 'GET']) # 游戏信息更改 done3 208 | def ChangeGameInfor(): 209 | if request.method == 'POST': 210 | # 获取信息 211 | postForm = json.loads(request.get_data(as_text=True)) 212 | developerID = postForm['developerID'] if 'developerID' in postForm else None 213 | if not developerID: 214 | return "WITHOUT COOKIES", 400 215 | developerID = verify_token(developerID) 216 | gameID = postForm['gameID'] if 'gameID' in postForm else None 217 | gameName = postForm['gameName'] if 'gameName' in postForm else None 218 | gamePrice = int(postForm['gamePrice'] if 'gamePrice' in postForm else None) 219 | introduction = postForm['introduction'] if 'introduction' in postForm else None 220 | gameType = postForm['gameType'] if 'gameType' in postForm else None 221 | gameGraph = postForm['gameGraph'] if 'gameGraph' in postForm else None 222 | game = session.query(Game).filter(Game.gameID == gameID).first() 223 | if gameGraph: 224 | game.gameGraph = gameGraph 225 | if gameName: 226 | game.gameName = gameName 227 | if gamePrice: 228 | game.gamePrice = gamePrice 229 | if introduction: 230 | game.introduction = introduction 231 | if gameType: 232 | game.gameType = gameType 233 | game.save() 234 | return "SUCCESS" 235 | 236 | 237 | @app.route('/uploadGameGraph', methods=['POST', 'GET']) # 上传缩略图片 done3 238 | def UploadGameGraph(): 239 | if request.method == 'POST': 240 | img = request.files.get('gameGraph') 241 | if img: 242 | if not os.path.exists(gameGraphPath): 243 | os.makedirs(gameGraphPath) 244 | uploadPath = os.path.join(basepath, gameGraphPath, (img.filename)) 245 | if os.path.exists(uploadPath): 246 | tmp = (img.filename).split('.') 247 | ticks = time.time() 248 | img.filename = tmp[0] + str(int(ticks)) + '.' + tmp[1] 249 | uploadPath = os.path.join(basepath, gameGraphPath, (img.filename)) 250 | img.save(uploadPath) 251 | uploadPath = '.' + uploadPath[8:] 252 | return json.dumps({ 253 | 'gameGraphPath': uploadPath 254 | }, ensure_ascii=False) 255 | else: 256 | return "NO GRAPH", 400 257 | 258 | 259 | @app.route('/uploadGameDetailGraph', methods=['POST', 'GET']) # 上传详细图片 done3 260 | def UploadGameDetailGraph(): 261 | if request.method == 'POST': 262 | img = request.files.get('gameDetailGraph') 263 | if img: 264 | if not os.path.exists(gameGraphPath): 265 | os.makedirs(gameGraphPath) 266 | uploadPath = os.path.join(basepath, gameGraphPath, (img.filename)) 267 | if os.path.exists(uploadPath): 268 | tmp = (img.filename).split('.') 269 | ticks = time.time() 270 | img.filename = tmp[0] + str(int(ticks)) + '.' + tmp[1] 271 | uploadPath = os.path.join(basepath, gameGraphPath, (img.filename)) 272 | img.save(uploadPath) 273 | uploadPath = '.' + uploadPath[8:] 274 | return json.dumps({ 275 | 'gameDetailGraph': uploadPath 276 | }, ensure_ascii=False) 277 | else: 278 | return "NO GRAPH", 400 279 | 280 | 281 | @app.route('/changeDeveloperInfor', methods=['POST', 'GET']) # 游戏信息更改 done3 282 | def ChangeDeveloperInfor(): 283 | if request.method == 'POST': 284 | # 获取信息 285 | postForm = json.loads(request.get_data(as_text=True)) 286 | developerID = postForm['developerID'] if 'developerID' in postForm else None 287 | if not developerID: 288 | return "WITHOUT COOKIES", 400 289 | developerID = verify_token(developerID) 290 | developerName = postForm['developerName'] if 'developerName' in postForm else None 291 | developerPassword = postForm['developerPassword'] if 'developerPassword' in postForm else None 292 | developerTel = postForm['developerTel'] if 'developerTel' in postForm else None 293 | developerGraph = postForm['developerGraph'] if 'developerGraph' in postForm else None 294 | # 295 | developer = session.query(Developer).filter(Developer.developerID == developerID).first() 296 | if developerGraph: 297 | developer.developerGraph = developerGraph 298 | if developerName: 299 | developer.developerName = developerName 300 | if developerPassword: 301 | developer.developerPassword = developerPassword 302 | if developerTel: 303 | developer.developerTel = developerTel 304 | developer.save() 305 | return "SUCCESS", 200 306 | 307 | 308 | @app.route('/uploadDeveloperGraph', methods=['POST', 'GET']) # 用户信息更改 done3 309 | def UploadDeveloperGraph(): 310 | if request.method == 'POST': 311 | img = request.files.get('developerGraph') 312 | if img: 313 | if not os.path.exists(developerGraphPath): 314 | os.makedirs(developerGraphPath) 315 | uploadPath = os.path.join(basepath, developerGraphPath, (img.filename)) 316 | if os.path.exists(uploadPath): 317 | tmp = (img.filename).split('.') 318 | ticks = time.time() 319 | img.filename = tmp[0] + str(int(ticks)) + '.' + tmp[1] 320 | uploadPath = os.path.join(basepath, developerGraphPath, (img.filename)) 321 | img.save(uploadPath) 322 | uploadPath = '.' + uploadPath[8:] 323 | return json.dumps({ 324 | 'developerGraphPath': uploadPath 325 | }, ensure_ascii=False) 326 | else: 327 | return "NO GRAPH", 400 328 | 329 | 330 | @app.route('/developerLogin', methods=['POST', 'GET']) # 查询开发者表的开发者 done 331 | def DeveloperLogin(): 332 | if request.method == 'POST': 333 | postForm = json.loads(request.get_data(as_text=True)) 334 | developerName = postForm['developerName'] 335 | developerPassword = postForm['developerPassword'] 336 | if not session.query(Developer).filter(Developer.developerName == developerName).all(): # 未注册 337 | print("NOT REGISTER") 338 | return "NotRegister", 400 # 还未注册 339 | else: 340 | ans = session.query(Developer.developerPassword).filter(Developer.developerName == developerName).first() 341 | if ans[0] == developerPassword: 342 | developerID = create_token(getDeveloperID(developerName)) 343 | return json.dumps({ 344 | 'developerID': developerID 345 | }, ensure_ascii=False) 346 | else: 347 | print("WRONG PASSWORD") 348 | return "WrongPassWord", 400 349 | 350 | 351 | @app.route('/developerLogout', methods=['POST', 'GET']) # 开发者推出,注销cookie done3 352 | def DeveloperLogout(): 353 | if request.method == 'POST': 354 | resp = make_response("DELETE SUCCESS") 355 | resp.delete_cookie("developerID") 356 | return resp 357 | 358 | 359 | @app.route('/adminLogout', methods=['POST', 'GET']) # 用户登出,注销cookie done3 360 | def AdminLogout(): 361 | if request.method == 'POST': 362 | resp = make_response("DELETE SUCCESS") 363 | resp.delete_cookie("admin") 364 | return resp 365 | 366 | 367 | @app.route('/userLogout', methods=['POST', 'GET']) # 用户登出,注销cookie done3 368 | def UserLogout(): 369 | if request.method == 'POST': 370 | resp = make_response("DELETE SUCCESS") 371 | resp.delete_cookie("userID") 372 | return resp 373 | 374 | 375 | @app.route('/getUserTable', methods=['POST', 'GET']) # 根据ID返回全部用户表内容 done3 376 | def GetUserTable(): 377 | if request.method == 'POST': 378 | postForm = json.loads(request.get_data(as_text=True)) 379 | userID = postForm['userID'] if 'userID' in postForm else None 380 | if not userID: 381 | return 'WITHOUT COOKIES', 400 382 | userID = verify_token(userID) 383 | user = session.query(User).filter(User.userID == userID).first() 384 | ansList = { 385 | 'userName': user.userName, 386 | 'email': user.email, 387 | 'userTel': user.userTel, 388 | 'userGraph': user.userGraph 389 | } 390 | return json.dumps(ansList, ensure_ascii=False); 391 | 392 | 393 | @app.route('/queryDeveloperGames', methods=['POST', 'GET']) # 根据姓名查询游戏报寒 done2 394 | def QueryDeveloperGames(): 395 | if request.method == 'POST': 396 | postForm = json.loads(request.get_data(as_text=True)) 397 | developerID = postForm['developerID'] if 'developerID' in postForm else None 398 | if not developerID: 399 | return 'WITHOUT COOKIES', 400 400 | developerID = verify_token(developerID) 401 | gameList = session.query(Game).filter(Game.developerID == developerID).all() 402 | ans = [] 403 | for i in gameList: 404 | ans.append({ 405 | 'gameName': i.gameName, 406 | 'gamePrice': i.gamePrice, 407 | 'introduction': i.introduction, 408 | 'gameType': i.gameType, 409 | 'gameGraph': i.gameGraph 410 | }) 411 | return json.dumps(ans, ensure_ascii=False) 412 | 413 | 414 | @app.route('/queryUserGames', methods=['POST', 'GET']) # 根据姓名查询游戏报寒 done2 415 | def QueryUserGames(): 416 | if request.method == 'POST': 417 | postForm = json.loads(request.get_data(as_text=True)) 418 | userID = postForm['userID'] if 'userID' in postForm else None 419 | if not userID: 420 | return 'WITHOUT COOKIES', 400 421 | userID = verify_token(userID) 422 | gameList = session.query(Game).filter(and_(User2Game.userID == userID, User2Game.gameID == Game.gameID)).all() 423 | ans = [] 424 | for i in gameList: 425 | ans.append({ 426 | 'gameName': i.gameName, 427 | 'gamePrice': i.gamePrice, 428 | 'introduction': i.introduction, 429 | 'gameType': i.gameType, 430 | 'gameGraph': i.gameGraph, 431 | 'gameID': i.gameID, 432 | 'gameDetailGraph': i.gameDetailGraph 433 | }) 434 | return json.dumps(ans, ensure_ascii=False) 435 | 436 | 437 | @app.route('/uploadGame', methods=['POST', 'GET']) # 上传游戏 done3 438 | def UploadGame(): 439 | if request.method == 'POST': 440 | postForm = json.loads(request.get_data(as_text=True)) 441 | developerID = postForm['developerID'] if 'developerID' in postForm else None 442 | if not developerID: 443 | return "WITHOUT COOKIES", 400 444 | developerID = verify_token(developerID) 445 | gameName = postForm['gameName'] if 'gameName' in postForm else None 446 | gamePrice = postForm['gamePrice'] if 'gamePrice' in postForm else None 447 | introduction = postForm['introduction'] if 'introduction' in postForm else None 448 | gameType = postForm['gameType'] if 'gameType' in postForm else None 449 | gameGraph = postForm['gameGraph'] if 'gameGraph' in postForm else None 450 | gameDetailGraph = postForm['gameDetailGraph'] if 'gameDetailGraph' in postForm else None 451 | 452 | if not developerID: # 不存在这个开发者 453 | return "DeveloperNotExists", 400 454 | elif gameType not in ['action', 'adventure', 'cosplay', 'simulation', 'relaxation', 'else']: 455 | return "TypeError", 400 456 | else: 457 | if not session.query(Game).filter(Game.gameName == gameName).all(): # 未注册 458 | game = Game(gameName=gameName, gamePrice=gamePrice, gameType=gameType, 459 | developerID=developerID) 460 | if introduction: 461 | game.introduction = introduction 462 | if gameGraph: 463 | game.gameGraph = gameGraph 464 | if gameDetailGraph: 465 | game.gameDetailGraph = gameDetailGraph 466 | game.save() 467 | gameID = getGameID(gameName) 468 | return json.dumps({ 469 | "gameID": int(gameID) 470 | }, ensure_ascii=False) # 必须要有return 471 | else: 472 | return "RepeatName", 400 473 | 474 | 475 | @app.route('/createFavorite', methods=['POST', 'GET']) # 用户添加收藏夹 done3 476 | def CreateFavorite(): 477 | if request.method == 'POST': 478 | postForm = json.loads(request.get_data(as_text=True)) 479 | userID = postForm['userID'] if 'userID' in postForm else None 480 | if not userID: 481 | return 'WITHOUT COOKIES', 400 482 | userID = verify_token(userID) 483 | favoriteName = postForm['favoriteName'] 484 | if not session.query(Favorite).filter(Favorite.favoriteName == favoriteName).all(): # 未注册 485 | favorite = Favorite(favoriteName=favoriteName, userID=userID) 486 | favorite.save() # 插入 收藏 487 | favoriteID = favorite.favoriteID 488 | return json.dumps({ 489 | "favoriteID": int(favoriteID) 490 | }, ensure_ascii=False) 491 | else: 492 | return "RepeatName", 400 493 | 494 | 495 | @app.route('/deleteFavorite', methods=['POST', 'GET']) # 删除收藏夹 done3 496 | def DeleteFavorite(): 497 | if request.method == 'POST': 498 | postForm = json.loads(request.get_data(as_text=True)) 499 | userID = postForm['userID'] if 'userID' in postForm else None 500 | if not userID: 501 | return 'WITHOUT COOKIES', 400 502 | userID = verify_token(userID) 503 | postForm = json.loads(request.get_data(as_text=True)) 504 | favoriteName = postForm['favoriteName'] 505 | favorite = session.query(Favorite).filter( 506 | and_(Favorite.favoriteName == favoriteName, Favorite.userID == userID)).first() 507 | if not favorite: 508 | return "NOT EXIST", 400 509 | favorite.delete() 510 | return "SUCCESS" 511 | 512 | 513 | @app.route('/buyGame', methods=['POST', 'GET']) # 添加订单 done3 514 | def BuyGame(): 515 | if request.method == 'POST': 516 | postForm = json.loads(request.get_data(as_text=True)) 517 | userID = postForm['userID'] if 'userID' in postForm else None 518 | if not userID: 519 | return 'WITHOUT COOKIES', 400 520 | userID = verify_token(userID) 521 | gameName = postForm['gameName'] 522 | if not session.query(Game).filter(Game.gameName == gameName).first(): # 游戏不存在 523 | return "NOT EXIST", 400 524 | gameID = getGameID(gameName) 525 | buyTime = str(time.asctime(time.localtime(time.time()))) 526 | status = "unconfirmed" 527 | if session.query(Buy).filter(and_(Buy.gameID == gameID, Buy.userID == userID)).first(): # 已经拥有了 528 | return "ALREADY HAVE", 400 529 | buy = Buy(userID=userID, gameID=gameID, buyTime=buyTime, status=status) 530 | buy.save() 531 | return json.dumps({ 532 | "buyID": int(buy.buyID), 533 | "buyTime": buyTime 534 | }, ensure_ascii=False) 535 | 536 | 537 | @app.route('/confirmGame', methods=['POST', 'GET']) # 确认游戏 done3 538 | def ConfirmGame(): 539 | if request.method == 'POST': 540 | postForm = json.loads(request.get_data(as_text=True)) 541 | userID = postForm['userID'] if 'userID' in postForm else None 542 | if not userID: 543 | return 'WITHOUT COOKIES', 400 544 | userID = verify_token(userID) 545 | buyID = postForm['buyID'] 546 | buy = session.query(Buy).filter(Buy.buyID == buyID).first() # 获取对象 547 | gameID = buy.gameID 548 | if not buy: 549 | return "BUY NOT EXIST", 400 550 | buy.status = 'confirmed' 551 | buy.update() 552 | com.deleteGame(gameID) # 从推荐列表中移除该游戏 553 | return "SUCCESS", 200 554 | 555 | 556 | @app.route('/deleteBuy', methods=['POST', 'GET']) # 玩家删除订单 done3 557 | def DeleteBuy(): 558 | if request.method == 'POST': 559 | postForm = json.loads(request.get_data(as_text=True)) 560 | userID = postForm['userID'] if 'userID' in postForm else None 561 | if not userID: 562 | return 'WITHOUT COOKIES', 400 563 | userID = verify_token(userID) 564 | gameName = postForm['gameName'] 565 | gameID = getGameID(gameName) 566 | buy = session.query(Buy).filter(and_(Buy.userID == userID, Buy.gameID == gameID)).first() 567 | buy.delete() # 直接删除 568 | return "SUCCESS", 200 569 | 570 | 571 | @app.route('/deleteGame', methods=['POST', 'GET']) # 下架游戏 done3 572 | def DeleteGame(): 573 | if request.method == 'POST': 574 | postForm = json.loads(request.get_data(as_text=True)) 575 | developerID = postForm['developerID'] if 'developerID' in postForm else None 576 | if not developerID: 577 | return "WITHOUT COOKIES", 400 578 | developerID = verify_token(developerID) 579 | gameName = postForm['gameName'] 580 | game = session.query(Game).filter(and_(Game.gameName == gameName, Game.developerID == developerID)).first() 581 | if not game: 582 | return "GAME NOT EXISTS", 400 583 | com.deleteGame(game.gameID) 584 | game.delete() 585 | return "SUCCESS", 200 586 | 587 | 588 | @app.route('/adminDeleteGame', methods=['POST', 'GET']) # 下架游戏 done3 589 | def AdminDeleteGame(): 590 | if request.method == 'POST': 591 | postForm = json.loads(request.get_data(as_text=True)) 592 | adminID = postForm['adminID'] if 'adminID' in postForm else None 593 | if not adminID: 594 | return "WITHOUT COOKIES", 400 595 | if int(adminID) != 996251: 596 | return "WRONG ANS", 400 597 | gameID = postForm['gameID'] 598 | game = session.query(Game).filter(Game.gameID == gameID).first() 599 | if not game: 600 | return "GAME NOT EXISTS", 400 601 | com.deleteGame(game.gameID) 602 | game.delete() 603 | return "SUCCESS", 200 604 | 605 | 606 | @app.route('/adminLogin', methods=['POST', 'GET']) # 管理者登录 done 607 | def AdminLogin(): 608 | if request.method == 'POST': 609 | postForm = json.loads(request.get_data(as_text=True)) 610 | getAdminCount = postForm['adminCount'] 611 | getAdminPassword = postForm['adminPassword'] 612 | if (getAdminCount == adminCount) & (getAdminPassword == adminPassword): 613 | return json.dumps({ 614 | 'adminID': 996251 615 | }, ensure_ascii=False) 616 | else: 617 | return "WrongPassword", 400 618 | 619 | 620 | @app.route('/addComment', methods=['POST', 'GET']) # 添加评论 done3 621 | def AddComment(): 622 | if request.method == 'POST': 623 | postForm = json.loads(request.get_data(as_text=True)) 624 | userID = postForm['userID'] if 'userID' in postForm else None 625 | if not userID: 626 | return "WITHOUT COOKIES", 400 627 | userID = verify_token(userID) 628 | gameName = postForm['gameName'] if 'gameName' in postForm else None 629 | gameID = int(getGameID(gameName)) 630 | if not session.query(Game).filter(Game.gameID == gameID).all(): # 游戏不存在 631 | return "GameNotExists", 400 632 | if session.query(Comment).filter(and_(Comment.gameID == gameID), Comment.userID == userID).first(): 633 | return "REPEAT COMMENT", 400 634 | commentTime = str(time.asctime(time.localtime(time.time()))) 635 | grade = str(postForm['grade']) # 只接受整形 636 | commentContents = postForm['commentContents'] 637 | comment = Comment(grade=grade, commentTime=commentTime, gameID=gameID, userID=userID, 638 | commentContents=commentContents) 639 | comment.save() 640 | # 增加1点兴趣 641 | if gameID in com.Game2Time: 642 | com.Game2Time[gameID] += 1 643 | else: 644 | com.Game2Time[gameID] = 1 645 | gameGradeUpdate(gameID) 646 | return json.dumps({ 647 | "commentID": int(comment.commentID) 648 | }, ensure_ascii=False) 649 | 650 | 651 | @app.route('/deleteComment', methods=['POST', 'GET']) # 删除评论 done3 todo优化更新变成触发器 652 | def DeleteComment(): 653 | if request.method == 'POST': 654 | postForm = json.loads(request.get_data(as_text=True)) 655 | userID = postForm['userID'] if 'userID' in postForm else None 656 | if not userID: 657 | return "WITHOUT COOKIES", 400 658 | userID = verify_token(userID) 659 | gameName = postForm['gameName'] 660 | gameID = getGameID(gameName) 661 | comment = session.query(Comment).filter(and_(Comment.gameID == gameID, Comment.userID == userID)).first() 662 | comment.delete() 663 | gameGradeUpdate(gameID) 664 | return "SUCCESS" 665 | 666 | 667 | @app.route('/addFavorite', methods=['POST', 'GET']) # 添加游戏到收藏夹 done3 668 | def AddFavorite(): 669 | if request.method == 'POST': 670 | postForm = json.loads(request.get_data(as_text=True)) 671 | userID = postForm['userID'] if 'userID' in postForm else None 672 | if not userID: 673 | return "WITHOUT COOKIES", 400 674 | userID = verify_token(userID) 675 | favoriteName = postForm['favoriteName'] 676 | gameName = postForm['gameName'] 677 | gameID = getGameID(gameName) 678 | favoriteID = session.query(Favorite.favoriteID).filter( 679 | and_(Favorite.favoriteName == favoriteName, Favorite.userID == userID)) 680 | if session.query(Favorite2Game).filter(and_(Favorite2Game.gameID == gameID), 681 | Favorite2Game.favoriteID == favoriteID).first(): 682 | return "ALREADY HAVE", 400 683 | favorite2game = Favorite2Game(favoriteID=favoriteID, gameID=gameID) 684 | favorite2game.save() 685 | return "SUCCESS" 686 | 687 | 688 | @app.route('/deleteGameFromFavroite', methods=['POST', 'GET']) # 删除收藏 done3 689 | def DeleteGameFromFavroite(): 690 | if request.method == 'POST': 691 | postForm = json.loads(request.get_data(as_text=True)) 692 | userID = postForm['userID'] if 'userID' in postForm else None 693 | if not userID: 694 | return "WITHOUT COOKIES", 400 695 | userID = verify_token(userID) 696 | favoriteName = postForm['favoriteName'] 697 | favoriteID = session.query(Favorite.favoriteID).filter( 698 | and_(Favorite.favoriteName == favoriteName, Favorite.userID == userID)) 699 | gameName = postForm['gameName'] 700 | gameID = getGameID(gameName) 701 | favorite2game = session.query(Favorite2Game).filter( 702 | and_(Favorite2Game.gameID == gameID, Favorite2Game.favoriteID == favoriteID)).first() 703 | favorite2game.delete() 704 | return "SUCCESS" 705 | 706 | 707 | @app.route('/querySingleFavorite', methods=['POST', 'GET']) # 查询单个收藏夹 返回游戏列表 done3 708 | def QuerySingleFavorite(): 709 | if request.method == 'POST': 710 | postForm = json.loads(request.get_data(as_text=True)) 711 | userID = postForm['userID'] if 'userID' in postForm else None 712 | if not userID: 713 | return "WITHOUT COOKIES", 400 714 | userID = verify_token(userID) 715 | favoriteID = postForm['favoriteID'] 716 | ans = [] 717 | gameList = [] # 游戏类列表 718 | gameIDList = session.query(Favorite2Game.gameID).filter(Favorite2Game.favoriteID == favoriteID).all() 719 | for i in gameIDList: 720 | gameList.append(session.query(Game).filter(Game.gameID == i[0]).first()) 721 | for i in gameList: 722 | ans.append({ 723 | 'gameName': i.gameName, 724 | 'introduction': i.introduction, 725 | 'gameType': i.gameType, 726 | 'gamePrice': i.gamePrice, 727 | 'gameGraph': i.gameGraph, 728 | 'gameDetailGraph': i.gameDetailGraph, 729 | 'gameID': i.gameID 730 | }) 731 | return json.dumps(ans, ensure_ascii=False) 732 | 733 | 734 | @app.route('/queryUserFavorite', methods=['POST', 'GET']) # 根据用户ID返回收藏夹信息 done3 735 | def QueryUserFavorite(): 736 | if request.method == 'POST': 737 | postForm = json.loads(request.get_data(as_text=True)) 738 | userID = postForm['userID'] if 'userID' in postForm else None 739 | if not userID: 740 | return "WITHOUT COOKIES", 400 741 | userID = verify_token(userID) 742 | favoriteList = session.query(Favorite).filter(Favorite.userID == userID).all() 743 | ans = [] 744 | for i in favoriteList: 745 | ans.append({ 746 | 'favoriteID': i.favoriteID, 747 | 'favoriteName': i.favoriteName 748 | }) 749 | return json.dumps(ans, ensure_ascii=False) 750 | 751 | 752 | @app.route('/queryAllGame', methods=['POST', 'GET']) # 查询所有游戏信息 done3 753 | def QueryAllGame(): 754 | if request.method == 'POST': 755 | ans = [] 756 | gameList = session.query(Game).all() # 游戏列表 757 | commentList = com.getCommentList() 758 | sumList = [] 759 | for i in commentList: 760 | sumList.append(session.query(Game).filter(Game.gameID == i).first()) 761 | 762 | for i in gameList: 763 | if i.gameID not in commentList: 764 | sumList.append(i) 765 | for i in sumList: 766 | ans.append( 767 | { 768 | "gameID": i.gameID, 769 | "gameName": i.gameName, 770 | "gameType": i.gameType, 771 | "gamePrice": i.gamePrice, 772 | "gameGraph": i.gameGraph 773 | }) 774 | return json.dumps(ans, ensure_ascii=False) 775 | 776 | 777 | @app.route('/queryBuy', methods=['POST', 'GET']) # 查询用户下面的订单 done3 778 | def QueryBuy(): 779 | if request.method == 'POST': 780 | postForm = json.loads(request.get_data(as_text=True)) 781 | userID = postForm['userID'] if 'userID' in postForm else None 782 | if not userID: 783 | return "WITHOUT COOKIES", 400 784 | userID = verify_token(userID) 785 | ans = [] 786 | buyList = session.query(Buy).filter(Buy.userID == userID).all() 787 | for i in buyList: 788 | gameName = session.query(Game.gameName).filter(Game.gameID == i.gameID).first() 789 | ans.append({ 790 | "gameStatus": i.status, 791 | "gameName": gameName, 792 | "buyTime": i.buyTime, 793 | }) 794 | return json.dumps(ans, ensure_ascii=False) 795 | 796 | 797 | @app.route('/queryGame', methods=['POST', 'GET']) # 查询游戏中详细信息(包括评分) done3 798 | def QueryGame(): 799 | if request.method == 'POST': 800 | postForm = json.loads(request.get_data(as_text=True)) 801 | userID = postForm['userID'] if 'userID' in postForm else None 802 | if not userID: 803 | return "WITHOUT COOKIES", 400 804 | userID = verify_token(userID) 805 | gameID = int(postForm['gameID']) 806 | if gameID in com.Game2Time: 807 | com.Game2Time[gameID] = com.Game2Time[gameID] + 1 # 浏览了一次 808 | else: 809 | com.Game2Time[gameID] = 1 810 | game = session.query(Game).filter(Game.gameID == gameID).first() 811 | developerName = \ 812 | session.query(Developer.developerName).filter(Developer.developerID == game.developerID).first()[0] 813 | tmpComments = session.query(Comment).filter(Comment.gameID == gameID).all() 814 | userList = [] 815 | for i in tmpComments: 816 | userList.append(session.query(User).filter(User.userID == i.userID).first()) 817 | comments = [] 818 | for i in range(len(userList)): 819 | comments.append({ 820 | 'userGraph': userList[i].userGraph, 821 | 'userName': userList[i].userName, 822 | 'comment': tmpComments[i].commentContents, 823 | 'commentID': tmpComments[i].commentID 824 | }) 825 | return json.dumps({ 826 | "gameName": game.gameName, 827 | "gamePrice": game.gamePrice, 828 | "introduction": game.introduction, 829 | "gameType": game.gameType, 830 | "developerName": developerName, 831 | "gradeAvg": game.gradeAvg, 832 | "comments": comments, 833 | "gameGraph": game.gameGraph, 834 | "gameDetailGraph": game.gameDetailGraph 835 | }, ensure_ascii=False) 836 | 837 | 838 | @app.route('/deleteUser', methods=['POST', 'GET']) # 管理者删除用户 839 | def DeleteUser(): 840 | if request.method == 'POST': 841 | postForm = json.loads(request.get_data(as_text=True)) 842 | admin = postForm['adminID'] 843 | if not admin: 844 | return "WITHOUT COOKIES", 400 845 | userID = postForm['userID'] 846 | user = session.query(User).filter(User.userID == userID).first() 847 | if not user: 848 | return "USER NOT EXISTS", 400 849 | user.delete() 850 | return "SUCCESS", 200 851 | 852 | 853 | @app.route('/deleteDeveloper', methods=['POST', 'GET']) # 管理者删除游戏厂商 854 | def DeleteDeveloper(): 855 | if request.method == 'POST': 856 | postForm = json.loads(request.get_data(as_text=True)) 857 | admin = postForm['adminID'] 858 | if not admin: 859 | return "WITHOUT COOKIES", 400 860 | developerID = postForm['developerID'] 861 | developerID = verify_token(developerID) 862 | developer = session.query(Developer).filter(Developer.developerID == developerID).first() 863 | if not developer: 864 | return "DEVELOPER NOT EXISTS", 400 865 | developer.delete() 866 | return "SUCCESS", 200 867 | 868 | 869 | @app.route('/adminDeleteComment', methods=['POST', 'GET']) # 管理者删除评论 870 | def AdminDeleteComment(): 871 | if request.method == 'POST': 872 | postForm = json.loads(request.get_data(as_text=True)) 873 | admin = postForm['adminID'] 874 | if not admin: 875 | return "WITHOUT COOKIES", 400 876 | commentID = postForm['commentID'] 877 | comment = session.query(Comment).filter(Comment.commentID == commentID).first() 878 | if not comment: 879 | return "COMMENT NOT EXISTS", 400 880 | comment.delete() 881 | return "SUCCESS", 200 882 | 883 | 884 | @app.route('/queryDeveloper', methods=['POST', 'GET']) # 管理者删除评论 885 | def QueryDeveloper(): 886 | if request.method == 'POST': 887 | postForm = json.loads(request.get_data(as_text=True)) 888 | developerID = postForm['developerID'] 889 | if not developerID: 890 | return "WITHOUT COOKIES", 400 891 | developerID = verify_token(developerID) 892 | developer = session.query(Developer).filter(Developer.developerID == developerID).first() 893 | return json.dumps({ 894 | 'developerName': developer.developerName, 895 | 'developerGraph': developer.developerGraph, 896 | 'developerTel': developer.developerTel 897 | }) 898 | --------------------------------------------------------------------------------