多表更新怎么写?为什么会报错
- 需求的场景描述(希望解决的问题)
发布产品时需要消耗个人积分,所以需要在个人表中更新,扣除积分成功才会在清单表中记录,否则删除刚才的产品发布记录
let $result = { bool: false, message: '提交失败!'};try{ await db.collection('Goods').add({ data: e.iData }).then(res => { await db.collection('Users').doc(id).update({ data: { _goods: _.unshift(res._id), _scores: _.inc(-$cost) } }).then(res => { await db.collection('Score').doc(id).update({ data: { _history: _.unshift({ _type: '支出', _scores: -$cost, _date: db.serverDate() }) } }).then(res => { $result.bool = true; $result.message = '提交成功!'; }) }).catch(err => { await db.collection('Goods').doc(res._id).remove(); }) });}catch(err){ console.log(err);}finally{ return $result;} |
- 希望提供的能力
怎么样写才不会报错?
