const cloud = require('wx-server-sdk')
cloud.init({
env: cloud.DYNAMIC_CURRENT_ENV
})
const TcbRouter = require('tcb-router');
const util = require('../../miniprogram/utils/util.js');
const db = cloud.database()
const _ = db.command
exports.main = async (event, context) => {
const app = new TcbRouter({
event
});
app.use(async (ctx,next)=>{
console.log('进入全局中间件')
ctx.data = {}
ctx.data.openId = event.userInfo.openId
await next()
console.log('退出全局中间件',ctx.data.openId)
})
console.log("event".event)
app.router('add', async (ctx, next) => {
try {
return await db.collection('repair_orders').add({
data: {
_openid:ctx.data.openId,
nickName: event.repairer_nickName,
avatarUrl: event.repairer_avatarUrl,
name: event.user_name,
phone: event.user_phone,
faultDetails: event.fault_details,
imgUrl: event.imgUrl,
address: event.address,
deviceName: event.device_name,
isClassing: event.is_classing,
submitdate: new Date(),
status: '已申请待分配',
imgUrlR:'',
step: 1,
staff: '',
staffphone: '',
feedback: '',
}
})
} catch (e) {
console.error(e)
}
await next();
})
app.router('share', async (ctx, next) => {
try {
return await db.collection('repair_orders').doc(event.id).update({
data: {
step: 2,
status: "已分配待维修",
staffName:event.staffName,
sharerOpenid:event.sharerOpenid,
sharerTime:new Date(),
}
})
} catch (e) {
console.error(e)
}
await next();
})
app.router('begin', async (ctx, next) => {
try {
return await db.collection('repair_orders').doc(event.id).update({
data: {
beginTime:new Date(),
step: 3,
status: "正在维修",
}
})
} catch (e) {
console.error(e)
}
await next();
})
app.router('finish', async (ctx, next) => {
try {
return await db.collection('repair_orders').doc(event.id).update({
data: {
feedback: event.feedback,
imgUrlR:event.imgUrlR,
step: 3,
completime:new Date(),
status: "已完成"
}
})
} catch (e) {
console.error(e)
}
await next();
})
return app.serve();
}
看你util是在小程序里,这样写不行,云函数和小程序代码开发是在一个文件夹内,但是部署不在一起,小程序在客户端,云函数是服务端
const util = require('../../miniprogram/utils/util.js');
没有找到这个文件。