const db = uniCloud.database(); const _ = db.command; module.exports = { _before: function () { // 通用预处理器 }, async getIsFollow(query) { try { const { uid, fid } = query; let isFollow = false; console.log(uid) console.log(fid) const res = await db.collection("follow").where({ uid: uid, fid: fid }) .count(); console.log(res.total); if (res.total > 0) { isFollow = true; } return { code: 200, isFollow: isFollow } } catch(e) { return { code: 500, msg: e.message } } }, async follow(query) { try { const { uid, fid } = query; const res = await db.collection("follow").where({ uid: uid, fid: fid }).count(); if (res.total > 0) { return { code: 201, msg: "已关注" } } else { let dateTime = new Date(); const add_res = await db.collection("follow").add({ uid: uid, fid: fid, create_time: dateTime }) console.log(add_res) return { code: 200, data: add_res } } } catch(e) { return { code: 500, msg: e.message } } }, async reFollow(query) { try { const { uid, fid } = query; const res = await db.collection("follow").where({ uid: uid, fid: fid }).count(); if (res.total < 0) { return { code: 201, msg: "未关注" } } else { const re_res = await db.collection("follow").where({ uid: uid, fid: fid }).remove(); console.log(re_res) return { code: 200, data: re_res } } } catch(e) { return { code: 500, msg: e.message } } } }