From 73d354f138c6c458781ccdc9e97ef3e9730fdc2d Mon Sep 17 00:00:00 2001 From: chaosBreaking Date: Sat, 7 Sep 2019 17:17:07 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=94=AF=E6=8C=81=E5=B8=81=E7=A7=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/fund/fund.controller.js | 47 ++++++++++++++++++----------- src/modules/fund/fund.model.js | 7 +++++ src/modules/fund/fund.service.js | 5 +++ 3 files changed, 42 insertions(+), 17 deletions(-) diff --git a/src/modules/fund/fund.controller.js b/src/modules/fund/fund.controller.js index 165313b..f840d05 100644 --- a/src/modules/fund/fund.controller.js +++ b/src/modules/fund/fund.controller.js @@ -9,6 +9,23 @@ const { deriveNewAccount } = require('../../utils/account'); const actionFilter = 'id type amount detail op createdAt'; const { inject } = require('../../common/Provider'); +const depositCoinsList = [{ + id: 'usdtBTC', + label: 'usdtBTC', +}, { + id: 'usdtETH', + label: 'usdtETH', +}]; +const withdrawCoinsList = [{ + id: 'vic', + label: 'vic', + fee: 0.005 +}, { + id: 'usdt', + label: 'usdt', + fee: 0.005 +}]; + module.exports = { async getFundDetail (req, res) { const { userId } = res.locals.user; @@ -59,24 +76,9 @@ module.exports = { }, async getSupportCoinsList (req, res) { // eslint-disable-next-line no-undef - let coinList; - try { - // eslint-disable-next-line no-undef - coinList = await Provider.getModule('System').getValue('supportCoins'); - } catch (error) { - coinList = [{ - id: 'vic', - label: 'vic', - fee: 0.005 - }, { - id: 'usdt', - label: 'usdt', - fee: 0.005 - }]; - } return res.json({ code: 0, - data: coinList + data: depositCoinsList }); }, async withdraw (req, res) { @@ -163,7 +165,18 @@ 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]); + (!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: list + }); + }, // 查询资金,直接拉数据库,区块链的查询交给定时任务 async refreshFund (req, res) { // todo: 要求刷新程序去刷新 diff --git a/src/modules/fund/fund.model.js b/src/modules/fund/fund.model.js index ad10ca1..7338c95 100644 --- a/src/modules/fund/fund.model.js +++ b/src/modules/fund/fund.model.js @@ -42,6 +42,13 @@ const FundSchema = new mongoose.Schema({ lastDeposit: { type: String }, + lastWithdraw: { + type: {}, + default: { + usdt: '', + vic: '' + } + }, option: { type: {} }, diff --git a/src/modules/fund/fund.service.js b/src/modules/fund/fund.service.js index a903780..6e56f41 100644 --- a/src/modules/fund/fund.service.js +++ b/src/modules/fund/fund.service.js @@ -17,6 +17,11 @@ const services = [ method: 'GET', controller: controller.getActionDetail }, + { + url: '/withdrawCoins', + method: 'GET', + controller: controller.getWithdrawCoinsList + }, { url: '/depositCoins', method: 'GET',