Commit d17c3fd2 authored by ml's avatar ml

金融部-账户管理相关

parent d7ff4690
......@@ -85,4 +85,7 @@ export const ErrorCode = {
STATUS_PASS_NO_UP:'30081',//审核已通过,不允许修改
AFTER_AUDIT_SUBMIT:'30082',//请先审核,再提交
PWD_FORMAT_ERR:'30083',//密码格式错误
CATEGORY_HAVE_ACCOUNT:'30084',//该分类下有账户,不可以删除
CATEGORY_HAVE_SAME_ACCOUNT:'30085',//该分类下存在相同账户
ACCOUNT_HAVE_INIT_ASSET:'30086',//该账户下存在初始资金记录,不允许删除
}
import * as financeAccountService from "../service/fianceAccount.service";
import { FinanceAccountVO, FinanceAccountPageVO } from "../service/fianceAccount.service";
import { FinanceAccountVO, FinanceAccountPageVO, AccountInitAssetVO } from "../service/fianceAccount.service";
let { logger, Res3Utils, optionalUtils: Optional, apiAssertUtils: ApiAssert, datetimeUtils } = require('@madex/ex-js-public');
......@@ -95,9 +95,59 @@ export const del = async (req: any, financeAccountVO: FinanceAccountVO) => {
}
};
/**
* 添加初始资金
* @param req
* @param authConfigVO
*/
export const addInitAsset = async (req: any, accountInitAssetVO: AccountInitAssetVO) => {
let func_name = "financeAccount.control.addInitAsset";
try {
let ip = isIp(req.ip) ? req.ip : '*.*.*.*';
let currentUserId = await getCurrentUserId(req.cookies.session_id);
if (!accountInitAssetVO.account_id || !accountInitAssetVO.symbol ||
!accountInitAssetVO.amount_usdt ||
!accountInitAssetVO.amount ||
Number(accountInitAssetVO.amount_usdt) < 0 ||
Number(accountInitAssetVO.amount) < 0) {
throw ErrorCode.PARAM_MISS;
}
let res = await financeAccountService.addInitAsset(accountInitAssetVO, currentUserId, ip);
return Res3Utils.result(res);
}
catch (e) {
logger.error(`${func_name} error:${e}`);
return Res3Utils.getErrorResult(e);
}
};
/**
* 初始资金列表
* @param req
* @param authConfigVO
*/
export const initAssetList = async (req: any, pageVO: FinanceAccountPageVO) => {
let func_name = "financeAccount.control.initAssetList";
try {
pageVO.page = Optional.opt(pageVO, 'page', 1);
pageVO.size = Optional.opt(pageVO, 'size', 20);
if (!pageVO.account_id) {
throw ErrorCode.PARAM_MISS;
}
let res = await financeAccountService.initAssetList(pageVO);
return Res3Utils.result(res);
}
catch (e) {
logger.error(`${func_name} error:${e}`);
return Res3Utils.getErrorResult(e);
}
};
async function paramValid(financeAccountVO: FinanceAccountVO) {
if (!financeAccountVO.account || !financeAccountVO.init_asset || !financeAccountVO.apikey ||
!financeAccountVO.secret || !financeAccountVO.secret_pwd ||
if (!financeAccountVO.category_id || !financeAccountVO.account || !financeAccountVO.apikey ||
!financeAccountVO.secret || !financeAccountVO.pwd ||
!financeAccountVO.platform) {
throw ErrorCode.PARAM_MISS;
}
......
import * as categoryService from "../service/fianceAccountCategory.service";
import { FinanceAccountCategoryVO, FinanceAccountCategoryPageVO } from "../service/fianceAccountCategory.service";
let { logger, Res3Utils, optionalUtils: Optional, apiAssertUtils: ApiAssert, datetimeUtils } = require('@madex/ex-js-public');
import { ErrorCode } from "../../../constant/errorCode";
import { getCurrentUserId } from "../../../utils/aclUserUtils";
import { coinType, contractPairs, spotPairs } from "@madex/ex-ts-dao";
let isIp = require('is-ip');
/**
* 分类列表
* @param req
* @param infoVO
*/
export const list = async (req: any, pageVO: FinanceAccountCategoryPageVO) => {
let func_name = "financeAccountCategory.control.list";
try {
pageVO.page = Optional.opt(pageVO, 'page', 1);
pageVO.size = Optional.opt(pageVO, 'size', 20);
let res = await categoryService.list(pageVO);
return Res3Utils.result(res);
}
catch (e) {
logger.error(`${func_name} error:${e}`);
return Res3Utils.getErrorResult(e);
}
};
/**
* 添加新的分类
* @param req
* @param authConfigVO
*/
export const add = async (req: any, financeAccountCategoryVO: FinanceAccountCategoryVO) => {
let func_name = "financeAccountCategory.control.add";
try {
let ip = isIp(req.ip) ? req.ip : '*.*.*.*';
let currentUserId = await getCurrentUserId(req.cookies.session_id);
await paramValid(financeAccountCategoryVO);
let res = await categoryService.add(financeAccountCategoryVO, currentUserId, ip);
return Res3Utils.result(res);
}
catch (e) {
logger.error(`${func_name} error:${e}`);
return Res3Utils.getErrorResult(e);
}
};
/**
* 修改分类
* @param req
* @param authConfigVO
*/
export const update = async (req: any, financeAccountCategoryVO: FinanceAccountCategoryVO) => {
let func_name = "financeAccountCategory.control.update";
try {
let ip = isIp(req.ip) ? req.ip : '*.*.*.*';
let currentUserId = await getCurrentUserId(req.cookies.session_id);
if (!financeAccountCategoryVO.id) {
throw ErrorCode.PARAM_MISS
}
await paramValid(financeAccountCategoryVO);
let res = await categoryService.update(financeAccountCategoryVO, currentUserId, ip);
return Res3Utils.result(res);
}
catch (e) {
logger.error(`${func_name} error:${e}`);
return Res3Utils.getErrorResult(e);
}
};
/**
* 删除分类
* @param req
* @param authConfigVO
*/
export const del = async (req: any, financeAccountCategoryVO: FinanceAccountCategoryVO) => {
let func_name = "financeAccountCategory.control.del";
try {
let ip = isIp(req.ip) ? req.ip : '*.*.*.*';
let currentUserId = await getCurrentUserId(req.cookies.session_id);
if (!financeAccountCategoryVO.id) {
throw ErrorCode.PARAM_MISS
}
let res = await categoryService.del(financeAccountCategoryVO.id, currentUserId, ip);
return Res3Utils.result(res);
}
catch (e) {
logger.error(`${func_name} error:${e}`);
return Res3Utils.getErrorResult(e);
}
};
async function paramValid(financeAccountCategoryVO: FinanceAccountCategoryVO) {
if (!financeAccountCategoryVO.name) {
throw ErrorCode.PARAM_MISS;
}
}
import { financeMarketAccount, ormDB, } from "@madex/ex-ts-dao";
import { financeAccount, ormDB, financeAccountInitAsset, financeAccountCategory } from "@madex/ex-ts-dao";
import { ErrorCode } from "../../../constant/errorCode";
import { addOptLog } from "./userOptLog.service";
......@@ -10,17 +10,19 @@ let { logger } = require('@madex/ex-js-public');
export interface FinanceAccountVO {
id?: number;
category_id?: number;
uid?: number;
account?: string | any;
remark?: string | any;
init_asset?: number;
apikey?: string | any;
secret?: string | any;
secret_pwd?: string | any;
pwd?: string | any;
platform?: number;
......@@ -33,33 +35,74 @@ export interface FinanceAccountVO {
}
export interface FinanceAccountPageVO extends FinanceAccountVO {
export interface FinanceAccountPageVO extends FinanceAccountVO, AccountInitAssetVO {
page?: number,
size?: number,
}
export interface AccountInitAssetVO {
id?: number;
account_id?: number;
symbol?: string | any;
amount?: number;
amount_usdt?: number;
remark?: string | any;
createdAt?: Date | any,
updatedAt?: Date | any,
}
export async function list(pageVO: FinanceAccountPageVO) {
let where = {};
let where = {
category_id: pageVO.category_id
};
let resList = await financeMarketAccount.prototype.findAndCount({
let resList = await financeAccount.prototype.findAndCount({
where: where,
limit: pageVO.size,
offset: (Number(pageVO.page) - 1) * Number(pageVO.size),
order: [["id", "asc"]],
raw: true
});
if (resList.rows.length) {
let cids = resList.rows.map(item => item.category_id);
let cList = await financeAccountCategory.prototype.findAll({
where: {
id: cids
},
raw: true
});
let tmpMap: any = {};
for (let item of cList) {
tmpMap[item.id] = item.name;
}
for (let item of resList.rows) {
item.category_name = tmpMap[item.category_id] ? tmpMap[item.category_id] : ""
}
}
return resList;
}
export async function add(financeAccountVO: FinanceAccountVO, currentUserId: any, ip: any) {
let dbOne = await financeMarketAccount.prototype.findOne({
let dbOne = await financeAccount.prototype.findOne({
where: {
account: financeAccountVO.account
category_id: financeAccountVO.category_id,
apikey: financeAccountVO.apikey
},
raw: true
});
......@@ -74,7 +117,7 @@ export async function add(financeAccountVO: FinanceAccountVO, currentUserId: any
financeAccountVO.status = 1;
}
await financeMarketAccount.prototype.create(financeAccountVO);
await financeAccount.prototype.create(financeAccountVO);
//管理后台操作日志
addOptLog(currentUserId, 0, '新增账户', ip, JSON.stringify(financeAccountVO), '金融部-其他管理');
return 'success';
......@@ -82,7 +125,7 @@ export async function add(financeAccountVO: FinanceAccountVO, currentUserId: any
export async function update(financeAccountVO: FinanceAccountVO, currentUserId: any, ip: any) {
let exist = await financeMarketAccount.prototype.findOne({
let exist = await financeAccount.prototype.findOne({
where: {
id: financeAccountVO.id
},
......@@ -92,21 +135,22 @@ export async function update(financeAccountVO: FinanceAccountVO, currentUserId:
throw ErrorCode.DATA_NOT_EXIST
}
let dbOne = await financeMarketAccount.prototype.findOne({
let dbOne = await financeAccount.prototype.findOne({
where: {
account: financeAccountVO.account,
category_id: financeAccountVO.category_id,
apikey: financeAccountVO.apikey,
id: { [ormDB.Op.ne]: financeAccountVO.id }
},
raw: true
});
if (dbOne) {
throw ErrorCode.DATA_EXIST;
throw ErrorCode.CATEGORY_HAVE_SAME_ACCOUNT;
}
financeAccountVO.updatedAt = new Date();
await financeMarketAccount.prototype.update(financeAccountVO, {
await financeAccount.prototype.update(financeAccountVO, {
where: {
id: Number(financeAccountVO.id)
}
......@@ -119,7 +163,7 @@ export async function update(financeAccountVO: FinanceAccountVO, currentUserId:
}
export async function del(id: number, currentUserId: any, ip: string | undefined) {
let exist = await financeMarketAccount.prototype.findOne({
let exist = await financeAccount.prototype.findOne({
where: {
id: id
},
......@@ -129,7 +173,18 @@ export async function del(id: number, currentUserId: any, ip: string | undefined
throw ErrorCode.DATA_NOT_EXIST
}
await financeMarketAccount.prototype.destroy({
let dbInitAsset = await financeAccountInitAsset.prototype.findOne({
where: {
account_id: id
},
raw: true
});
if (dbInitAsset) {
throw ErrorCode.ACCOUNT_HAVE_INIT_ASSET
}
await financeAccount.prototype.destroy({
where: {
id: id
}
......@@ -141,5 +196,51 @@ export async function del(id: number, currentUserId: any, ip: string | undefined
return 'success';
}
export async function addInitAsset(accountInitAssetVO: AccountInitAssetVO, currentUserId: any, ip: any) {
accountInitAssetVO.createdAt = new Date();
accountInitAssetVO.updatedAt = new Date();
await financeAccountInitAsset.prototype.create(accountInitAssetVO);
//管理后台操作日志
addOptLog(currentUserId, 0, '新增初始资金', ip, JSON.stringify(accountInitAssetVO), '金融部-其他管理');
return 'success';
}
export async function initAssetList(pageVO: FinanceAccountPageVO) {
let where = {
account_id: pageVO.account_id
};
let resList = await financeAccountInitAsset.prototype.findAndCount({
where: where,
limit: pageVO.size,
offset: (Number(pageVO.page) - 1) * Number(pageVO.size),
order: [["createdAt", "desc"]],
raw: true
});
if (resList.rows.length) {
let aids = resList.rows.map(item => item.account_id);
let aList = await financeAccount.prototype.findAll({
where: {
id: aids
},
raw: true
});
let tmpMap: any = {};
for (let item of aList) {
tmpMap[item.id] = item.account;
}
for (let item of resList.rows) {
item.account_name = tmpMap[item.account_id] ? tmpMap[item.account_id] : ""
}
}
return resList;
}
import { financeAccountCategory, ormDB, financeAccount } from "@madex/ex-ts-dao";
import { ErrorCode } from "../../../constant/errorCode";
import { addOptLog } from "./userOptLog.service";
let _ = require('lodash');
let { logger } = require('@madex/ex-js-public');
export interface FinanceAccountCategoryVO {
id?: number;
name?: string | any;
remark?: string | any;
createdAt?: Date | any,
updatedAt?: Date | any,
}
export interface FinanceAccountCategoryPageVO extends FinanceAccountCategoryVO {
page?: number,
size?: number,
}
export async function list(pageVO: FinanceAccountCategoryPageVO) {
let where = {};
let resList = await financeAccountCategory.prototype.findAndCount({
where: where,
limit: pageVO.size,
offset: (Number(pageVO.page) - 1) * Number(pageVO.size),
order: [["id", "asc"]],
raw: true
});
return resList;
}
export async function add(financeAccountCategoryVO: FinanceAccountCategoryVO, currentUserId: any, ip: any) {
financeAccountCategoryVO.createdAt = new Date();
financeAccountCategoryVO.updatedAt = new Date();
await financeAccountCategory.prototype.create(financeAccountCategoryVO);
//管理后台操作日志
addOptLog(currentUserId, 0, '新增账户分类', ip, JSON.stringify(financeAccountCategoryVO), '金融部-其他管理');
return 'success';
}
export async function update(financeAccountCategoryVO: FinanceAccountCategoryVO, currentUserId: any, ip: any) {
let exist = await financeAccountCategory.prototype.findOne({
where: {
id: financeAccountCategoryVO.id
},
raw: true
});
if (!exist) {
throw ErrorCode.DATA_NOT_EXIST
}
financeAccountCategoryVO.updatedAt = new Date();
await financeAccountCategory.prototype.update(financeAccountCategoryVO, {
where: {
id: Number(financeAccountCategoryVO.id)
}
})
//管理后台操作日志
addOptLog(currentUserId, 0, '修改账户分类', ip, JSON.stringify(financeAccountCategoryVO), '金融部-其他管理');
return 'success';
}
export async function del(id: number, currentUserId: any, ip: string | undefined) {
let exist = await financeAccountCategory.prototype.findOne({
where: {
id: id
},
raw: true
});
if (!exist) {
throw ErrorCode.DATA_NOT_EXIST
}
//分类下有账户 不可以删除
let dbAccount = await financeAccount.prototype.findOne({
where: {
category_id: id
},
raw: true
});
if (dbAccount) {
throw ErrorCode.CATEGORY_HAVE_ACCOUNT;
}
await financeAccountCategory.prototype.destroy({
where: {
id: id
}
})
//管理后台操作日志
addOptLog(currentUserId, 0, '删除账户分类', ip, `id:${id}`, '金融部-其他管理');
return 'success';
}
......@@ -53,6 +53,7 @@ import * as exBusinessAreaCtrl from "../../mvc/control/exBusinessArea.control";
import * as rewardTimePeriodCtrl from "../../mvc/control/rewardTimePeriod.control";
import * as collateralCtrl from "../../mvc/control/collateral.control";
import * as fianceAccountCtrl from "../../mvc/control/fianceAccount.control";
import * as fianceAccountCategoryCtrl from "../../mvc/control/fianceAccountCategory.control";
const getFunc = {
'user/info': userController.getUserInfo,
......@@ -306,11 +307,22 @@ const postFunc = {
'tech/other/reward/time/period/set': rewardTimePeriodCtrl.set,
'tech/other/reward/time/period/get': rewardTimePeriodCtrl.get,
//金融部-其他管理-账户管理
'fiance/other/account/category/list': fianceAccountCategoryCtrl.list,
'fiance/other/account/category/add': fianceAccountCategoryCtrl.add,
'fiance/other/account/category/update': fianceAccountCategoryCtrl.update,
'fiance/other/account/category/del': fianceAccountCategoryCtrl.del,
'fiance/other/account/list': fianceAccountCtrl.list,
'fiance/other/account/add': fianceAccountCtrl.add,
'fiance/other/account/update': fianceAccountCtrl.update,
'fiance/other/account/del': fianceAccountCtrl.del,
'fiance/other/account/addInitAsset': fianceAccountCtrl.addInitAsset,
'fiance/other/account/initAssetList': fianceAccountCtrl.initAssetList,
};
// TODO 这里先和 nodejs 的注册路由方式保持一样,后面在调整。
......
......@@ -240,10 +240,16 @@ let cmdWhiteList = {
'tech/other/reward/time/period/set': 1,
'tech/other/reward/time/period/get': 1,
//金融部-其他管理-账户管理
'fiance/other/account/category/list': 1,
'fiance/other/account/category/add': 1,
'fiance/other/account/category/update': 1,
'fiance/other/account/category/del': 1,
'fiance/other/account/list': 1,
'fiance/other/account/add': 1,
'fiance/other/account/update': 1,
'fiance/other/account/del': 1,
'fiance/other/account/addInitAsset': 1,
'fiance/other/account/initAssetList': 1,
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment