| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- // 云函数入口文件
- const cloud = require('wx-server-sdk')
- cloud.init()
- const db = cloud.database()
- // 云函数入口函数
- exports.main = async (event, context) => {
- const {
- OPENID
- } = cloud.getWXContext()
- const question_check = await db.collection('question')
- .where({
- _id: event.que_id || ''
- })
- .get()
- if (question_check.data.length === 0) {
- return {
- errMsg: '提问不存在',
- status: 'ERR'
- }
- }
- const manager_check = await db.collection('question')
- .aggregate()
- .match({
- _id: event.que_id
- })
- .lookup({
- from: 'message',
- localField: 'msg_id',
- foreignField: '_id',
- as: 'message'
- })
- .unwind('$message')
- .lookup({
- from: 'manager',
- localField: 'message.pub_id',
- foreignField: 'pub_id',
- as: 'manager'
- })
- .unwind('$manager')
- .match({
- 'manager.user_id': OPENID
- })
- .end()
- if (manager_check.list.length === 0 && !(question_check.data[0].user_id === OPENID && question_check[0].answer === '')) {
- return {
- errMsg: '只有管理员可以删除',
- status: 'ERR'
- }
- }
- const question = await db.collection('question')
- .doc(event.que_id)
- .remove()
- return {
- removed: question.removed,
- status: 'OK'
- }
- }
|