我小程序开发,从checkResul函数开始,在里面调用不了声明的函数,数据库权限是所以人可读,假如注释掉updateMyCount函数就会执行到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();//引入数据库
var myDate;
var time;
var wxNum;
var place;
var age;
var hopeSex;
var samOrDiffCity;
Page({
data: {
myJoinId:’’, //报名参加创建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: ‘报名成功!!’
})
})
},
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 调用成功’)})
},
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 () {
}
})
辛苦大佬们了