ceshikaoshi/controllers/index.js
2021-01-08 14:57:38 +08:00

83 lines
1.9 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")
}
module.exports = {
"GET /":index,
"POST /addshop": addshop,
"GET /findshop": findshop
}