Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
本次更新依赖的数据库与服务器!
  • Loading branch information
Json-WJK authored Oct 31, 2018
1 parent 48a9c50 commit 7735233
Show file tree
Hide file tree
Showing 6 changed files with 222 additions and 22 deletions.
14 changes: 7 additions & 7 deletions mysql/game.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
SET NAMES UTF8;
USE zhw;


#游戏账号分类
DROP TABLE IF EXISTS zhw_game_classify;
CREATE TABLE zhw_game_classify(
Expand Down Expand Up @@ -247,6 +245,7 @@ INSERT INTO zhw_game_gallery VALUES
(null,2,"zuhao/5bbb7e6aa14e1.png","zuhao/5bbb7e6aa14e1.png","zuhao/5bbb7e6aa14e1.png"),
(null,2,"zuhao/5bbb7e619b0ef.png","zuhao/5bbb7e619b0ef.png","zuhao/5bbb7e619b0ef.png");

#租金情况表
DROP TABLE IF EXISTS zhw_game_details;
CREATE TABLE zhw_game_details(
details_id INT PRIMARY KEY AUTO_INCREMENT,
Expand All @@ -262,10 +261,11 @@ CREATE TABLE zhw_game_details(
night Decimal(10,2),#包夜
hours Decimal(10,2),#10小时
week Decimal(10,2),#周租
hire INT#押金
hire INT,#押金
game_name VARCHAR(128)
);
INSERT INTO zhw_game_details VALUES
(1,1,1003,"绝地求生☆包天包夜10小时最低价★到时不下线 ★吃鸡",173,180,"绝地求生/全区/全服","1.20","7.70","3.40","4.70","5.70","28.70",1),
(null,2,1001,"370V160全王,全交易所,炫金毁灭,雷神/7幻兽,雅典娜",963,1137,"穿越火线/电信区/江苏一区 ","2.20","29.60","6.50","10.70","19.10","147.20",5),
(null,3,1005,"【给密码】贵8❤199皮肤30页铭文❤星空梦想海洋全史诗限定",1803,2113,"王者荣耀/安卓系统/QQ账号","12.00","200.00","30.00","45.00","90.20","700.20",10),
(null,4,1002,"1050皮丨全年限丨龙瞎丨摄魂vn恐惧諾手丨金靴瞎丨新泳池套",120,215,"英雄联盟/电信/黑色玫瑰","4.80","85.20","20.20","36.20","43.20","499.20",3);
(1,1,1003,"绝地求生☆包天包夜10小时最低价★到时不下线 ★吃鸡",173,180,"绝地求生/全区/全服","1.20","7.70","3.40","4.70","5.70","28.70",1,"ace8122"),
(null,2,1001,"370V160全王,全交易所,炫金毁灭,雷神/7幻兽,雅典娜",963,1137,"穿越火线/电信区/江苏一区 ","2.20","29.60","6.50","10.70","19.10","147.20",5,"晚秋的尘封"),
(null,3,1005,"【给密码】贵8❤199皮肤30页铭文❤星空梦想海洋全史诗限定",1803,2113,"王者荣耀/安卓系统/QQ账号","12.00","200.00","30.00","45.00","90.20","700.20",10,"夜太美"),
(null,4,1002,"1050皮丨全年限丨龙瞎丨摄魂vn恐惧諾手丨金靴瞎丨新泳池套",120,215,"英雄联盟/电信/黑色玫瑰","4.80","85.20","20.20","36.20","43.20","499.20",3,"不能开口的再见");
15 changes: 15 additions & 0 deletions mysql/lease.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
SET NAMES UTF8;
USE zhw;
/*订单状态表(是否被租用,,,,,租用剩余时间 租用账号的用户)*/
DROP TABLE IF EXISTS zhw_lease;
CREATE TABLE zhw_lease(
lease_id INT PRIMARY KEY AUTO_INCREMENT,
uid INT,
game_id INT,
starting_date datetime,#起始时间
duration INT #租用时长
);
INSERT INTO zhw_lease VALUES
(1,1,1,"2018-10-31 23:50:00",1),
(2,1,2,"2018-10-31 23:50:00",2);

12 changes: 9 additions & 3 deletions mysql/user.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,19 @@ SET NAMES UTF8;
DROP DATABASE IF EXISTS zhw;
CREATE DATABASE zhw CHARSET=UTF8;
USE zhw;
#用户信息表
DROP TABLE IF EXISTS zhw_user;
CREATE TABLE zhw_user(
uid INT PRIMARY KEY AUTO_INCREMENT,
uname VARCHAR(32),
uname VARCHAR(32),#账号
upwd VARCHAR(32),
phone VARCHAR(32),
avatar VARCHAR(128),
gender INT
gender INT,
nickname VARCHAR(32),#名称
balance Decimal(10,2),#可用余额
freeze Decimal(10,2),#不可用余额
redPacket Decimal(10,2),#红包
frequency INT#租号次数
);
INSERT INTO zhw_user VALUES(1,"920819994","18696052995","18696052995",null,1);
INSERT INTO zhw_user VALUES(1,"920819994","18696052995","18696052995",null,1,"后台账号","9999.99","9999.99","0.00",2);
37 changes: 33 additions & 4 deletions routes/account-detail.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const express=require("express")
const router=express.Router()
const pool=require("../pool")

/*根据点击的账号id查询账号详情 */
/*根据点击的账号id查询账号图片 */
router.get('/gamegallery',(req,res)=>{
var game_id=req.query.game_id;
var sql="SELECT * FROM zhw_game_gallery where game_id=?"
Expand All @@ -15,11 +15,13 @@ router.get('/gamegallery',(req,res)=>{
})
res.write(JSON.stringify(result));
res.end();

})
})

/*根据点击的账号id查询账号详情 */
router.get('/details',(req,res)=>{
var game_id=req.query.game_id;
var $date=req.query.date;
var sql="SELECT * FROM zhw_game_details where game_id=?"
pool.query(sql,[game_id],(err,result)=>{
if(err) console.log(err);
Expand All @@ -29,8 +31,35 @@ router.get('/details',(req,res)=>{
})
res.write(JSON.stringify(result));
res.end();
console.log(" "+$date+" 有人刚才查看了"+game_id+"号游戏账号");
})
})
/*查询当前账号剩余时间 */
router.get('/lease',(req,res)=>{
var game_id=req.query.game_id;
var sql="SELECT * FROM zhw_lease where game_id=?"
pool.query(sql,[game_id],(err,result)=>{
if(err) console.log(err);
res.writeHead(200,{
"Content-Type":"application/json;charset=utf-8",
"Access-Control-Allow-Origin":"*"
})
res.write(JSON.stringify(result));
res.end();
})
})
/*删除到期账号*/
router.get('/remove',(req,res)=>{
var game_id=req.query.game_id;
var sql="DELETE FROM zhw_lease WHERE game_id=?"
pool.query(sql,[game_id],(err,result)=>{
if(err) console.log(err);
res.writeHead(200,{
"Content-Type":"application/json;charset=utf-8",
"Access-Control-Allow-Origin":"*"
})
console.log(" "+game_id+"号商铺租用时长到期,已重新上架!")
res.end();
})
})


module.exports=router;
64 changes: 64 additions & 0 deletions routes/order.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
const express=require("express")
const router=express.Router()
const pool=require("../pool")

/*选择租用方式 确认租号 */
router.post("/affirm",(req,res)=>{
var game_id=req.body.game_id;
var $date=req.body.date;
var sql="SELECT *,(select game_overall_img from zhw_game_account where game_id=?) as game_overall_img,(select game_starting from zhw_game_account where game_id=?) as game_starting FROM zhw_game_details where game_id=?"
pool.query(sql,[game_id,game_id,game_id],(err,result)=>{
if(err) console.log(err);
//res.send(result);
res.writeHead(200,{
"Content-Type":"application/json;charset=utf-8",
"Access-Control-Allow-Origin":"*"
})
res.write(JSON.stringify(result));
res.end();
console.log(" "+$date+" 有人正在尝试租用"+game_id+"号游戏账号");
})
})

/*租号成功 */
router.post("/add",(req,res)=>{
console.log(req.body.DateTime)
var $date=req.body.dates;
var game_id=req.body.game_id;
var uname=req.body.uname;
var myDate=req.body.DateTime;
var duration=req.body.duration;
console.log(myDate)
var sql="INSERT INTO zhw_lease (game_id,uid,starting_date,duration) values(?,(select uid from zhw_user where uname=?),?,?)";
pool.query(sql,[game_id,uname,myDate,duration],(err,result)=>{
if(err) console.log(err);
//res.send(result);
res.writeHead(200,{
"Content-Type":"application/json;charset=utf-8",
"Access-Control-Allow-Origin":"*"
})
res.write(JSON.stringify(result));
res.end();
console.log(" "+$date+" "+uname+"租用了"+game_id+"号游戏账号");
})
})
/*租号完成 扣费 */
router.post("/fee",(req,res)=>{
var $down=req.body.down;
var $uname=req.body.uname;
var $date=req.body.date;
var sql="update zhw_user set balance=balance-? where uname=?";
pool.query(sql,[$down,$uname],(err,result)=>{
if(err) console.log(err);
res.writeHead(200,{
"Content-Type":"application/json;charset=utf-8",
"Access-Control-Allow-Origin":"*"
})
res.write(JSON.stringify(result));
res.end();
console.log(" "+$date+" 从"+$uname+"账户扣除了"+$down+"元");
})
})


module.exports=router;
102 changes: 94 additions & 8 deletions routes/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ const express=require('express');
const pool=require('../pool.js');
//创建路由器
var router=express.Router();
//用户注册


//用户登录
router.post('/login',(req,res)=>{
var uname=req.body.uname;
var upwd=req.body.upwd;
console.log(uname,upwd);
var $date=req.body.date;
pool.query(
"select * from zhw_user where uname=? and upwd=?",
[uname,upwd],
Expand All @@ -22,13 +22,15 @@ router.post('/login',(req,res)=>{
res.write(JSON.stringify({
ok:1,
msg:"登录成功!"
}))
}))
console.log(" "+$date+" "+uname+"刚刚登录平台...");
}else{
res.write(JSON.stringify({
ok:0,
msg:"用户名或密码错误!"
}))
}
}

res.end();
}
)
Expand All @@ -53,12 +55,15 @@ router.get("/islogin",(req,res)=>{
})
}
})

/*退出登录 */
router.get("/signout",(req,res)=>{
req.session["uid"]=undefined;
console.log(" "+"一位用户悄悄离开了平台")
res.end();
})


//用户注册
router.post('/register',(req,res)=>{
var obj=req.body;
var $uname=obj.uname;
Expand All @@ -71,8 +76,7 @@ router.post('/register',(req,res)=>{
res.send("密码不能为空")
return;
}

var sql='INSERT INTO zhw_user VALUES(null,?,?,null,null,null)';
var sql='INSERT INTO zhw_user VALUES(null,?,?,null,1,null,null,0,0,0,0)';
pool.query(sql,[$uname,$upwd],(err,result)=>{
if(err) throw err;
if(result.affectedRows>0){
Expand All @@ -90,7 +94,6 @@ router.post('/verify',(req,res)=>{
var sql='SELECT * FROM zhw_user where uname=?';
pool.query(sql,[$uname],(err,result)=>{
if(err) throw err;
console.log(result);
if(result.length>0){
res.send("1");
}else{
Expand All @@ -100,4 +103,87 @@ router.post('/verify',(req,res)=>{
});
});

/*用户信息 */
router.post("/data",(req,res)=>{
var $uname=req.body.uname;
console.log($uname)
var sql="SELECT * FROM zhw_user where uname=?";
pool.query(sql,[$uname],(err,result)=>{
if(err) throw err;
res.writeHead(200,{
"Content-Type":"application/json;charset=utf-8",
"Access-Control-Allow-Origin":"*"
})
res.write(JSON.stringify(result));
res.end();
})
})

/*账户充值 */
router.post("/recharge",(req,res)=>{
var $up=req.body.up;
var $uname=req.body.uname;
var $date=req.body.date;
var sql="update zhw_user set balance=balance+? where uname=?";
pool.query(sql,[$up,$uname],(err,result)=>{
if(err) console.log(err);
res.writeHead(200,{
"Content-Type":"application/json;charset=utf-8",
"Access-Control-Allow-Origin":"*"
})
res.write(JSON.stringify(result));
res.end();
console.log(" "+$date+" "+$uname+"充值了"+$up+"元");
})
})

/*用户租过的订单 */
router.post("/lease",(req,res)=>{
var $uname=req.body.uname;
var $date=req.body.date;
var output={name:{},account:{}};
var sql1="SELECT game_name FROM zhw_game_details where game_id IN (SELECT game_id FROM zhw_lease where uid=(SELECT uid FROM zhw_user where uname=?))";
var sql2="SELECT * FROM zhw_game_account where game_id IN (SELECT game_id FROM zhw_lease where uid=(SELECT uid FROM zhw_user where uname=?))";
Promise.all([
new Promise(function(open){
pool.query(sql1,[$uname],(err,result)=>{
if(err) console.log(err);
output.name=result;
open();
})
}),
new Promise(function(open){
pool.query(sql2,[$uname],(err,result)=>{
if(err) console.log(err);
output.account=result;
open();
})
})
]).then(function(){
res.writeHead(200,{
"Content-Type":"application/json;charset=utf-8",
"Access-Control-Allow-Origin":"*"
})
res.write(JSON.stringify(output));
res.end();
console.log(" "+$date+" "+$uname+"刚刚查看了自己的资料!");
})
})
/*用户租过的订单 */
// router.post("/lease",(req,res)=>{
// var $uname=req.body.uname;
// /*备注一下这个sql语句 通过uname查找uid 再通过uid查找game_id 再通过game_id查找game_name和账号详情*/
// var sql="SELECT *,(SELECT game_name FROM zhw_game_details where game_id=(SELECT game_id FROM zhw_lease where uid=(SELECT uid FROM zhw_user where uname=920819994))) as game_name FROM zhw_game_account where game_id=(SELECT game_id FROM zhw_lease where uid=(SELECT uid FROM zhw_user where uname=920819994))";
// var sql="SELECT *,game_name FROM zhw_game_details WHERE game_id IN ( SELECT game_id FROM zhw_lease WHERE uid = ( SELECT uid FROM zhw_user WHERE uname = ? ) )";
// pool.query(sql,[$uname,$uname],(err,result)=>{
// if(err) throw err;
// res.writeHead(200,{
// "Content-Type":"application/json;charset=utf-8",
// "Access-Control-Allow-Origin":"*"
// })
// res.write(JSON.stringify(result));
// res.end();
// })
// })

module.exports=router;

0 comments on commit 7735233

Please sign in to comment.