110 lines
2.5 KiB
JavaScript
110 lines
2.5 KiB
JavaScript
let index = async (ctx,next)=>{
|
|
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")
|
|
}
|
|
|
|
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"
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
module.exports = {
|
|
"GET /":index,
|
|
"POST /addshop": addshop,
|
|
"GET /findshop": findshop,
|
|
"POST /login": logins
|
|
} |