feat: 充值查询+刷新
This commit is contained in:
@@ -4,6 +4,7 @@ const mongoose = require('mongoose');
|
||||
const ASSETTYPES = ['gin', 'vic', 'usdtBTC', 'usdtETH', 'usdtTRX'];
|
||||
const { createAction } = require('../action/action.handler');
|
||||
const { createNewFund } = require('./fund.handler');
|
||||
const { getNewDepositTx, getUSDTTxList } = require('../../common/deposit');
|
||||
|
||||
const FundSchema = new mongoose.Schema({
|
||||
userId: {
|
||||
@@ -61,8 +62,20 @@ const FundSchema = new mongoose.Schema({
|
||||
|
||||
|
||||
const FundModel = mongoose.model('Fund', FundSchema);
|
||||
|
||||
FundModel.prototype.hasNewDeposit = async function () {
|
||||
if (this.tokenAddress.usdtETH) {
|
||||
const usdtTx = await getUSDTTxList(this.tokenAddress.usdtETH);
|
||||
const fundList = this.fundList;
|
||||
const newDepositList = getNewDepositTx(usdtTx, fundList);
|
||||
if (newDepositList && newDepositList.length > 0)
|
||||
return { hasNew: true, list: newDepositList };
|
||||
}
|
||||
return { hasNew: false };
|
||||
};
|
||||
|
||||
/**
|
||||
[incFund] : 向用户添加矿晶,在用户充值USDT时调用!!!!
|
||||
[addFund] : 向用户添加矿晶,在用户充值USDT时调用!!!!
|
||||
* 当一个用户充值,
|
||||
• 4% 给上面第一个 金 或 银 或 铜 会员
|
||||
• 3%
|
||||
@@ -70,34 +83,47 @@ const FundModel = mongoose.model('Fund', FundSchema);
|
||||
• 如果直接上家不是金,就平分 3% 给上线所有银会员
|
||||
• 2% 给上线所有金会员平分
|
||||
*/
|
||||
FundModel.prototype.incFund = async function (amount, option = {}) {
|
||||
if (!amount || !Number.isFinite(amount) || amount <= 0) return null;
|
||||
FundModel.prototype.addFund = async function (txlist = [], option) {
|
||||
let newSum = 0;
|
||||
const actionPromiseList = [];
|
||||
const newFundList = txlist.map(txObj => {
|
||||
newSum += +txObj.amount;
|
||||
const action = createAction(0, {
|
||||
userId: this.userId,
|
||||
amount: txObj.amount,
|
||||
tokenType: 'vic', // 目前设定只能挖出矿晶vic
|
||||
remain: this.asset
|
||||
});
|
||||
actionPromiseList.push(action.save());
|
||||
return createNewFund(txObj);
|
||||
});
|
||||
// 1.注入资金
|
||||
const newFund = createNewFund(amount);
|
||||
const res = await FundModel.findByIdAndUpdate(this.id, {
|
||||
$push: {
|
||||
fundList: newFund
|
||||
fundList: newFundList
|
||||
},
|
||||
$inc: {
|
||||
fundSum: amount
|
||||
fundSum: newSum
|
||||
},
|
||||
$set: {
|
||||
lastDeposit: new Date().toISOString()
|
||||
}
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
}, { ...option, returnOriginal: false }).exec().catch(err => null);
|
||||
|
||||
// 2.记录action
|
||||
const action = createAction(0, {
|
||||
userId: this.userId,
|
||||
amount,
|
||||
tokenType: 'vic', // 目前设定只能挖出矿晶vic
|
||||
remain: this.asset
|
||||
});
|
||||
await action.save().catch(err => {
|
||||
Promise.all(actionPromiseList).catch(err => {
|
||||
throw new Error('充值行为记录失败', err.errmsg);
|
||||
});
|
||||
// 3.奖励团队
|
||||
|
||||
// 3.增加上家团队总额
|
||||
FundModel.findOneAndUpdate({ userId: option.inviter }, {
|
||||
$inc: {
|
||||
groupFundSum: newSum
|
||||
}
|
||||
});
|
||||
// 4.奖励团队
|
||||
// todo
|
||||
return res;
|
||||
};
|
||||
FundModel.prototype.increase = async function (assetName, amount, option = {}) {
|
||||
|
||||
Reference in New Issue
Block a user