Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion client/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ var config = {
uploadUrl: `${host}/weapp/upload`,

// Memory api url
memoryUrl: `${host}/weapp/memory`
memoryUrl: `${host}/weapp/memory`,

// Birthday api url
birthdayUrl: `${host}/weapp/birthday`,
}
};

Expand Down
40 changes: 39 additions & 1 deletion client/pages/index/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
//index.js
const qcloud = require('wafer2-client-sdk');
const config = require('../../config');
const app = getApp();

Page({

/**
Expand Down Expand Up @@ -36,7 +40,41 @@ Page({
* 生命周期函数--监听页面显示
*/
onShow: function () {

var that = this;
qcloud.request({
url: config.service.birthdayUrl,
method: 'GET',
header: {
'content-type': 'application/x-www-form-urlencoded'
},
success: function(res) {
var data = res.data;
if (data.length > 0) {
var birthdayMsg = "Happy birthday ";
if (data.length == 1) {
birthdayMsg += data[0].EnglishName + "(" + data[0].ChineseName + ")";
} else {
for (var i = 0; i < data.length; i++) {
birthdayMsg += (data[i].EnglishName + "(" + data[i].ChineseName + ")");
if (i < data.length - 2) {
birthdayMsg += ", ";
} else if (i == data.length - 2) {
birthdayMsg += " and ";
} else {
birthdayMsg += "!";
}
}
}
that.setData({
birthdayMsg: birthdayMsg
})
}
},
fail: err => {
console.log("failed to get birthday");
console.error(err);
}
})
},

/**
Expand Down
3 changes: 3 additions & 0 deletions client/pages/index/index.wxml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,7 @@
<view class='time'>
<text>Training starts at {{ time }}</text>
</view>
<view class='birthdayMsg'>
<text>{{ birthdayMsg }}</text>
</view>
</view>
7 changes: 7 additions & 0 deletions client/pages/index/index.wxss
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,11 @@
text-align: center;
margin-top: 20px;
margin-bottom: 30px;
}
.birthdayMsg {
color: #FFF;
font-size: 16px;
text-align: center;
margin-top: 15px;
margin-bottom: 30px;
}
16 changes: 16 additions & 0 deletions server/controllers/birthday.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const assert = require('assert');
const { mysql } = require('../qcloud.js');
const userTableName = "User";


async function get(ctx) {
var today = new Date();
var dd = parseInt(String(today.getDate()).padStart(2, '0'));
var mm = parseInt(String(today.getMonth() + 1).padStart(2, '0'));
var birthday_guys = await mysql(userTableName).where({ BirthdayMonth: mm, BirthdayDate: dd });
ctx.body = birthday_guys;
}

module.exports = {
get
};
3 changes: 3 additions & 0 deletions server/routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ router.put('/training', controllers.training.put)
// Memory API endpoints
router.get('/memory', controllers.memory.get)

// Birthday API endpoints
router.get('/birthday', controllers.birthday.get)

// --- 图片上传 Demo --- //
// 图片上传接口,小程序端可以直接将 url 填入 wx.uploadFile 中
router.post('/upload', controllers.upload)
Expand Down
8 changes: 5 additions & 3 deletions server/tools/sql_tables/User.sql
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ DROP TABLE IF EXISTS `User`;
CREATE TABLE `User` (
`OpenId` varchar(255) NOT NULL,
`WechatName` varchar(255) NOT NULL,
`Birthday` date NOT NULL,
`BirthdayYear` smallint NOT NULL,
`BirthdayMonth` smallint NOT NULL,
`BirthdayDate` smallint NOT NULL,
`ChineseName` varchar(255) DEFAULT NULL,
`EnglishName` varchar(255) DEFAULT NULL,
`EmailAddress` varchar(255) NOT NULL,
Expand All @@ -29,7 +31,7 @@ CREATE TABLE `User` (
--
ALTER TABLE `User`
ADD PRIMARY KEY (`OpenId`),
ADD KEY `Name_Index` (`WechatName`),
ADD KEY `Birthday_Index` (`Birthday`);
ADD KEY `Name_Index` (`WechatName`);
-- ADD KEY `Birthday_Index` (`Birthday`)

SET FOREIGN_KEY_CHECKS = 1;