'use strict'; exports.main = async (event, context) => { const db = uniCloud.database() const collection = db.collection('mustgo-team-activity') let res = await collection.where({ _id: event.activityId }).get() if (res.affectedDocs == 1) { const usercollection = db.collection('mustgo-user') let res1 = await usercollection.where({ _id: res.data[0]["owner_id"] }).get() let username let icon if (res1.affectedDocs == 1) { username = res1.data[0]["name"] icon = res1.data[0]["icon"] } const reg = db.collection('mustgo-registration') let res2 = await reg.where({ team_activity_id: event.activityId, owner_id: event.userId }).get() var time = getSystemTime() if (time > res.data[0]["start_date"]) { return { code: 200, message: "成功返回活动详情", qualification: "报名时间截止", data: { "username": username, "icon": icon, "content": res.data[0]["content"], "startDate": res.data[0]["start_date"], "endDate": res.data[0]["end_date"], "place": res.data[0]["place"], "participants": res.data[0]["participants"], "contact": res.data[0]["contact"], "enrollment": res.data[0]["enrollment"] } } } if (res2.affectedDocs == 1) { return { code: 200, message: "成功返回活动详情", qualification: "取消报名", data: { "username": username, "icon": icon, "content": res.data[0]["content"], "startDate": res.data[0]["start_date"], "endDate": res.data[0]["end_date"], "place": res.data[0]["place"], "participants": res.data[0]["participants"], "contact": res.data[0]["contact"], "enrollment": res.data[0]["enrollment"] } } } if (res.data[0]["participants"] <= res.data[0]["enrollment"]) { return { code: 200, message: "成功返回活动详情", qualification: "活动人数已满", data: { "username": username, "icon": icon, "content": res.data[0]["content"], "startDate": res.data[0]["start_date"], "endDate": res.data[0]["end_date"], "place": res.data[0]["place"], "participants": res.data[0]["participants"], "contact": res.data[0]["contact"], "enrollment": res.data[0]["enrollment"] } } } return { code: 200, message: "成功返回活动详情", qualification: "报名", data: { "username": username, "icon": icon, "content": res.data[0]["content"], "startDate": res.data[0]["start_date"], "endDate": res.data[0]["end_date"], "place": res.data[0]["place"], "participants": res.data[0]["participants"], "contact": res.data[0]["contact"], "enrollment": res.data[0]["enrollment"] } } } return { "code": 400, "message": "返回小队活动详情失败", "data": {} } }; function getSystemTime() { // 实例化日期类 var time = new Date(); // 获取完整的年份(4位) var year = time.getFullYear(); // 获取月份(0-11,0代表1月) var month = time.getMonth() + 1; if(month<10) month = "0"+month // 获取日期(1-31) var date = time.getDate(); if(date<10) date = "0"+date // 获取小时 var h = time.getHours() + 8; h = h < 10 ? '0' + h : h; // 获取分钟 var m = time.getMinutes(); m = m < 10 ? '0' + m : m; // 获取秒钟 var s = time.getSeconds(); s = s < 10 ? '0' + s : s; // 合并返回 return(year + "-" + month + "-" + date + " " + h + ":" + m) ; }