admin
This commit is contained in:
2
cn.js
2
cn.js
@@ -8,7 +8,7 @@ const Fund = require('./src/modules/fund/fund.model');
|
|||||||
const system = require('./src/modules/system/system.model');
|
const system = require('./src/modules/system/system.model');
|
||||||
const { createAction } = require('./src/modules/action/action.handler');
|
const { createAction } = require('./src/modules/action/action.handler');
|
||||||
|
|
||||||
const tokenReleaseRate = 0.01;
|
const tokenReleaseRate = 0.02;
|
||||||
const inviteReward = 2.5;
|
const inviteReward = 2.5;
|
||||||
|
|
||||||
async function awardMine(user, fund) {
|
async function awardMine(user, fund) {
|
||||||
|
|||||||
@@ -27,6 +27,16 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
async sendVIC2User (toAddress, amount, option = {}) {
|
async sendVIC2User (toAddress, amount, option = {}) {
|
||||||
const account = ERC20.fromMnemonic(VICSECWORD, VICCONTRACTADDR);
|
const account = ERC20.fromMnemonic(VICSECWORD, VICCONTRACTADDR);
|
||||||
return await account.transfer(toAddress, amount, Object.assign(option, { decimals: 18 }));
|
return await account.transfer(toAddress, amount, Object.assign(option, { decimals: 18 })).then(res => {
|
||||||
|
return {
|
||||||
|
success: true,
|
||||||
|
res
|
||||||
|
};
|
||||||
|
}).catch(err => {
|
||||||
|
return {
|
||||||
|
error: err,
|
||||||
|
res: null
|
||||||
|
};
|
||||||
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
61
src/modules/admin/admin.controller.js
Normal file
61
src/modules/admin/admin.controller.js
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
const { createToken } = require('../../utils/jwt');
|
||||||
|
const { inject } = require('../../common/Provider');
|
||||||
|
const Admin = require('./admin.model');
|
||||||
|
const Action = require('../action/action.model');
|
||||||
|
const Ticket = require('../ticket/ticket.model');
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
signin: function (SysConfig) {
|
||||||
|
const { JWT_SECRET } = SysConfig;
|
||||||
|
return async (req, res) => {
|
||||||
|
const { adminId, passwd } = req.headers;
|
||||||
|
if (!adminId || !passwd) return res.json({ code: 1, msg: '密码错误' });
|
||||||
|
const admin = await Admin.findOne({ id: adminId, passwd });
|
||||||
|
// res.locals.user
|
||||||
|
// const { userId } = res.locals.user;
|
||||||
|
const token = createToken({
|
||||||
|
adminId: admin.id
|
||||||
|
}, JWT_SECRET, {});
|
||||||
|
return res.json({
|
||||||
|
code: 0,
|
||||||
|
data: {
|
||||||
|
token
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
},
|
||||||
|
async getUserActions (req, res) {
|
||||||
|
const { adminId } = res.locals.user;
|
||||||
|
if (!adminId) return res.json({ code: 1, msg: '非法访问' });
|
||||||
|
const { userId, type, op } = req.body;
|
||||||
|
await Action.find({ userId, type, op }).then(data => {
|
||||||
|
return res.json({
|
||||||
|
code: 0,
|
||||||
|
data
|
||||||
|
});
|
||||||
|
}).catch(err => {
|
||||||
|
return res.json({
|
||||||
|
code: 1,
|
||||||
|
msg: err.msg
|
||||||
|
});
|
||||||
|
});
|
||||||
|
},
|
||||||
|
async getDepositTicket (req, res) {
|
||||||
|
const { adminId } = res.locals.user;
|
||||||
|
if (!adminId) return res.json({ code: 1, msg: '非法访问' });
|
||||||
|
const { userId, type, status } = req.body;
|
||||||
|
await Ticket.find({ userId, status, type }).then(data => {
|
||||||
|
return res.json({
|
||||||
|
code: 0,
|
||||||
|
data
|
||||||
|
});
|
||||||
|
}).catch(err => {
|
||||||
|
return res.json({
|
||||||
|
code: 1,
|
||||||
|
msg: err.msg
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
17
src/modules/admin/admin.model.js
Normal file
17
src/modules/admin/admin.model.js
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
const mongoose = require('mongoose');
|
||||||
|
|
||||||
|
const AdminSchema = new mongoose.Schema({
|
||||||
|
passwd: {
|
||||||
|
type: String
|
||||||
|
},
|
||||||
|
option: {
|
||||||
|
type: {},
|
||||||
|
default: {}
|
||||||
|
}
|
||||||
|
},{});
|
||||||
|
|
||||||
|
const AdminModel = mongoose.model('Admin', AdminSchema);
|
||||||
|
|
||||||
|
module.exports = AdminModel;
|
||||||
22
src/modules/admin/admin.service.js
Normal file
22
src/modules/admin/admin.service.js
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
const indexRoute = '/admin/api';
|
||||||
|
const controller = require('./admin.controller');
|
||||||
|
const services = [
|
||||||
|
{
|
||||||
|
url: '/in',
|
||||||
|
method: 'GET',
|
||||||
|
controller: controller.signin
|
||||||
|
},
|
||||||
|
{
|
||||||
|
url: '/actions',
|
||||||
|
method: 'POST',
|
||||||
|
controller: controller.getUserActions
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
|
module.exports = services.map(service => {
|
||||||
|
// 可以在此处对要导出的服务map进行统一处理
|
||||||
|
service.url = indexRoute + service.url;
|
||||||
|
return service;
|
||||||
|
});
|
||||||
@@ -176,11 +176,12 @@ module.exports = {
|
|||||||
const { userId } = res.locals.user;
|
const { userId } = res.locals.user;
|
||||||
const { password, newPassword } = req.body;
|
const { password, newPassword } = req.body;
|
||||||
const user = await User.findById(userId).exec();
|
const user = await User.findById(userId).exec();
|
||||||
if (!user || user.password !== Crypto.hash(password, { salt: PWD_HASH_SALT }))
|
if (!user || user.password !== Crypto.hash(password, { salt: PWD_HASH_SALT })) {
|
||||||
return res.json({
|
return res.json({
|
||||||
code: 1,
|
code: 1,
|
||||||
msg: '原始密码错误'
|
msg: '原始密码错误'
|
||||||
});
|
});
|
||||||
|
}
|
||||||
const newHashPasswd = Crypto.hash(newPassword, { salt: PWD_HASH_SALT });
|
const newHashPasswd = Crypto.hash(newPassword, { salt: PWD_HASH_SALT });
|
||||||
const update = { password: newHashPasswd };
|
const update = { password: newHashPasswd };
|
||||||
const success = await User.findByIdAndUpdate(userId, update, { new: true })
|
const success = await User.findByIdAndUpdate(userId, update, { new: true })
|
||||||
|
|||||||
@@ -6,7 +6,8 @@ const handleTicket = require('./ticket.handler');
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
// 处理工单请求的api
|
// 处理工单请求的api
|
||||||
async reqHandleTicket (req, res) {
|
async reqHandleTicket (req, res) {
|
||||||
const { handlerId } = res.local.handler;
|
const { adminId } = res.locals.user;
|
||||||
|
if (!adminId) return res.json({ code: 1, msg: '非法访问' });
|
||||||
const { id } = req.body;
|
const { id } = req.body;
|
||||||
// 存在性检查
|
// 存在性检查
|
||||||
const ticket = await Ticket.findById(id).exec().catch(err => {
|
const ticket = await Ticket.findById(id).exec().catch(err => {
|
||||||
@@ -18,7 +19,7 @@ module.exports = {
|
|||||||
msg: 'unknow ticket'
|
msg: 'unknow ticket'
|
||||||
});
|
});
|
||||||
// 调用处理函数
|
// 调用处理函数
|
||||||
handleTicket(ticket, handlerId).then(data => {
|
handleTicket(ticket, adminId).then(data => {
|
||||||
return res.json({
|
return res.json({
|
||||||
code: 0,
|
code: 0,
|
||||||
msg: 'success',
|
msg: 'success',
|
||||||
@@ -32,8 +33,10 @@ module.exports = {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
async getTicketList (req, res) {
|
async getTicketList (req, res) {
|
||||||
|
const { adminId } = res.locals.user;
|
||||||
|
if (!adminId) return res.json({ code: 1, msg: '非法访问' });
|
||||||
const { pageSize = 0, pageIndex = 1} = req.query;
|
const { pageSize = 0, pageIndex = 1} = req.query;
|
||||||
return Ticket.find().skip((+pageIndex - 1) * +pageSize).limit(+pageSize).then(data => {
|
return Ticket.find({}).skip((+pageIndex - 1) * +pageSize).limit(+pageSize).then(data => {
|
||||||
return res.json({
|
return res.json({
|
||||||
code: 0,
|
code: 0,
|
||||||
data
|
data
|
||||||
@@ -46,6 +49,8 @@ module.exports = {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
async getTicketDetail (req, res) {
|
async getTicketDetail (req, res) {
|
||||||
|
const { adminId } = res.locals.user;
|
||||||
|
if (!adminId) return res.json({ code: 1, msg: '非法访问' });
|
||||||
const { ticketId } = req.query;
|
const { ticketId } = req.query;
|
||||||
return Ticket.findById(ticketId).then(data => {
|
return Ticket.findById(ticketId).then(data => {
|
||||||
return res.json({
|
return res.json({
|
||||||
|
|||||||
@@ -19,17 +19,15 @@ function createTicket (name, data) {
|
|||||||
|
|
||||||
async function handleTicket (ticket, handlerId) {
|
async function handleTicket (ticket, handlerId) {
|
||||||
// 所有工单在此处理,只要状态未完结(status !== 'finished'),就可以多次调用改变状态。
|
// 所有工单在此处理,只要状态未完结(status !== 'finished'),就可以多次调用改变状态。
|
||||||
const { userId, status } = ticket;
|
|
||||||
const user = await User.findById(userId).exec();
|
|
||||||
if (!user) return null;
|
|
||||||
ticket = await ticket.next(handlerId);
|
ticket = await ticket.next(handlerId);
|
||||||
if (status === 'processing') {
|
if (ticket.status === 'processing') {
|
||||||
await dealTicket(ticket, user);
|
await dealTicket(ticket);
|
||||||
await ticket.next(handlerId);
|
await ticket.next(handlerId);
|
||||||
return ticket;
|
return ticket;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function dealTicket (ticket, user) {
|
async function dealTicket (ticket, user) {
|
||||||
if (ticket.type === 0) {
|
if (ticket.type === 0) {
|
||||||
// 提现
|
// 提现
|
||||||
@@ -37,12 +35,13 @@ async function dealTicket (ticket, user) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function dealWithdraw (ticket, user) {
|
async function dealWithdraw (ticket) {
|
||||||
// userId, amount: +amount, action, targetAddress
|
// userId, amount: +amount, action, targetAddress
|
||||||
const { userId, amount, targetAddress, coinId } = ticket;
|
const { userId, amount, targetAddress, coinId } = ticket;
|
||||||
const fund = await Fund.findOne({ userId }).exec();
|
if (coinId === 'vic') {
|
||||||
const { path } = fund.tokenAddress['usdtETH'];
|
const res = await sendVIC2User(targetAddress, amount);
|
||||||
return coinId === 'usdt' ? sendUSDT2User(targetAddress, amount, {path}) : sendVIC2User(targetAddress, amount)
|
if (res.success) return { code: 0, msg: '处理成功' };
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ const { inject } = require('../common/Provider');
|
|||||||
const { verifyToken, createToken } = require('../utils/jwt');
|
const { verifyToken, createToken } = require('../utils/jwt');
|
||||||
const crypto = require('../utils/crypto');
|
const crypto = require('../utils/crypto');
|
||||||
|
|
||||||
const ignoreToken = ['/sign/check', '/sign/in', '/sign/up', '/sign/upwi', '/sign/forget', '/sign/send', '/sign/changePwd', '/sign/code'];
|
const ignoreToken = ['/sign/check', '/sign/in', '/sign/up', '/sign/upwi', '/sign/forget', '/sign/send', '/sign/changePwd', '/sign/code', '/admin/api/signin'];
|
||||||
module.exports = {
|
module.exports = {
|
||||||
auth: inject(function (SysConfig) {
|
auth: inject(function (SysConfig) {
|
||||||
const { JWT_SECRET } = SysConfig;
|
const { JWT_SECRET } = SysConfig;
|
||||||
|
|||||||
Reference in New Issue
Block a user