| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- // 云函数入口文件
- const cloud = require('wx-server-sdk')
- cloud.init()
- const db = cloud.database()
- // 云函数入口函数
- exports.main = async (event, context) => {
- const {
- OPENID
- } = cloud.getWXContext()
- const message_check = await db.collection('message')
- .where({
- _id: event.msg_id || ''
- })
- .get()
- if (message_check.data.length === 0) {
- return {
- errMsg: '信息不存在',
- status: 'ERR'
- }
- }
- const manager_check = await db.collection('manager')
- .where({
- pub_id: message_check.data[0].pub_id,
- user_id: OPENID
- })
- .get()
- if (manager_check.data.length === 0) {
- return {
- errMsg: '只有管理员可以修改',
- status: 'ERR'
- }
- }
- if (event.type === '纳新') {
- const publisher = await db.collection('publisher')
- .doc(message_check.data[0].pub_id)
- .get()
- event.type = publisher.data.type + '纳新'
- }
- const message = await db.collection('message')
- .doc(event.msg_id)
- .update({
- data: {
- 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,
- link: event.link
- }
- })
- const favorites = await db.collection('favorite')
- .where({
- msg_id: event.msg_id
- })
- .get()
- const notifications = []
- for (let i = 0; i < favorites.data.length; i++) {
- notifications.push({
- user_id: favorites.data[i].user_id,
- msg_id: favorites.data[i].msg_id,
- type: '动态',
- content: event.notification || '',
- nofity_time: new Date()
- })
- }
- await db.collection('notification')
- .add({
- data: notifications
- })
- return {
- stats: message.stats,
- status: 'OK'
- }
- }
|