Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…into master
  • Loading branch information
eeg1412 committed Apr 25, 2021
2 parents b609b62 + 59d957e commit f35333d
Show file tree
Hide file tree
Showing 69 changed files with 1,033 additions and 364 deletions.
315 changes: 151 additions & 164 deletions server/api/dailyCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,182 +8,169 @@ var fs = require('fs');
var chalk = require('chalk');
module.exports = async function (req, res, next) {
let IP = utils.getUserIp(req);
let token = req.body.token;
//解析token
if (!token) {
console.info(
chalk.yellow(IP + '参数有误!')
)
res.send({
code: 403,
msg: 'token为空!'
});
return false;
}
let result = await utils.tokenCheckAndEmail(token).catch((err) => {
throw err;
});
if (!result) {
res.send({
code: 403,
msg: '账户信息已失效,请重新登录!'
});
console.info(
chalk.yellow('查询结果token无效,IP为:' + IP)
);
return false;
}
let email = result.email;
console.info(
chalk.green(IP + '的邮箱解析结果为' + email)
)
console.info(
chalk.green(req.body.email + '开始日常抽卡。IP为:' + IP)
chalk.green(email + '开始日常抽卡。IP为:' + IP)
);
if (req.body.email) {
var userEmail = req.body.email;
var sel = Math.floor(req.body.sel);
//判断选择的卡牌编号是否有误
if (isNaN(sel) || sel < 0 || sel > 2) {
res.send({
code: 0,
msg: '参数有误!'
});
console.info(
chalk.yellow(req.body.email + '传参(sel)有误!IP为:' + IP)
);
return false;
}
//验证邮箱格式
if (utils.emailCheck(userEmail)) {
let params = { email: userEmail }
// document查询
let result = await userData.findUser(params).catch((err) => {
res.send({
code: 0,
msg: '内部错误请联系管理员!'
});
console.error(
chalk.red('数据库查询错误!')
);
throw err;
})
//判断是否有该用户
if (result) {
if (result.ban > 0) {
res.send({
code: 0,
msg: '该账户已被封禁!'
});
console.info(
chalk.yellow(req.body.email + '已被封禁!IP为:' + IP)
);
return false;
}
let dailyCard = result.dailyCard;
// 取消竞技点抽卡加成
let scoreChance = 0;//Math.floor(result.score/1000);
if (isNaN(scoreChance)) {
res.send({
code: 0,
msg: '内部错误请联系管理员!'
});
return false;
}
let dailyCardTime = Math.round(Number(result.dailyCardTime) * 1000);
let timeNow = Math.round(new Date().getTime() / 1000);
let myDailyChance = global.myAppConfig.dailyChance + scoreChance;
if (new Date(timeNow * 1000).toDateString() === new Date(dailyCardTime).toDateString()) {//如果是同天
if (dailyCard >= myDailyChance) {
res.send({
code: 3,
msg: '已经超过今天的抽卡次数了!'
});
console.info(
chalk.blue(req.body.email + '超过每日抽卡限制。IP为:' + IP)
);
return false;
}
} else {
dailyCard = 0;
}
let packageId = req.body.packageId || 0;
// 抽卡三次
let cardIdArr = await cardUitls.chioseCard(packageId, 3);
if (!cardIdArr) {
res.send({
code: 0,
msg: '抽卡失败,请检查参数!'
});
return false;
}
// 获取卡牌ID
let cardId = cardIdArr[sel].cardId;
if (cardId === undefined || cardId === null) {
res.send({
code: 0,
msg: '数据错误!'
});
return false;
}

let cardDataBase = {};
cardDataBase['card.' + packageId + '.' + cardId] = 1;
let emailmd5 = result.md5;
dailyCard = dailyCard + 1;
let filters = {
email: userEmail
}
let updataParams = {
dailyCard: dailyCard,
$inc: cardDataBase,
ip: IP,
dailyCardTime: timeNow
}
await userData.updataUser(filters, updataParams, true).catch((err) => {
res.send({
code: 0,
msg: '内部错误请联系管理员!'
});
console.error(
chalk.red('数据库更新错误!')
);
throw err;
})
console.info(
chalk.green('邮箱:' + userEmail + ',抽到卡牌:【' + cardId + '】! IP为:' + IP)
);
let logObject = {
email: userEmail,
md5: md5(userEmail),
nickName: result.nickName,
type: 'dailyCard',
time: timeNow,
data: {
cardId: cardId,
title: cardIdArr[sel].title,
name: cardIdArr[sel].name,
star: cardIdArr[sel].star,
packageId: packageId
},
ip: IP
}
utils.writeLog(logObject);
let cardChoiseList = []
for (let i = 0; i < cardIdArr.length; i++) {
cardChoiseList.push(cardIdArr[i].cardId)
}
const userCard = result.card || {};
const userPackageCard = userCard[packageId] || {};
const userCardIdList = Object.keys(userPackageCard);
const userCardIdIndex = userCardIdList.indexOf(cardId);
res.send({
code: 1,
cardChoiseList: cardChoiseList,
choiseIndex: sel,
emailmd5: emailmd5,
card: cardId,
packageId: packageId,
isNew: userCardIdIndex === -1,
leftGetChance: myDailyChance - dailyCard,
msg: 'ok'
});
} else {
res.send({
code: 2,
msg: '该邮箱未注册!'
});
console.info(
chalk.blue(req.body.email + '并未注册。IP为:' + IP)
);
}
} else {
var sel = Math.floor(req.body.sel);
//判断选择的卡牌编号是否有误
if (isNaN(sel) || sel < 0 || sel > 2) {
res.send({
code: 0,
msg: '参数有误!'
});
console.info(
chalk.yellow(req.body.email + '传参(sel)有误!IP为:' + IP)
);
return false;
}

if (result.ban > 0) {
res.send({
code: 0,
msg: '该账户已被封禁!'
});
console.info(
chalk.yellow(req.body.email + '已被封禁!IP为:' + IP)
);
return false;
}
let dailyCard = result.dailyCard;
// 取消竞技点抽卡加成
let scoreChance = 0;//Math.floor(result.score/1000);
if (isNaN(scoreChance)) {
res.send({
code: 0,
msg: '内部错误请联系管理员!'
});
return false;
}
let dailyCardTime = Math.round(Number(result.dailyCardTime) * 1000);
let timeNow = Math.round(new Date().getTime() / 1000);
let myDailyChance = global.myAppConfig.dailyChance + scoreChance;
if (new Date(timeNow * 1000).toDateString() === new Date(dailyCardTime).toDateString()) {//如果是同天
if (dailyCard >= myDailyChance) {
res.send({
code: 0,
msg: '邮箱地址格式有误!'
code: 3,
leftGetChance: 0,
msg: '已经超过今天的抽卡次数了!'
});
console.info(
chalk.yellow('邮箱格式有误,IP为:' + IP)
chalk.blue(req.body.email + '超过每日抽卡限制。IP为:' + IP)
);
return false;
}
} else {
dailyCard = 0;
}
let packageId = req.body.packageId || 0;
// 抽卡三次
let cardIdArr = await cardUitls.chioseCard(packageId, 3);
if (!cardIdArr) {
res.send({
code: 0,
msg: '邮箱地址不能为空!'
msg: '抽卡失败,请检查参数!'
});
console.info(
chalk.yellow('邮箱为空,IP为:' + IP)
return false;
}
// 获取卡牌ID
let cardId = cardIdArr[sel].cardId;
if (cardId === undefined || cardId === null) {
res.send({
code: 0,
msg: '数据错误!'
});
return false;
}

let cardDataBase = {};
cardDataBase['card.' + packageId + '.' + cardId] = 1;
let emailmd5 = result.md5;
dailyCard = dailyCard + 1;
let filters = {
email: email
}
let updataParams = {
dailyCard: dailyCard,
$inc: cardDataBase,
ip: IP,
dailyCardTime: timeNow
}
await userData.updataUser(filters, updataParams, true).catch((err) => {
res.send({
code: 0,
msg: '内部错误请联系管理员!'
});
console.error(
chalk.red('数据库更新错误!')
);
throw err;
})
console.info(
chalk.green('邮箱:' + email + ',抽到卡牌:【' + cardId + '】! IP为:' + IP)
);
let logObject = {
email: email,
md5: md5(email),
nickName: result.nickName,
type: 'dailyCard',
time: timeNow,
data: {
cardId: cardId,
title: cardIdArr[sel].title,
name: cardIdArr[sel].name,
star: cardIdArr[sel].star,
packageId: packageId
},
ip: IP
}
utils.writeLog(logObject);
let cardChoiseList = []
for (let i = 0; i < cardIdArr.length; i++) {
cardChoiseList.push(cardIdArr[i].cardId)
}
const userCard = result.card || {};
const userPackageCard = userCard[packageId] || {};
const userCardIdList = Object.keys(userPackageCard);
const userCardIdIndex = userCardIdList.indexOf(cardId);
res.send({
code: 1,
cardChoiseList: cardChoiseList,
choiseIndex: sel,
emailmd5: emailmd5,
card: cardId,
packageId: packageId,
isNew: userCardIdIndex === -1,
leftGetChance: myDailyChance - dailyCard,
msg: 'ok'
});
}
Loading

0 comments on commit f35333d

Please sign in to comment.