Initial commit

This commit is contained in:
2026-06-05 17:46:51 +08:00
commit c04c890186
96 changed files with 6477 additions and 0 deletions

View File

@@ -0,0 +1,48 @@
const cloud = require('wx-server-sdk')
cloud.init({ env: cloud.DYNAMIC_CURRENT_ENV })
const db = cloud.database()
exports.main = async (event, context) => {
const { OPENID, APPID } = cloud.getWXContext()
try {
// 查找或创建用户
const userRes = await db.collection('users').where({ openid: OPENID }).get()
let userInfo
if (userRes.data.length === 0) {
// 新用户 - 创建档案
const newUser = {
openid: OPENID,
nickName: event.nickName || '宠物爱好者',
avatarUrl: event.avatarUrl || '',
handle: '',
location: '',
bio: '',
stats: { posts: 0, friends: 0, likes: 0 },
lastLocation: null,
isOnline: true,
lastSeen: new Date().toISOString(),
pets: [],
createdAt: db.serverDate(),
updatedAt: db.serverDate(),
}
const addRes = await db.collection('users').add({ data: newUser })
userInfo = { _id: addRes._id, ...newUser }
} else {
// 老用户 - 更新在线状态
userInfo = userRes.data[0]
await db.collection('users').doc(userInfo._id).update({
data: {
isOnline: true,
lastSeen: db.serverDate(),
updatedAt: db.serverDate(),
},
})
}
return { code: 0, data: { userInfo } }
} catch (e) {
return { code: -1, message: e.message }
}
}