收藏
回答

我想让他按顺序执行应该怎么做?

首先去activity集合查询sign_in_code为code的记录,返回该记录里的act_id里的值,=》再去activity_sign_up集合里找到act_id和_openid符合条件的记录,=》随后在该记录中插入act_sign_in为1

yzcode:function(e){
    var code = this.data.yzmcode;
    let nowDate= common.formatDate(new Date())
    this.setData({
      nowDate: common.formatDate(new Date())
    })
    //查询code相符的记录,并相符记录的act_id值返回
    wx.cloud.database().collection('activity').where({
      sign_in_code:"code"
    }).get().then(ress => {
      if(ress.data.length==0){
        wx.showToast({
          title: '亲,你输入的验证码错误或未到签到时间',
          duration: 2000,
          icon:'none'
        })
      }
      else{
        this.setData({
          activity_id:ress.data[0].act_id
        })
      }
    })
    //在activity_sign_up中查找activity_id和openid均匹配的记录
    db.collection("activity_sign_up").where({
      activity_id:this.data.activity_id,
      _openid:this.openid
    }).get().then(resss => {
      //在相符的记录中插入sign_in_state:"1",sign_in_time:nowDate,
      db.collection("activity_sign_up").doc(resss.data[0]._id).update({
        data: {
          sign_in_state:"1",
          sign_in_time:nowDate,
        },
        success: res => {
          wx.showToast({
            title: '签到成功!',
          });
          wx.navigateTo({
            url: '/pages/act_sign_in_result/act_sign_in_result?activity_name='+ resss.data[0].activity_name +'&act_id='+ resss.data[0].activity_id+'&name='+ resss.data[0].name+'&bjclass='+ resss.data[0].bjclass+'&time='+nowDate,
          })
        },
        fail: err => {
          wx.showToast({
            title: '签到失败,请刷新重试!',
          })
        }
      })
    })
  },
回答关注问题邀请回答
收藏

2 个回答

  • wang li
    wang li
    2020-12-26

    如楼下正确

    2020-12-26
    有用
    回复
  • i
W
    i W
    2020-12-21

    async / await

    2020-12-21
    有用
    回复
登录 后发表内容
问题标签