```
// 云函数入口文件
const cloud = require('wx-server-sdk')
const TcbRouter = require('tcb-router')
cloud.init()
const db = cloud.database()
// 云函数入口函数
exports.main = async (event, context) => {
const app = new TcbRouter({
event
})
// 添加记录的路由
app.router('add', async (ctx, next) => {
//可以直接调用event
ctx.body = await db.collection('goods').add({
data: {
info: event.info,
address: event.address,
desc: event.desc
}
})
.then((res) => {
return res
})
})
// 获取指定商品信息
app.router('get', async (ctx, next) => {
let _id=event._id
ctx.body = await db.collection('goods').where({
_id
}).get()
.then((res) => {
return res
})
})
// 获取所有商品信息
app.router('getall', async (ctx, next) => {
ctx.body = await db.collection('goods').get()
.then((res) => {
return res
})
})
// 更新商品信息
app.router('updata', async (ctx, next) => {
ctx.body = await db.collection('goods').where({
_id:event._id
}).update({
data:{
info:event.info
}
})
.then((res) => {
return res
})
})
// 删除商品信息
```
app.router('del', async (ctx, next) => {
ctx.body = await db.collection('goods').where({
_id: event._id
}).remove()
.then((res) => {
return res
})
})
return app.serve()
}
```
app.router('del', async (ctx, next) => { ctx.body = await db.collection('goods').where({ _id: event._id }).remove() .then((res) => { return res })})return app.serve()}