const cloud = require('wx-server-sdk')
cloud.init(
{
env: cloud.DYNAMIC_CURRENT_ENV,
}
)
const db = cloud.database();
exports.main = async(event, context) => {
console.log(event)
const wxContext = cloud.getWXContext();
const _id = event._id;
const billData = await db.collection('tb_bill').doc(_id).get();
const bill = billData.data || null;
if (bill && bill.wallet && bill.wallet !== "") {
const tbWallet = db.collection("tb_wallet");
let wallets = await tbWallet.where({
_openid: wxContext.OPENID,
_name: bill.wallet
}).get();
if (wallets.data.length > 0) {
let wallet = wallets.data[0];
let _balance = wallet._balance - bill.money;
let updateRes = await tbWallet.doc(wallet._id).update({
data: {
_balance: _balance
}
});
}
}
return await db.collection('tb_bill').where({
_id: _id
}).remove();
}
不是写得很清楚吗,你docId 传错了吧。要传数据表里面的主键 _id,是不是没传到
_id: _id
}).remove();
_id:_id我改成_id:event._id居然就行了 哈哈
打开云开发云函数的云端测试云函数弹出
appid:wxf5c597e3331406b7