ceshikaoshi/controllers/index.js
2021-09-08 14:46:03 +08:00

97 lines
2.0 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} = 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(fenlei == 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) => {
let q = {}
if(ctx.query.name){
q.mingcheng = ctx.query.name
}
ctx.body = await dbs.find("shop",q)
}
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
}