2021-01-08 13:54:22 +08:00
|
|
|
let index = async (ctx,next)=>{
|
2021-01-08 14:57:38 +08:00
|
|
|
ctx.body = "欢迎"
|
|
|
|
}
|
|
|
|
|
|
|
|
let addshop = async (ctx,next)=>{
|
|
|
|
// a = {
|
|
|
|
// mingcheng:"mingzi",
|
|
|
|
// fenlei: 1,
|
|
|
|
// maidian:"lalala",
|
|
|
|
// jiage:12,
|
|
|
|
// huodongjia:10,
|
|
|
|
// kucun:100,
|
|
|
|
// xiaoliang:50,
|
|
|
|
// shangjia:1,
|
|
|
|
// xiangqing:"xiangqing",
|
|
|
|
// }
|
|
|
|
// JSON.stringify(a)
|
|
|
|
// console.log(ctx.request.body)
|
|
|
|
let { mingcheng, fenlei, maidian, jiage, huodongjia, kucun, shangjia ,xiangqing } = ctx.request.body
|
|
|
|
if(mingcheng == undefined){
|
|
|
|
ctx.body = JSON.stringify({
|
|
|
|
code: 1,
|
|
|
|
msg: "名称不能为空"
|
|
|
|
})
|
|
|
|
return ;
|
|
|
|
}
|
|
|
|
if(maidian == undefined){
|
|
|
|
ctx.body = JSON.stringify({
|
|
|
|
code: 1,
|
|
|
|
msg: "卖点不能为空"
|
|
|
|
})
|
|
|
|
return ;
|
|
|
|
}
|
|
|
|
if(jiage == undefined){
|
|
|
|
ctx.body = JSON.stringify({
|
|
|
|
code: 1,
|
|
|
|
msg: "价格不能为空"
|
|
|
|
})
|
|
|
|
return ;
|
|
|
|
}
|
|
|
|
if(huodongjia == undefined){
|
|
|
|
ctx.body = JSON.stringify({
|
|
|
|
code: 1,
|
|
|
|
msg: "活动价格不能为空"
|
|
|
|
})
|
|
|
|
return ;
|
|
|
|
}
|
|
|
|
if(kucun == undefined){
|
|
|
|
ctx.body = JSON.stringify({
|
|
|
|
code: 1,
|
|
|
|
msg: "库存不能为空"
|
|
|
|
})
|
|
|
|
return ;
|
|
|
|
}
|
|
|
|
if(shangjia == undefined){
|
|
|
|
ctx.body = JSON.stringify({
|
|
|
|
code: 1,
|
|
|
|
msg: "是否上架不能为空"
|
|
|
|
})
|
|
|
|
return ;
|
|
|
|
}
|
|
|
|
if(xiangqing == undefined){
|
|
|
|
ctx.body = JSON.stringify({
|
|
|
|
code: 1,
|
|
|
|
msg: "商品详情不能为空"
|
|
|
|
})
|
|
|
|
return ;
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx.body = await dbs.add("shop", ctx.request.body)
|
|
|
|
// ctx.body="添加"
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
let findshop = async (ctx, next) => {
|
|
|
|
ctx.body = await dbs.find("shop")
|
2021-01-08 13:54:22 +08:00
|
|
|
}
|
|
|
|
|
2021-02-24 09:06:18 +08:00
|
|
|
let logins = async(ctx,next)=>{
|
|
|
|
let {user , pwd} = ctx.request.body
|
|
|
|
console.log(123)
|
|
|
|
if(user == "admin" && pwd == "123"){
|
|
|
|
ctx.body = JSON.stringify({
|
|
|
|
code: 200,
|
|
|
|
msg:"登录成功",
|
|
|
|
data:{
|
|
|
|
name:"admin",
|
|
|
|
age:18,
|
|
|
|
quxain: "admin"
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}else{
|
|
|
|
ctx.body = JSON.stringify({
|
|
|
|
code: 200,
|
|
|
|
msg:"登录成功",
|
|
|
|
data:{
|
|
|
|
name:"user",
|
|
|
|
age:18,
|
|
|
|
quxain: "user"
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-08 13:54:22 +08:00
|
|
|
module.exports = {
|
2021-01-08 14:57:38 +08:00
|
|
|
"GET /":index,
|
|
|
|
"POST /addshop": addshop,
|
2021-02-24 09:06:18 +08:00
|
|
|
"GET /findshop": findshop,
|
|
|
|
"POST /login": logins
|
2021-01-08 13:54:22 +08:00
|
|
|
}
|