// 云函数入口文件 const cloud = require('wx-server-sdk') cloud.init() const db = cloud.database() // 云函数入口函数 exports.main = async (event, context) => { let { OPENID } = cloud.getWXContext() const manage_check = await db.collection('manager').where({ pub_id: event.pub_id, user_id: OPENID }).get() if (manage_check.data.length === 0) { return { errMsg: '只有管理员可以发布' } } if (manage_check.data[0].role !== '拥有者' && manage_check.data[0].role !== '发布者') { return { errMsg: '没有发布权限' } } if (!event.type) { const publisher = await db.collection('publisher').doc(event.pub_id).get() event.type = publisher.data.type + '纳新' } const message = await db.collection('message').add({ data: { pub_id: event.pub_id, user_id: OPENID, name: event.name, type: event.type, brief: event.brief, poster: event.poster, photo: event.photo, tag: event.tag, orient: event.orient, time: event.time, place: event.place, contact: event.contact, detail: event.detail, publish_time: new Date() } }) return message }