ceshikaoshi/controllers/index.js

97 lines
2.0 KiB
JavaScript
Raw Normal View History

2021-01-08 05:54:22 +00:00
let index = async (ctx,next)=>{
2021-01-08 06:57:38 +00: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)
2021-09-08 06:46:03 +00:00
let { mingcheng, fenlei, maidian, jiage} = ctx.request.body
2021-01-08 06:57:38 +00:00
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 ;
}
2021-09-08 06:46:03 +00:00
if(fenlei == undefined){
2021-01-08 06:57:38 +00:00
ctx.body = JSON.stringify({
code: 1,
2021-09-08 06:46:03 +00:00
msg: "分类不能为空"
2021-01-08 06:57:38 +00:00
})
return ;
}
2021-09-08 06:46:03 +00:00
2021-01-08 06:57:38 +00:00
ctx.body = await dbs.add("shop", ctx.request.body)
// ctx.body="添加"
}
let findshop = async (ctx, next) => {
2021-04-16 06:04:01 +00:00
let q = {}
if(ctx.query.name){
q.mingcheng = ctx.query.name
}
ctx.body = await dbs.find("shop",q)
2021-01-08 05:54:22 +00:00
}
2021-04-16 06:04:01 +00:00
2021-02-24 01:06:18 +00: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 05:54:22 +00:00
module.exports = {
2021-01-08 06:57:38 +00:00
"GET /":index,
"POST /addshop": addshop,
2021-02-24 01:06:18 +00:00
"GET /findshop": findshop,
"POST /login": logins
2021-01-08 05:54:22 +00:00
}