feat: reward
This commit is contained in:
@@ -11,12 +11,11 @@ const { calRevenueLastday, getActiveFund } = require('./fund.handler');
|
||||
const { getDate } = require('../../utils/date');
|
||||
const Crypto = require('../../utils/crypto');
|
||||
const actionFilter = 'id type amount detail op createdAt tokenType';
|
||||
const { USDT2VIC_RATE } = require('./constant');
|
||||
|
||||
const depositCoinsList = [{
|
||||
id: 'usdtETH',
|
||||
label: 'usdt',
|
||||
rate: USDT2VIC_RATE
|
||||
label: 'vic',
|
||||
rate: 1
|
||||
}];
|
||||
const withdrawCoinsList = [{
|
||||
id: 'vic',
|
||||
@@ -37,7 +36,7 @@ module.exports = {
|
||||
return res.json({
|
||||
code: 0,
|
||||
msg: 'success',
|
||||
data: fund && fund.asset
|
||||
data: { vic: fund.vicFundSum, usdt: 0 }
|
||||
});
|
||||
}).catch(err => {
|
||||
mylog.error("[getFundDetail]", err);
|
||||
@@ -123,9 +122,9 @@ module.exports = {
|
||||
});
|
||||
const [user, fund] = await Promise.all([User.findById(userId), Fund.findOne({ userId })]);
|
||||
if (
|
||||
(coinId === 'vic' && +amount < 30)
|
||||
+amount < 1000
|
||||
||
|
||||
+fund.fundSum < 500
|
||||
+fund.vicFundSum < 1000
|
||||
||
|
||||
+user.verifyLevel < 1
|
||||
) {
|
||||
@@ -135,6 +134,12 @@ module.exports = {
|
||||
error: '不满足提现条件',
|
||||
});
|
||||
}
|
||||
const cost = +amount * 1.005;
|
||||
if (fund.asset && +fund.asset[coinId] < cost) return res.json({
|
||||
code: 2,
|
||||
msg: '资金不足',
|
||||
error: 'insufficient fund'
|
||||
});
|
||||
let hashpwd = password;
|
||||
if (hashpwd.length < 30) {
|
||||
hashpwd = Crypto.hash(password, {hasher: 'md5'});
|
||||
@@ -144,16 +149,10 @@ module.exports = {
|
||||
msg: '资金密码错误',
|
||||
error: '资金密码错误',
|
||||
});
|
||||
const cost = +amount * 1.005;
|
||||
if (fund.asset && +fund.asset[coinId] < cost) return res.json({
|
||||
code: 2,
|
||||
msg: '资金不足',
|
||||
error: 'insufficient fund'
|
||||
});
|
||||
const action = createAction(3, { userId, amount, remain: fund.asset, op: 0, detail: { targetAddress, coinId } });
|
||||
const ticket = createTicket('withdraw', { userId, amount: +amount, action, targetAddress, coinId });
|
||||
try {
|
||||
await fund.decrease(coinId, cost);
|
||||
await fund.decFund(cost);
|
||||
} catch (error) {
|
||||
mylog.error('[Fund提现] ', error);
|
||||
action.detail = { error };
|
||||
@@ -217,12 +216,6 @@ module.exports = {
|
||||
};
|
||||
}),
|
||||
async getWithdrawCoinsList (req, res) {
|
||||
// const { userId } = res.locals.user;
|
||||
// const userFund = await Fund.findOne({userId}).exec();
|
||||
// const asset = userFund.asset;
|
||||
// const list = [];
|
||||
// (asset['vic'] >= 1000) && list.push(withdrawCoinsList[0]);
|
||||
// (asset['usdt'] > 0 && (!userFund.lastWithdraw.usdt || (new Date() - new Date(userFund.lastWithdraw.usdt)) / (1000 * 3600 * 24 * 7) >= 1)) && list.push(withdrawCoinsList[1]);
|
||||
return res.json({
|
||||
code: 0,
|
||||
data: withdrawCoinsList
|
||||
@@ -249,7 +242,8 @@ module.exports = {
|
||||
// 计算昨日收益
|
||||
let revenueLastday = calRevenueLastday(actions);
|
||||
// 筛选有效矿晶
|
||||
let activeFund = getActiveFund(fund.fundList);
|
||||
// let activeFund = getActiveFund(fund.fundList);
|
||||
let activeFund = fund.fundList;
|
||||
let revenueAll = Array.isArray(allAction) && allAction.reduce((pre, cur) => pre + (+cur.amount || 0), 0) || 0;
|
||||
revenueAll = revenueAll.toFixed(4);
|
||||
return res.json({
|
||||
@@ -272,7 +266,8 @@ module.exports = {
|
||||
// 计算昨日收益
|
||||
let revenueLastday = calRevenueLastday(actions);
|
||||
// 筛选有效矿晶
|
||||
let activeFund = getActiveFund(fund.fundList);
|
||||
// let activeFund = getActiveFund(fund.fundList);
|
||||
let activeFund = fund.fundList;
|
||||
if (!newFund || !newFund.fundList) newFund = fund;
|
||||
let revenueAll = Array.isArray(allAction) && allAction.reduce((pre, cur) => pre + (+cur.amount || 0), 0) || 0;
|
||||
revenueAll = revenueAll.toFixed(4);
|
||||
@@ -291,7 +286,7 @@ module.exports = {
|
||||
},
|
||||
async getFundList (req, res) {
|
||||
const { userId } = res.locals.user;
|
||||
return Fund.findOne({userId}, 'fundList').then(fund => {
|
||||
return Fund.findOne({ userId }, 'fundList').then(fund => {
|
||||
return res.json({
|
||||
code: 0,
|
||||
data: fund.fundList
|
||||
@@ -310,7 +305,8 @@ module.exports = {
|
||||
const [ start, end ] = getDate(1);
|
||||
let now = new Date();
|
||||
// 筛选有效矿晶
|
||||
let activeFund = getActiveFund(fund.fundList);
|
||||
// let activeFund = getActiveFund(fund.fundList);
|
||||
let activeFund = fund.fundList;
|
||||
const actions = await Action.find({ userId, type: 1, createdAt: { $gt: start, $lt: now } }).exec();
|
||||
const allAction = await Action.find({ userId, type: 1 }).exec();
|
||||
// 计算昨日收益
|
||||
|
||||
Reference in New Issue
Block a user