index.js 681 B

12345678910111213141516171819202122232425262728293031323334353637
  1. // 云函数入口文件
  2. const cloud = require('wx-server-sdk')
  3. cloud.init()
  4. const db = cloud.database()
  5. // 云函数入口函数
  6. exports.main = async (event, context) => {
  7. const {
  8. OPENID
  9. } = cloud.getWXContext()
  10. const follow_check = await db.collection('follow')
  11. .where({
  12. user_id: OPENID,
  13. pub_id: event.pub_id || ''
  14. })
  15. .get()
  16. if (follow_check.data.length === 0) {
  17. return {
  18. errMsg: '社团组织不存在',
  19. status: 'ERR'
  20. }
  21. }
  22. const follow = await db.collection('follow')
  23. .where({
  24. user_id: OPENID,
  25. pub_id: event.pub_id
  26. })
  27. .remove()
  28. return {
  29. removed: follow.removed,
  30. status: 'OK'
  31. }
  32. }