-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
108 lines (102 loc) · 2.4 KB
/
app.js
File metadata and controls
108 lines (102 loc) · 2.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
App({
globalData: {
appID: 'wxc8e55628d4b7396c',
unionid: null,
openid: null,
userInfo: null,
encryptedData: null,
vi: null
},
onLaunch: function() {
// 初始化云开发
if (!wx.cloud) {
console.error('请使用 2.2.3 或以上的基础库以使用云能力')
} else {
wx.cloud.init({
traceUser: true,
env: 'test-199cdb'
})
}
// 获取openid
var that = this;
wx.cloud.callFunction({
name: 'login',
data: {},
success(res) {
that.globalData.openid = res.result.openid;
that.globalData.unionid = res.result.unionid;
checkUser(that.globalData.openid, that.globalData.unionid);
},
fail(res) {
// to be done
}
})
}
})
function checkUser(openid, unionid) {
const db = wx.cloud.database();
/**//////////////////////////////////
// 临时插入管理员
db.collection('administrator').doc(openid).get({
success(res) {
// 已有用户数据
console.log(res);
},
fail(res) {
db.collection('administrator').add({
data: {
_id: openid,
unionid: unionid,
wechatInfo: {
nickName: null,
avatarUrl: null,
gender: null, // 性别 0:未知、1:男、2:女
province: null,
city: null,
country: null
},
},
})
}
})
/**///////////////////////////////////
// 查询openid,新用户则插入
db.collection('userInfo').doc(openid).get({
success(res) {
// 已有用户数据
console.log(res);
},
fail(res) {
// 插入新用户openid
db.collection('userInfo').add({
data: {
_id: openid,
unionid: unionid,
registrationDate: new Date(),
wechatInfo: {
nickName: null,
avatarUrl: null,
gender: null, // 性别 0:未知、1:男、2:女
province: null,
city: null,
country: null
},
name: null,
gender: null,
phoneNumber: null,
age: null,
permissionAppointment: false,
permissionQuestion: false,
appointment: []
},
success(res) {
console.log(res);
},
fail(res) {
// insert fail
// to be done
}
})
}
})
}