fix:更换刷新接口

This commit is contained in:
chaosBreaking
2019-09-08 21:05:50 +08:00
parent 383e24fbfa
commit 89de3ac51c
2 changed files with 18 additions and 6 deletions

View File

@@ -96,6 +96,16 @@ module.exports = {
const { userId } = res.locals.user;
const { coinId, targetAddress, amount, password } = req.body;
// 暂且硬编码支持币种!!!!
if (!coinId || !targetAddress || !amount || !password) return res.json({
code: 6,
msg: '缺少必要参数',
error: '缺少必要参数'
});
if (!Number.isFinite(+amount) || !Number.isSafeInteger(+amount) || Number.isNaN(+amount)) return res.json({
code: 5,
msg: '非法额度',
error: '非法额度'
});
if (coinId !== 'usdt' && coinId !== 'vic') return res.json({
code: 4,
msg: '不支持的提现币种',
@@ -108,24 +118,27 @@ module.exports = {
error: '资金密码错误',
});
const fund = await Fund.findOne({ userId }).exec();
if (fund.asset && fund.asset[coinId] < amount * 1.005 ) return res.json({
const cost = +amount * 1.005;
if (fund.asset && +fund.asset[coinId] < cost) return res.json({
code: 2,
msg: '资金不足',
error: 'insufficient fund'
});
const action = createAction(1, { userId, amount, remain: fund.asset, op: 0, detail: { targetAddress } });
const ticket = createTicket('withdraw', { userId, amount, action, targetAddress });
const action = createAction(3, { userId, amount, remain: fund.asset, op: 0, detail: { targetAddress } });
const ticket = createTicket('withdraw', { userId, amount: +amount, action, targetAddress });
try {
await fund.decrease(coinId, +amount);
await fund.decrease(coinId, cost);
} catch (error) {
mylog.error('[Fund提现] ', error);
action.detail = { error };
await action.save();
return res.json({
code: 3,
msg: '扣款失败',
error: JSON.stringify(error)
});
}
Promise.all([ticket.save(), action.save()]).then(() => {
return await Promise.all([ticket.save(), action.save()]).then(() => {
return res.json({
code: 0,
msg: '工单已创建'

View File

@@ -44,7 +44,6 @@ const services = [
controller: controller.getBasicInfo
},
{
indexRoute: '/mine',
url: '/refresh',
method: 'GET',
controller: controller.refreshFund