Initial commit
This commit is contained in:
25
cloudfunctions/updateLocation/index.js
Normal file
25
cloudfunctions/updateLocation/index.js
Normal file
@@ -0,0 +1,25 @@
|
||||
const cloud = require('wx-server-sdk')
|
||||
cloud.init({ env: cloud.DYNAMIC_CURRENT_ENV })
|
||||
const db = cloud.database()
|
||||
|
||||
exports.main = async (event, context) => {
|
||||
const { OPENID } = cloud.getWXContext()
|
||||
const { latitude, longitude } = event
|
||||
|
||||
if (!latitude || !longitude) return { code: -1, message: '缺少位置' }
|
||||
|
||||
try {
|
||||
await db.collection('users')
|
||||
.where({ openid: OPENID })
|
||||
.update({
|
||||
data: {
|
||||
lastLocation: { latitude, longitude },
|
||||
isOnline: true,
|
||||
lastSeen: db.serverDate(),
|
||||
},
|
||||
})
|
||||
return { code: 0, data: null }
|
||||
} catch (e) {
|
||||
return { code: -1, message: e.message }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user