fix:更换刷新接口
This commit is contained in:
@@ -96,6 +96,16 @@ module.exports = {
|
|||||||
const { userId } = res.locals.user;
|
const { userId } = res.locals.user;
|
||||||
const { coinId, targetAddress, amount, password } = req.body;
|
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({
|
if (coinId !== 'usdt' && coinId !== 'vic') return res.json({
|
||||||
code: 4,
|
code: 4,
|
||||||
msg: '不支持的提现币种',
|
msg: '不支持的提现币种',
|
||||||
@@ -108,24 +118,27 @@ module.exports = {
|
|||||||
error: '资金密码错误',
|
error: '资金密码错误',
|
||||||
});
|
});
|
||||||
const fund = await Fund.findOne({ userId }).exec();
|
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,
|
code: 2,
|
||||||
msg: '资金不足',
|
msg: '资金不足',
|
||||||
error: 'insufficient fund'
|
error: 'insufficient fund'
|
||||||
});
|
});
|
||||||
const action = createAction(1, { userId, amount, remain: fund.asset, op: 0, detail: { targetAddress } });
|
const action = createAction(3, { userId, amount, remain: fund.asset, op: 0, detail: { targetAddress } });
|
||||||
const ticket = createTicket('withdraw', { userId, amount, action, targetAddress });
|
const ticket = createTicket('withdraw', { userId, amount: +amount, action, targetAddress });
|
||||||
try {
|
try {
|
||||||
await fund.decrease(coinId, +amount);
|
await fund.decrease(coinId, cost);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
mylog.error('[Fund提现] ', error);
|
mylog.error('[Fund提现] ', error);
|
||||||
|
action.detail = { error };
|
||||||
|
await action.save();
|
||||||
return res.json({
|
return res.json({
|
||||||
code: 3,
|
code: 3,
|
||||||
msg: '扣款失败',
|
msg: '扣款失败',
|
||||||
error: JSON.stringify(error)
|
error: JSON.stringify(error)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
Promise.all([ticket.save(), action.save()]).then(() => {
|
return await Promise.all([ticket.save(), action.save()]).then(() => {
|
||||||
return res.json({
|
return res.json({
|
||||||
code: 0,
|
code: 0,
|
||||||
msg: '工单已创建'
|
msg: '工单已创建'
|
||||||
|
|||||||
@@ -44,7 +44,6 @@ const services = [
|
|||||||
controller: controller.getBasicInfo
|
controller: controller.getBasicInfo
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
indexRoute: '/mine',
|
|
||||||
url: '/refresh',
|
url: '/refresh',
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
controller: controller.refreshFund
|
controller: controller.refreshFund
|
||||||
|
|||||||
Reference in New Issue
Block a user