大佬們幫我看看轨香,我小程序開發(fā)忽你,從checkResul函數(shù)開始,在里面調(diào)用不了聲明在下面的函數(shù)臂容,數(shù)據(jù)庫權(quán)限是所以人可讀科雳,假如注釋掉updateMyCount函數(shù)就會執(zhí)行到if(0==sam)的打印sam=0就停了,哭了嗚嗚嗚
// pages/last/last.js
var util = require('../../utils/util.js');//用于時間
//const $ = db.command.aggregate
const app = getApp();//獲取全局對象userInfo={}
const db = wx.cloud.database();//引入數(shù)據(jù)庫
var myDate;
var time;
var wxNum;
var place;
var age;
var hopeSex;
var samOrDiffCity;
Page({
? data: {
? ? myJoinId:'', //報名參加創(chuàng)建join時自己的id
? ? youSex:'',
? ? wxNum: '',
? ? age: '',
? ? place:'',
? ? hopeSex:'',
? ? samOrDiffCity:'',?
? ? sam: 0 ,
? ? myCount: 0,
? ? myActWxNum: '',
? ? myActAge: ''
? },
? handleInputWxNum: function (e) {
? ? wxNum=e.detail.value
? },
? handleInputPlace: function (e) {
? ? place= e.detail.value
? },
? inputAge: function(age){
? ? age=age.detail.value
? },
? radioGroupSex: function (sex) {
? ? hopeSex= sex.detail.value
? },
? radioGroupCity: function (city) {
? ? samOrDiffCity= city.detail.value
? },
? addData: function(){
? db.collection('join').add({
? ? data: {
? ? ? wxNum: this.data.wxNum,
? ? ? place: this.data.place,
? ? ? hopeSex: this.data.hopeSex,
? ? ? samOrDiffCity: this.data.samOrDiffCity,
? ? ? age: this.data.age,
? ? ? sam:0,
? ? ? myCount:0,
? ? }
? }).then((res) => {
? ? var myJoinId = res._id;
? this.setData({
? ? myJoinId: myJoinId
? })
? ? wx.showToast({
? ? ? title: '報名成功E肌糟秘!'
? ? })
? })
},
checkResult: function(){
? myDate = new Date();
? time = myDate.getDay();//獲取今天星期幾
if(time==5){
? updateMyCount();
? db.collection('join').doc(this.data.myJoinId).get().then(()=>{
? ? var sam=res.data.sam;
? ? ? if (0==sam){
? ? ? ? whereData();
? ? ? ? removeMyJoin();
? ? ? ? wx.redirectTo({
? ? ? ? ? url: '../result/result'
? ? ? ? })
? ? ? }
}
? ? else{
? ? ? wx.redirectTo({
? ? ? ? url: '../waitResult/waitResult'
? ? ? })
? ? }
},
updateMyCount: function(){
? var myJoinId = this.data.myJoinId;
? db.collection('join').doc(myJoinId).update({
? ? data: {
? ? ? myCount: 1
? ? },
? }).then((res)=>{console.log('updateMyCount 調(diào)用成功')})
},
lookMyJoin: function () {
? db.collection('join').doc(this.data.myJoinId).get().then((res) => {
? ? console.log('i am sam=1,succsee to get myself join record', res);
? ? getApp().globalData2.resulted = res.data.myActWxNum;
? ? getApp().globalData2.resulted = res.data.myActAge;
? })
},
whereData: function () {
? db.collection('join').where({
? ? sam: 0,
? ? myCount: 0,
? ? hopeSex:this.data.youSex
? }).get().then((res) => {
? ? ? console.log('succeed to where get data :', res.data);
? ? ? getApp().globalData.result = res.data[0];
? ? ? var youId = res.data[0]._id;
? ? ? console.log('var youId=', youId);
? ? ? updateYourJoin(youId);
? ? })
},
updateYourJoin: function () {
? db.collection('join').doc(youId).update({
? ? data: {
? ? ? sam: 1,
? ? ? myActWxNum: that.data.wxNum,
? ? ? myActAge: that.data.age
? ? },
? }).then((res) => {
? ? console.log('succeed to 局更 your sam:1,myActWxNum...');
? })
},
removeMyJoin: function () {
? db.collection('join').doc(this.data.myJoinId).remove({
? }).then((res) => {
? ? console.log('succeed to remove my join record');
? })
},
? onShareAppMessage: function () {
? }
})
謝謝大佬們了