PS:后端是NODE
实现功能很简单,记录连续签到,签到内容,签到时间
//config.sql引入数据库
config.sql(`UPDATE sign_in_table SET total = total +1,reward = reward + 5,content_id = ${content_id},today = ${now},tomorrow=${tomorrow} WHERE uid = ? AND tomorrow <= ${now}`,uid).then(datas=>{
if(datas.warning.affectedRows == 1 || datas.warning.changedRows == 1){
config.sql(`UPDATE user_main_table SET silver = silver + 5, u_exp = u_exp + 5, g_exp = g_exp + 5 WHERE uid = ?`,uid).then(datas=>{
if(datas.warning.affectedRows == 1 || datas.warning.changedRows == 1){
config.sql(`UPDATE sign_in_table SET continuous = continuous + 1,night=${night} WHERE uid = ? AND (${now} < night OR night = 0)`,uid).then(datas=>{
if(datas.warning.affectedRows == 1 || datas.warning.changedRows == 1){
res.json({
name: 'SUCCESS',
msg: '签到成功'
});
return;
}else{
config.sql(`UPDATE sign_in_table SET continuous = 0 WHERE uid = ?`,uid).then(datas=>{
res.json({
name: 'SUCCESS',
msg: '签到成功'
});
return;
}).catch((error)=>{
console.log(`sign1.41:${error}`.red);
res.send("SERVER_ERROR").end();
});
}
}).catch((error)=>{
console.log(`sign1.31:${error}`.red);
res.send("SERVER_ERROR").end();
});
}else{
res.json({
name: 'WARNING',
msg: '签到失败'
});
return;
}
}).catch((error)=>{
console.log(`sign1.21:${error}`.red);
res.send("SERVER_ERROR").end();
});
}else{
res.json({
name: 'WARNING',
msg: '你今天已经签到了哦'
});
return;
}
}).catch((error)=>{
console.log(`sign1.11:${error}`.red);
res.send("SERVER_ERROR").end();
});
这语法其实挺简单的,只是我更新了四次数据库,我想优化...我是做前端的,NODE勉强能接受,至于数据库......
其实我不需要很好的性能,一天只需要处理最多6000用户的签到就可以了。请问这样可以吗?