3 回复
const wxContext = cloud.getWXContext() let user = db.collection( 'user' ) let {total} = await new Promise( (resolve, reject)=>{ user.where({ _openid: wxContext.OPENID }).count().then( res=>{ resolve(res) }) }) let data = { _openid: wxContext.OPENID, updateDate: new Date().getTime(), ...event, } if ( total == 0 ){ data.createDate = new Date().getTime() return await user.add({ data }).then( res=>{ console.log( '新增成功->' , res) return res }). catch ( err=>{ console.log( '新增失败' ,err) }) } else { return await user.where({ _openid: wxContext.OPENID }).update({ data }).then( res=>{ console.log( '更新成功->' , res) return res }). catch ( err=>{ console.log( '更新失败' ,err) }) } |
这样写优雅吗?