index.js 3.4 KB
Newer Older
L
ljw 已提交
1 2 3 4 5 6 7 8
'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) {
L
修改  
ljw 已提交
9

L
ljw 已提交
10 11 12 13 14 15 16 17 18 19
		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"]
		}
L
修改  
ljw 已提交
20 21 22 23 24 25

		const reg = db.collection('mustgo-registration')
		let res2 = await reg.where({
			team_activity_id: event.activityId,
			owner_id: event.userId
		}).get()
L
ljw 已提交
26

L
ljw 已提交
27
		var time =  getSystemTime()
L
ljw 已提交
28
		
L
ljw 已提交
29

L
ljw 已提交
30
		if (time > res.data[0]["start_date"]) {
L
ljw 已提交
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
			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"]
				}
			}
		}

L
修改  
ljw 已提交
49 50 51 52 53 54 55 56 57 58 59 60 61 62
		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"],
L
ljw 已提交
63
					"enrollment": res.data[0]["enrollment"]
L
修改  
ljw 已提交
64 65 66 67 68 69 70 71
				}
			}
		}

		if (res.data[0]["participants"] <= res.data[0]["enrollment"]) {
			return {
				code: 200,
				message: "成功返回活动详情",
L
ljw 已提交
72
				qualification: "活动人数已满",
L
修改  
ljw 已提交
73 74 75 76 77 78 79 80 81
				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"],
L
ljw 已提交
82
					"enrollment": res.data[0]["enrollment"]
L
修改  
ljw 已提交
83 84 85
				}
			}
		}
L
ljw 已提交
86

L
ljw 已提交
87 88 89
		return {
			code: 200,
			message: "成功返回活动详情",
L
修改  
ljw 已提交
90
			qualification: "报名",
L
ljw 已提交
91
			data: {
L
修改  
ljw 已提交
92 93
				"username": username,
				"icon": icon,
L
ljw 已提交
94 95 96 97 98
				"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"],
L
修改  
ljw 已提交
99
				"contact": res.data[0]["contact"],
L
ljw 已提交
100
				"enrollment": res.data[0]["enrollment"]
L
ljw 已提交
101 102
			}
		}
L
修改  
ljw 已提交
103

L
ljw 已提交
104 105 106 107 108 109
	}
	return {
		"code": 400,
		"message": "返回小队活动详情失败",
		"data": {}
	}
L
ljw 已提交
110 111 112 113 114 115 116 117 118
};

function getSystemTime() {
	// 实例化日期类
	var time = new Date();
	// 获取完整的年份(4位)
	var year = time.getFullYear();
	// 获取月份(0-11,0代表1月)
	var month = time.getMonth() + 1;
L
ljw 已提交
119 120
	if(month<10)
		month = "0"+month
L
ljw 已提交
121 122
	// 获取日期(1-31)
	var date = time.getDate();
L
ljw 已提交
123 124
	if(date<10)
		date = "0"+date
L
ljw 已提交
125 126 127 128 129 130 131 132 133 134 135 136 137
	// 获取小时
	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) ;

}