收藏
回答

怎么在支付完成后,实现云数据库的更新?

success(res) {
              console.log("支付成功", res)
              const db = wx.cloud.database();
              wx.cloud.callFunction({    // 1 调用云函数获取openid
                name:"getopenid",
                complete:res=>{
                  db.collection("userList").where({
                    openID:res.result.openid   //进行筛选
                  }).get({
                    success:res=>{
                      console.log(res.data.length)
                      if(res.data.length==0){ // 2 判断
                        // 3 (不在) 通过判断data数组长度是否为0来进行下一步的逻辑处理
                        //创建数据库连接
                        const db = wx.cloud.database();
                        db.collection('userList').add({
                          data: {
                          openid: openid,
                          phone: phone,
                          point:point + 450
                          },
                          successres => {
                            wx.showToast({
                              icon'none',
                              title'充值成功'
                            })
                          },
                        })
                      }else{
                        // 在
                        db.doc(openid).update({
                          data:{
                            point: point + 520
                          },
                          success(res){
                            console.log("更新成功", res)
                          },
                          fail(res){
                            console.log("更新失败", res)
                          }
                        })
                      }
                    }
                  })
                }
              })
回答关注问题邀请回答
收藏
登录 后发表内容
问题标签