Commit 94108a6a authored by ml's avatar ml

费率管理调整为VIP管理、相关逻辑调整、增加市商费率逻辑

parent 72108c1a
...@@ -47,7 +47,7 @@ export const ErrorCode = { ...@@ -47,7 +47,7 @@ export const ErrorCode = {
LEVEL_NOT_EXIST:'30043',//指定等级不存在 LEVEL_NOT_EXIST:'30043',//指定等级不存在
ONLY_ONE_FEE:'30044',//只能有一条未提交的费率设置 ONLY_ONE_FEE:'30044',//只能有一条未提交的费率设置
ONLY_UN_SUBMIT_UPDATE:'30045',//只有未提交的记录可以修改 ONLY_UN_SUBMIT_UPDATE:'30045',//只有未提交的记录可以修改
UID_TYPE_NOT_UPDATE:'30046',//用户ID和类型不能修改 UID_TYPE_NOT_UPDATE:'30046',//用户ID、费率类型、交易对不能修改
DEL_UN_SUBMIT_ACTIVE:'30047',//只能删除未提交或未生效的记录 DEL_UN_SUBMIT_ACTIVE:'30047',//只能删除未提交或未生效的记录
FEE_USED_NOT_DEL:'30048',//费率已生效,不能删除 FEE_USED_NOT_DEL:'30048',//费率已生效,不能删除
ONLY_UN_SUBMIT_CAN_SUBMIT:'30049',//只有未提交的记录才能提交 ONLY_UN_SUBMIT_CAN_SUBMIT:'30049',//只有未提交的记录才能提交
...@@ -57,8 +57,8 @@ export const ErrorCode = { ...@@ -57,8 +57,8 @@ export const ErrorCode = {
PWD_ILLEGAL:'30053',//密码过短或过长 PWD_ILLEGAL:'30053',//密码过短或过长
FIXED_AND_DEFAULT:'30054',//固定和默认不能同时为是 FIXED_AND_DEFAULT:'30054',//固定和默认不能同时为是
NOT_HIDDEN_TWO:'30055',//每种语言非隐藏并且固定的至少要有2个 NOT_HIDDEN_TWO:'30055',//每种语言非隐藏并且固定的至少要有2个
COIN_TYPE_NOT_EXIST:'30056',//指定币种不存在 COIN_TYPE_NOT_EXIST:'30056',//币种不存在
PAIR_NOT_EXIST:'30057',//指定币对不存在 PAIR_NOT_EXIST:'30057',//币对不存在
LIMIT_ERROR:'30058',//limit参数必须在10-2000之间 LIMIT_ERROR:'30058',//limit参数必须在10-2000之间
ADD_PAIR_TO_CORE_ERR:'30059',//币种/交易对提交到撮合失败 ADD_PAIR_TO_CORE_ERR:'30059',//币种/交易对提交到撮合失败
SUBMIT_STATUS_ERR:'30060',//请确认提交状态 SUBMIT_STATUS_ERR:'30060',//请确认提交状态
...@@ -70,7 +70,9 @@ export const ErrorCode = { ...@@ -70,7 +70,9 @@ export const ErrorCode = {
DEPOSIT_WITHDRAW_TM_EXPIRE:'30066',//开放充值时间/开放提现时间过短 DEPOSIT_WITHDRAW_TM_EXPIRE:'30066',//开放充值时间/开放提现时间过短
CURRENT_STATUS_NOT_APPLY:'30067',//当前状态不可以审核 CURRENT_STATUS_NOT_APPLY:'30067',//当前状态不可以审核
CURRENT_COIN_DATA_NOT_EXIST:'30068',//币种管理中计价币种不存在 CURRENT_COIN_DATA_NOT_EXIST:'30068',//币种管理中计价币种不存在
PAIR_EXIST:'30069',//交易对已存在 PAIR_EXIST:'30069',//交易对已存在
ACTIVE_TM_EXPIRE:'30070',//交易时间过短 ACTIVE_TM_EXPIRE:'30070',//交易时间过短
NO_TRIGGER_DEL:'30071',//只有未触发的任务可以删除 NO_TRIGGER_DEL:'30071',//只有未触发的任务可以删除
EXIST_ACTIVE_PAIR:'30072',//已存在生效或即将生效的该交易对费率配置
FEE_EX_OR_DEL:'30073',//费率设置已过期或已删除,不可以修改
} }
export const FEE_TYPE = { export const FEE_TYPE = {
/**
* 费率类型: 全部。
*/
FEE_TYPE_ALL: 0,
/** /**
* 费率类型: 币币。 * 费率类型: 币币。
...@@ -17,20 +13,11 @@ export const FEE_TYPE = { ...@@ -17,20 +13,11 @@ export const FEE_TYPE = {
* 费率类型: 币本位合约。 * 费率类型: 币本位合约。
*/ */
FEE_TYPE_BASE_COIN_CONTRACT: 3, FEE_TYPE_BASE_COIN_CONTRACT: 3,
/**
* 费率类型: 合约(U本位+币本位)
*/
FEE_TYPE_CONTRACT_ALL: 5,
} }
export const FEE_TYPE_LIST = [FEE_TYPE.FEE_TYPE_ALL, FEE_TYPE.FEE_TYPE_SPOT, FEE_TYPE.FEE_TYPE_CONTRACT, FEE_TYPE.FEE_TYPE_BASE_COIN_CONTRACT, FEE_TYPE.FEE_TYPE_CONTRACT_ALL,] export const FEE_TYPE_LIST = [FEE_TYPE.FEE_TYPE_SPOT, FEE_TYPE.FEE_TYPE_CONTRACT, FEE_TYPE.FEE_TYPE_BASE_COIN_CONTRACT]
export const FEE_STATUS = { export const FEE_STATUS = {
/**
* 费率设置纪录状态: 未提交。
*/
STATUS_FEE_SETTING_NEW: 0,
/** /**
* 费率设置纪录状态: 已提交。 * 费率设置纪录状态: 已提交。
*/ */
...@@ -53,3 +40,15 @@ export const FEE_STATUS = { ...@@ -53,3 +40,15 @@ export const FEE_STATUS = {
* 普通用户手续费提交备注。 * 普通用户手续费提交备注。
*/ */
export const COMMENT_USER_FEE_SUBMIT = "提交普通用户手续费"; export const COMMENT_USER_FEE_SUBMIT = "提交普通用户手续费";
/**
* 市商手续费提交备注。
*/
export const COMMENT_MAKER_FEE_SUBMIT = "提交市商手续费";
/**
* KOL手续费提交备注。
*/
export const COMMENT_KOL_FEE_SUBMIT = "提交KOL手续费";
\ No newline at end of file
...@@ -65,7 +65,11 @@ export const update = async (req: any, commonUserFeeVO: CommonUserFeeVO) => { ...@@ -65,7 +65,11 @@ export const update = async (req: any, commonUserFeeVO: CommonUserFeeVO) => {
try { try {
let ip = isIp(req.ip) ? req.ip : '*.*.*.*'; let ip = isIp(req.ip) ? req.ip : '*.*.*.*';
let currentUserId = await getCurrentUserId(req.cookies.session_id); let currentUserId = await getCurrentUserId(req.cookies.session_id);
await updateParamValid(commonUserFeeVO); if (!commonUserFeeVO.id){
throw ErrorCode.PARAM_MISS;
}
await addParamValid(commonUserFeeVO);
let res = await commonUserFeeSettingService.update(commonUserFeeVO, currentUserId, ip); let res = await commonUserFeeSettingService.update(commonUserFeeVO, currentUserId, ip);
return Res3Utils.result(res); return Res3Utils.result(res);
...@@ -99,27 +103,6 @@ export const del = async (req: any, commonUserFeeVO: CommonUserFeeVO) => { ...@@ -99,27 +103,6 @@ export const del = async (req: any, commonUserFeeVO: CommonUserFeeVO) => {
}; };
/**
* 提交用户费率
* @param req
* @param authConfigVO
*/
export const submit = async (req: any, commonUserFeeVO: CommonUserFeeVO) => {
let func_name = "commonUserFeeSetting.control.submit";
try {
let ip = isIp(req.ip) ? req.ip : '*.*.*.*';
let currentUserId = await getCurrentUserId(req.cookies.session_id);
if (!commonUserFeeVO.id) {
throw ErrorCode.PARAM_MISS
}
let res = await commonUserFeeSettingService.submit(commonUserFeeVO.id, currentUserId, ip);
return Res3Utils.result(res);
}
catch (e) {
logger.error(`${func_name} error:${e}`);
return Res3Utils.getErrorResult(e);
}
};
/** /**
* 用户等级费率列表 * 用户等级费率列表
...@@ -145,11 +128,15 @@ async function addParamValid(commonUserFeeVO: CommonUserFeeVO) { ...@@ -145,11 +128,15 @@ async function addParamValid(commonUserFeeVO: CommonUserFeeVO) {
let expireTime = commonUserFeeVO.expire_time; let expireTime = commonUserFeeVO.expire_time;
let type = commonUserFeeVO.type; let type = commonUserFeeVO.type;
let levelId = commonUserFeeVO.level_id; let levelId = commonUserFeeVO.level_id;
let pair = commonUserFeeVO.pair;
let applicant = commonUserFeeVO.applicant;
let makerFee = commonUserFeeVO.maker_fee;
let takerFee = commonUserFeeVO.taker_fee;
if (!userId || !beginTime || !expireTime) { if (!userId || !beginTime || !expireTime || !pair || !applicant || !makerFee || !takerFee) {
throw ErrorCode.PARAM_MISS; throw ErrorCode.PARAM_MISS;
} }
await checkMaker(commonUserFeeVO);
await paramCheck(beginTime, expireTime, Number(type), userId); await paramCheck(beginTime, expireTime, Number(type), userId);
if (levelId) { if (levelId) {
...@@ -162,25 +149,18 @@ async function addParamValid(commonUserFeeVO: CommonUserFeeVO) { ...@@ -162,25 +149,18 @@ async function addParamValid(commonUserFeeVO: CommonUserFeeVO) {
if (!vipLevelSetting) { if (!vipLevelSetting) {
throw ErrorCode.LEVEL_NOT_EXIST; throw ErrorCode.LEVEL_NOT_EXIST;
} }
commonUserFeeVO.spot_maker_fee = vipLevelSetting.spot_maker; if (type == FEE_TYPE.FEE_TYPE_SPOT) {
commonUserFeeVO.spot_taker_fee = vipLevelSetting.spot_taker; commonUserFeeVO.maker_fee = vipLevelSetting.spot_maker;
commonUserFeeVO.contract_maker_fee = vipLevelSetting.contract_maker; commonUserFeeVO.taker_fee = vipLevelSetting.spot_taker;
commonUserFeeVO.contract_taker_fee = vipLevelSetting.contract_taker;
return;
} }
else {
if ((type == FEE_TYPE.FEE_TYPE_ALL || type == FEE_TYPE.FEE_TYPE_SPOT) commonUserFeeVO.maker_fee = vipLevelSetting.contract_maker;
&& (!commonUserFeeVO.spot_maker_fee || !commonUserFeeVO.spot_taker_fee)) { commonUserFeeVO.taker_fee = vipLevelSetting.contract_taker;
throw ErrorCode.SPOT_FEE_NEED_SET;
} }
return;
if ((type == FEE_TYPE.FEE_TYPE_ALL || type == FEE_TYPE.FEE_TYPE_CONTRACT_ALL
|| type == FEE_TYPE.FEE_TYPE_CONTRACT || type == FEE_TYPE.FEE_TYPE_BASE_COIN_CONTRACT)
&& (!commonUserFeeVO.contract_maker_fee || !commonUserFeeVO.contract_taker_fee)) {
throw ErrorCode.CONTRACT_FEE_NEED_SET;
} }
let user = await getMUserInfoByUid(userId); let user = await getMUserInfoByUid(userId);
if (!user || user.deleted_flag == 1) { if (!user || user.deleted_flag == 1) {
throw ErrorCode.USER_NOT_EXIST; throw ErrorCode.USER_NOT_EXIST;
...@@ -194,22 +174,6 @@ async function addParamValid(commonUserFeeVO: CommonUserFeeVO) { ...@@ -194,22 +174,6 @@ async function addParamValid(commonUserFeeVO: CommonUserFeeVO) {
} }
async function updateParamValid(commonUserFeeVO: CommonUserFeeVO) {
let id = commonUserFeeVO.id;
let userId = commonUserFeeVO.user_id;
let beginTime = commonUserFeeVO.begin_time;
let expireTime = commonUserFeeVO.expire_time;
let type = commonUserFeeVO.type;
let makerFee = commonUserFeeVO.maker_fee;
let takerFee = commonUserFeeVO.taker_fee;
if (!id || !userId || !beginTime || !expireTime || !makerFee || !takerFee) {
throw ErrorCode.PARAM_MISS;
}
await paramCheck(beginTime, expireTime, Number(type), userId);
}
/** /**
* 添加和更新校验入参 * 添加和更新校验入参
* @param beginTime * @param beginTime
...@@ -242,23 +206,24 @@ async function paramCheck(beginTime: any, expireTime: any, type: number, userId: ...@@ -242,23 +206,24 @@ async function paramCheck(beginTime: any, expireTime: any, type: number, userId:
throw ErrorCode.COIN_NO_ASSETS; throw ErrorCode.COIN_NO_ASSETS;
} }
} }
else if (type == FEE_TYPE.FEE_TYPE_CONTRACT_ALL) {
if (!await baseUCheck(userId)) { }
throw ErrorCode.U_NO_ASSETS;
} async function checkMaker(commonUserFeeVO: CommonUserFeeVO) {
if (!await baseCoinCheck(userId)) { let userChannel = commonUserFeeVO.user_channel;
throw ErrorCode.COIN_NO_ASSETS; if (!userChannel) {
} throw ErrorCode.PARAM_MISS
}
else if (type == FEE_TYPE.FEE_TYPE_ALL) {
if (!await spotCheck(userId)) {
throw ErrorCode.SPOT_NO_ASSETS;
} }
if (!await baseUCheck(userId)) { //项目方
throw ErrorCode.U_NO_ASSETS; if (userChannel == 2) {
//TODO:校验该用户是不是市商
let statisPeriod = commonUserFeeVO.statis_period;
let amount_require_usdt = commonUserFeeVO.amount_require_usdt;
if (!statisPeriod || Number(statisPeriod) < 0 || Number(statisPeriod) > 30) {
throw ErrorCode.PARAM_MISS;
} }
if (!await baseCoinCheck(userId)) { if (!amount_require_usdt) {
throw ErrorCode.COIN_NO_ASSETS; throw ErrorCode.PARAM_MISS;
} }
} }
} }
\ No newline at end of file
import { ormDB, usefulLink, commonUserFeeSetting, feeRateContractLog, feeRateBaseCoinContractLog, feeRateSpotLog, vipLevelFeeSetting } from "@madex/ex-ts-dao"; import {
ormDB,
usefulLink,
commonUserFeeSetting,
feeRateContractLog,
feeRateBaseCoinContractLog,
feeRateSpotLog,
vipLevelFeeSetting,
spotPairs, madSpotOrmDB, contractPairs, madContractOrmDB
} from "@madex/ex-ts-dao";
import { ErrorCode } from "../../../constant/errorCode"; import { ErrorCode } from "../../../constant/errorCode";
import { addOptLog } from "./userOptLog.service"; import { addOptLog } from "./userOptLog.service";
import { COMMENT_USER_FEE_SUBMIT, FEE_STATUS, FEE_TYPE } from "../../../constant/marketMakerConst"; import { COMMENT_KOL_FEE_SUBMIT, COMMENT_MAKER_FEE_SUBMIT, COMMENT_USER_FEE_SUBMIT, FEE_STATUS, FEE_TYPE } from "../../../constant/marketMakerConst";
import { SYMBOL_ALL } from "../../../constant/symbolConst"; import { SYMBOL_ALL } from "../../../constant/symbolConst";
import * as feeRateSpotLogService from "./feeRateSpotLog.service"; import * as feeRateSpotLogService from "./feeRateSpotLog.service";
import * as feeRateContractLogService from "./feeRateContractLog.service"; import * as feeRateContractLogService from "./feeRateContractLog.service";
import * as feeRateBaseCoinContractLogService from "./feeRateBaseCoinContractLog.service"; import * as feeRateBaseCoinContractLogService from "./feeRateBaseCoinContractLog.service";
import { FEE_MODEL_SPOT_DEFAULT, FEE_RATE_LOG_STATUS } from "../../../constant/feeRateLogConst"; import { FEE_MODEL_SPOT_DEFAULT, FEE_RATE_LOG_STATUS } from "../../../constant/feeRateLogConst";
import { where } from "sequelize";
import { it } from "node:test";
let _ = require('lodash'); let _ = require('lodash');
let { logger } = require('@madex/ex-js-public'); let { logger, datetimeUtils } = require('@madex/ex-js-public');
let { redisUtilsCommon: RedisClient, } = require('@madex/ex-js-common');
export interface CommonUserFeeVO { export interface CommonUserFeeVO {
...@@ -49,13 +61,15 @@ export interface CommonUserFeeVO { ...@@ -49,13 +61,15 @@ export interface CommonUserFeeVO {
level_id?: number; level_id?: number;
spot_maker_fee?: number; user_channel?: number;
spot_taker_fee?: number; statis_period?: number;
amount_require_usdt?: number;
applicant?: string;
contract_maker_fee?: number;
contract_taker_fee?: number;
} }
...@@ -71,24 +85,33 @@ export interface CommonUserFeePageVO extends CommonUserFeeVO { ...@@ -71,24 +85,33 @@ export interface CommonUserFeePageVO extends CommonUserFeeVO {
export async function list(pageVO: CommonUserFeePageVO) { export async function list(pageVO: CommonUserFeePageVO) {
let where = {};
//即将过期 前端入参 = 5 单独处理 数据库没有此值
if (pageVO.status) {
if (pageVO.status == 5) {
let now = new Date();
let before = datetimeUtils.sub(now, datetimeUtils.DAY * 3);
where['status'] = 2;
where['expire_time'] = { [ormDB.Op.between]: [before, now] }
}
else {
where['status'] = pageVO.status;
}
}
if (pageVO.export) { if (pageVO.export) {
let resList = await commonUserFeeSetting.prototype.findAll({ let resList = await commonUserFeeSetting.prototype.findAll({
where: { where: where,
status: { [ormDB.Op.ne]: 4 }
},
order: [['id', 'desc']], order: [['id', 'desc']],
raw: true raw: true
}); });
return resList; return resList;
} }
let where = Object.create(null);
if (pageVO.user_id) { if (pageVO.user_id) {
where.user_id = pageVO.user_id; where['user_id'] = pageVO.user_id;
} }
where.status = { [ormDB.Op.ne]: 4 };
if (pageVO.type) { if (pageVO.type) {
where.type = pageVO.type; where['type'] = pageVO.type;
} }
...@@ -99,48 +122,83 @@ export async function list(pageVO: CommonUserFeePageVO) { ...@@ -99,48 +122,83 @@ export async function list(pageVO: CommonUserFeePageVO) {
order: [["id", "desc"]], order: [["id", "desc"]],
raw: true raw: true
}); });
if (resList.rows.length) {
for (let item of resList.rows) {
let userId = item.user_id;
let pair = item.pair;
let userChannel = item.user_channel;
let cacheData: any;
if (userChannel == 2) {
cacheData = await getProjectMakerTradeStat(userId, pair);
}
item.avg7 = cacheData ? cacheData.avg7 : 0;
item.avg15 = cacheData ? cacheData.avg15 : 0;
item.avgUsdt = cacheData ? cacheData.avgUsdt : 0;
}
}
return resList; return resList;
} }
export async function add(commonUserFeeVO: CommonUserFeeVO, currentUserId: any, ip: string | undefined) { export async function add(commonUserFeeVO: CommonUserFeeVO, currentUserId: any, ip: string | undefined) {
let insertList: any = [];
let { spotFeeSetting, contractFeeSetting, baseCoinFeeSetting } = dealData(commonUserFeeVO); let feeSettingItem = await checkAndBuildFeeSettingItem(commonUserFeeVO);
let tx: any;
try {
tx = await ormDB.transaction();
//新建
let dbInfo = await commonUserFeeSetting.prototype.create(feeSettingItem, {
transaction: tx
});
let pair = dbInfo.pair;
let type = dbInfo.type;
let now = new Date();
let insertDbOne: any = [];
let rateLog = buildSubmitItem(pair, dbInfo, now, dbInfo.user_channel);
if (spotFeeSetting) { //提交到log表
let [spot, all] = await Promise.all([getFeeSetting(commonUserFeeVO.user_id, FEE_TYPE.FEE_TYPE_SPOT), if (type == FEE_TYPE.FEE_TYPE_SPOT) {
getFeeSetting(commonUserFeeVO.user_id, FEE_TYPE.FEE_TYPE_ALL)]); insertDbOne = await feeRateSpotLog.prototype.create(rateLog, {
if (spot || all) { transaction: tx
throw ErrorCode.ONLY_ONE_FEE });
} }
insertList.push(spotFeeSetting); else if (type == FEE_TYPE.FEE_TYPE_BASE_COIN_CONTRACT) {//币本位
insertDbOne = await feeRateBaseCoinContractLog.prototype.create(rateLog, {
transaction: tx
});
} }
else {//U本位
insertDbOne = await feeRateContractLog.prototype.create(rateLog, {
transaction: tx
});
if (contractFeeSetting) {
let [contract, contractAll, all] = await Promise.all([getFeeSetting(commonUserFeeVO.user_id, FEE_TYPE.FEE_TYPE_CONTRACT),
getFeeSetting(commonUserFeeVO.user_id, FEE_TYPE.FEE_TYPE_CONTRACT_ALL),
getFeeSetting(commonUserFeeVO.user_id, FEE_TYPE.FEE_TYPE_ALL)]);
if (contract || contractAll || all) {
throw ErrorCode.ONLY_ONE_FEE
}
insertList.push(contractFeeSetting);
} }
let feeLogId = insertDbOne.id;
await commonUserFeeSetting.prototype.update({
fee_log_ids: feeLogId,
update_time: new Date()
}, {
where: {
id: dbInfo.id,
},
transaction: tx
});
if (baseCoinFeeSetting) { await tx.commit();
let [contract, contractAll, all] = await Promise.all([getFeeSetting(commonUserFeeVO.user_id, FEE_TYPE.FEE_TYPE_BASE_COIN_CONTRACT),
getFeeSetting(commonUserFeeVO.user_id, FEE_TYPE.FEE_TYPE_CONTRACT_ALL), }
getFeeSetting(commonUserFeeVO.user_id, FEE_TYPE.FEE_TYPE_ALL)]); catch (e) {
if (contract || contractAll || all) { if (tx) {
throw ErrorCode.ONLY_ONE_FEE await tx.rollback();
} }
insertList.push(baseCoinFeeSetting); logger.error('commonUserFeeSetting.service.add.error:' + e);
throw e;
} }
await commonUserFeeSetting.prototype.bulkCreate(insertList);
//管理后台操作日志 //管理后台操作日志
addOptLog(currentUserId, Number(commonUserFeeVO.user_id), '新增用户手续费', ip, JSON.stringify(commonUserFeeVO), '费率管理'); addOptLog(currentUserId, Number(commonUserFeeVO.user_id), '新增用户手续费', ip, JSON.stringify(commonUserFeeVO), 'VIP管理');
return 'success';
} }
...@@ -154,31 +212,78 @@ export async function update(commonUserFeeVO: CommonUserFeeVO, currentUserId: an ...@@ -154,31 +212,78 @@ export async function update(commonUserFeeVO: CommonUserFeeVO, currentUserId: an
if (!dbInfo) { if (!dbInfo) {
throw ErrorCode.DATA_NOT_EXIST throw ErrorCode.DATA_NOT_EXIST
} }
if (dbInfo.status != FEE_STATUS.STATUS_FEE_SETTING_NEW) { let pair = dbInfo.pair;
throw ErrorCode.ONLY_UN_SUBMIT_UPDATE let type = dbInfo.type;
if (dbInfo.user_id != commonUserFeeVO.user_id || type != commonUserFeeVO.type || commonUserFeeVO.pair != pair) {
throw ErrorCode.UID_TYPE_NOT_UPDATE;
}
if (dbInfo.status == 3 || dbInfo.status == 4) {
throw ErrorCode.FEE_EX_OR_DEL;
}
let tx;
try {
tx = await ormDB.transaction();
let feeLogId: any;
//这四项修改需要 重新写入 rate_log
if (commonUserFeeVO.maker_fee != dbInfo.maker_fee || commonUserFeeVO.taker_fee != dbInfo.taker_fee
|| commonUserFeeVO.begin_time != dbInfo.begin_time || commonUserFeeVO.expire_time != dbInfo.expire_time) {
let insertDbOne: any;
let rateLog = buildSubmitItem(pair, commonUserFeeVO, new Date(), Number(commonUserFeeVO.user_channel));
//提交到log表
if (type == FEE_TYPE.FEE_TYPE_SPOT) {
insertDbOne = await feeRateSpotLog.prototype.create(rateLog, {
transaction: tx
});
}
else if (type == FEE_TYPE.FEE_TYPE_BASE_COIN_CONTRACT) {//币本位
insertDbOne = await feeRateBaseCoinContractLog.prototype.create(rateLog, {
transaction: tx
});
}
else {//U本位
insertDbOne = await feeRateContractLog.prototype.create(rateLog, {
transaction: tx
});
} }
if (dbInfo.user_id != commonUserFeeVO.user_id || dbInfo.type != commonUserFeeVO.type) { feeLogId = insertDbOne.id;
throw ErrorCode.UID_TYPE_NOT_UPDATE
} }
let dbFeeLogIdsArr = dbInfo.fee_log_ids.split(",");
dbFeeLogIdsArr.push(String(feeLogId));
await commonUserFeeSetting.prototype.update({ await commonUserFeeSetting.prototype.update({
pair: commonUserFeeVO.pair,
maker_fee: Number(commonUserFeeVO.maker_fee), maker_fee: Number(commonUserFeeVO.maker_fee),
taker_fee: Number(commonUserFeeVO.taker_fee), taker_fee: Number(commonUserFeeVO.taker_fee),
begin_time: commonUserFeeVO.begin_time, begin_time: commonUserFeeVO.begin_time,
expire_time: commonUserFeeVO.expire_time, expire_time: commonUserFeeVO.expire_time,
remark: commonUserFeeVO.remark, remark: commonUserFeeVO.remark,
fee_log_ids: "", user_channel: commonUserFeeVO.user_channel,
statis_period: commonUserFeeVO.statis_period,
amount_require_usdt: commonUserFeeVO.amount_require_usdt,
applicant: commonUserFeeVO.applicant,
update_time: new Date(), update_time: new Date(),
fee_log_ids: feeLogId ? dbFeeLogIdsArr.toString() : dbInfo.fee_log_ids,
}, { }, {
where: { where: {
id: Number(commonUserFeeVO.id) id: Number(commonUserFeeVO.id)
},
transaction: tx
});
await tx.commit();
}
catch (e) {
if (tx) {
await tx.rollback();
}
logger.error('commonUserFeeSetting.service.update.error:' + e);
throw e;
} }
})
//管理后台操作日志
addOptLog(currentUserId, Number(commonUserFeeVO.user_id), '修改用户手续费', ip, JSON.stringify(commonUserFeeVO), '费率管理');
//管理后台操作日志
addOptLog(currentUserId, Number(commonUserFeeVO.user_id), '修改用户手续费', ip, JSON.stringify(commonUserFeeVO), 'VIP管理');
return 'success';
} }
...@@ -194,19 +299,8 @@ export async function del(id: number, currentUserId: any, ip: string | undefined ...@@ -194,19 +299,8 @@ export async function del(id: number, currentUserId: any, ip: string | undefined
} }
let status = dbInfo.status; let status = dbInfo.status;
let type = dbInfo.type; let type = dbInfo.type;
if (status != FEE_STATUS.STATUS_FEE_SETTING_NEW && status != FEE_STATUS.STATUS_FEE_SETTING_SUBMIT) { if (status == FEE_STATUS.STATUS_FEE_SETTING_EFFECTED) {
throw ErrorCode.DEL_UN_SUBMIT_ACTIVE throw ErrorCode.FEE_USED_NOT_DEL
}
if (status == FEE_STATUS.STATUS_FEE_SETTING_NEW) {
await commonUserFeeSetting.prototype.destroy({
where: {
id: id
}
});
//管理后台操作日志
addOptLog(currentUserId, Number(dbInfo.user_id), '删除用户手续费', ip, JSON.stringify(dbInfo), '费率管理');
return 'success'
} }
...@@ -287,124 +381,13 @@ export async function del(id: number, currentUserId: any, ip: string | undefined ...@@ -287,124 +381,13 @@ export async function del(id: number, currentUserId: any, ip: string | undefined
} }
//管理后台操作日志 //管理后台操作日志
addOptLog(currentUserId, Number(dbInfo.user_id), '删除用户手续费', ip, JSON.stringify(dbInfo), '费率管理'); addOptLog(currentUserId, Number(dbInfo.user_id), '删除用户手续费', ip, JSON.stringify(dbInfo), 'VIP管理');
return 'success'; return 'success';
} }
export async function submit(id: number, currentUserId: any, ip: string | undefined) {
let dbInfo = await commonUserFeeSetting.prototype.findOne({
where: {
id: id
},
raw: true
});
if (!dbInfo) {
throw ErrorCode.DATA_NOT_EXIST
}
let status = dbInfo.status;
let type = dbInfo.type;
if (status != FEE_STATUS.STATUS_FEE_SETTING_NEW) {
throw ErrorCode.ONLY_UN_SUBMIT_CAN_SUBMIT
}
let pair = String(dbInfo.pair);
let userId = dbInfo.user_id;
let feeLogId = "";
let now = new Date();
let tx;
try {
tx = await ormDB.transaction();
if (type == FEE_TYPE.FEE_TYPE_SPOT) {
let insertInfo = buildSubmitItem(pair, dbInfo, now);
let item = await feeRateSpotLog.prototype.create(insertInfo, {
transaction: tx
});
feeLogId = item.id.toString();
}
else if (type == FEE_TYPE.FEE_TYPE_BASE_COIN_CONTRACT) {//币本位
if (pair.toLowerCase() == "all") {
//TODO:币本位币对查询 enable = 1 的 pairList = 数据库查询结果
let pairList = [];
let insertList: any = [];
let ids: any = [];
for (let onePair of pairList) {
let oneInsert = buildSubmitItem(onePair, dbInfo, now);
insertList.push(oneInsert);
}
let bulkList = await feeRateBaseCoinContractLog.prototype.bulkCreate(insertList, {
transaction: tx
});
for (let one of bulkList) {
ids.push(one.id);
}
feeLogId = ids.toString();
}
else {
let one = buildSubmitItem(pair, dbInfo, now);
let insertOne = await feeRateBaseCoinContractLog.prototype.create(one, {
transaction: tx
});
feeLogId = insertOne.id.toString()
}
}
else {//U本位
if (pair.toLowerCase() == "all") {
//TODO:U本位币对查询 enable = 1 的 pairList = 数据库查询结果
let pairList = [];
let insertList: any = [];
let ids: any = [];
for (let onePair of pairList) {
let oneInsert = buildSubmitItem(onePair, dbInfo, now);
insertList.push(oneInsert);
}
let bulkList = await feeRateContractLog.prototype.bulkCreate(insertList, {
transaction: tx
});
for (let one of bulkList) {
ids.push(one.id);
}
feeLogId = ids.toString();
}
else {
let one = buildSubmitItem(pair, dbInfo, now);
let insertOne = await feeRateContractLog.prototype.create(one, {
transaction: tx
});
feeLogId = insertOne.id.toString()
}
}
await commonUserFeeSetting.prototype.update({
status: FEE_STATUS.STATUS_FEE_SETTING_SUBMIT,
fee_log_ids: feeLogId,
update_time: new Date()
}, {
where: {
id: id,
status: FEE_STATUS.STATUS_FEE_SETTING_NEW
},
transaction: tx
});
await tx.commit();
}
catch (e) {
if (tx) {
await tx.rollback();
}
logger.error('commonUserFeeSetting.service.submit.error:' + e);
throw e;
}
//管理后台操作日志
addOptLog(currentUserId, Number(dbInfo.user_id), '提交用户手续费', ip, JSON.stringify(dbInfo), '费率管理');
return 'success'
}
export async function vipLevelList() { export async function vipLevelList() {
let resList = await vipLevelFeeSetting.prototype.findAll({ let resList = await vipLevelFeeSetting.prototype.findAll({
order: [['id', 'desc']], order: [['id', 'desc']],
...@@ -414,72 +397,70 @@ export async function vipLevelList() { ...@@ -414,72 +397,70 @@ export async function vipLevelList() {
} }
function dealData(commonUserFeeVO: CommonUserFeeVO) { async function checkAndBuildFeeSettingItem(commonUserFeeVO: CommonUserFeeVO) {
let spotFeeSetting, contractFeeSetting, baseCoinFeeSetting;
let type = commonUserFeeVO.type; let type = commonUserFeeVO.type;
let pair = String(commonUserFeeVO.pair);
if (type == FEE_TYPE.FEE_TYPE_SPOT) { if (type == FEE_TYPE.FEE_TYPE_SPOT) {
spotFeeSetting = buildOne(commonUserFeeVO, commonUserFeeVO.spot_maker_fee, commonUserFeeVO.spot_taker_fee, FEE_TYPE.FEE_TYPE_SPOT) if (pair != 'all') {
} //校验交易对是否存在
else if (type == FEE_TYPE.FEE_TYPE_CONTRACT) { await checkSpotPair(pair);
contractFeeSetting = buildOne(commonUserFeeVO, commonUserFeeVO.contract_maker_fee, commonUserFeeVO.contract_taker_fee, FEE_TYPE.FEE_TYPE_CONTRACT)
}
else if (type == FEE_TYPE.FEE_TYPE_BASE_COIN_CONTRACT) {
baseCoinFeeSetting = buildOne(commonUserFeeVO, commonUserFeeVO.contract_maker_fee, commonUserFeeVO.contract_taker_fee, FEE_TYPE.FEE_TYPE_BASE_COIN_CONTRACT)
} }
else if (type == FEE_TYPE.FEE_TYPE_CONTRACT_ALL) {
contractFeeSetting = buildOne(commonUserFeeVO, commonUserFeeVO.contract_maker_fee, commonUserFeeVO.contract_taker_fee, FEE_TYPE.FEE_TYPE_CONTRACT)
baseCoinFeeSetting = buildOne(commonUserFeeVO, commonUserFeeVO.contract_maker_fee, commonUserFeeVO.contract_taker_fee, FEE_TYPE.FEE_TYPE_BASE_COIN_CONTRACT)
} }
else { else {
spotFeeSetting = buildOne(commonUserFeeVO, commonUserFeeVO.spot_maker_fee, commonUserFeeVO.spot_taker_fee, FEE_TYPE.FEE_TYPE_SPOT) if (pair != 'all') {
contractFeeSetting = buildOne(commonUserFeeVO, commonUserFeeVO.contract_maker_fee, commonUserFeeVO.contract_taker_fee, FEE_TYPE.FEE_TYPE_CONTRACT) //校验交易对是否存在
baseCoinFeeSetting = buildOne(commonUserFeeVO, commonUserFeeVO.contract_maker_fee, commonUserFeeVO.contract_taker_fee, FEE_TYPE.FEE_TYPE_BASE_COIN_CONTRACT) await checkContractPair(pair);
}
} }
return { let dbFeeSetting = await getDbFeeSetting(commonUserFeeVO.user_id, type, commonUserFeeVO.user_channel, pair);
spotFeeSetting, if (dbFeeSetting) {
contractFeeSetting, throw ErrorCode.EXIST_ACTIVE_PAIR;
baseCoinFeeSetting
} }
let feeSettingItem = buildOne(commonUserFeeVO, commonUserFeeVO.maker_fee, commonUserFeeVO.taker_fee, type, pair);
return feeSettingItem;
} }
function buildOne(commonUserFeeVO: CommonUserFeeVO, maker_fee: number | any, taker_fee: number | any, type: number | any) { function buildOne(commonUserFeeVO: CommonUserFeeVO, maker_fee: number | any, taker_fee: number | any, type: number | any, pair: any) {
let one = { let one = {
user_id: commonUserFeeVO.user_id, user_id: commonUserFeeVO.user_id,
type: Number(type), type: Number(type),
pair: SYMBOL_ALL, pair: pair,
maker_fee: Number(maker_fee), maker_fee: Number(maker_fee),
taker_fee: Number(taker_fee), taker_fee: Number(taker_fee),
begin_time: commonUserFeeVO.begin_time, begin_time: commonUserFeeVO.begin_time,
expire_time: commonUserFeeVO.expire_time, expire_time: commonUserFeeVO.expire_time,
remark: commonUserFeeVO.remark, remark: commonUserFeeVO.remark,
status: FEE_STATUS.STATUS_FEE_SETTING_NEW, status: FEE_STATUS.STATUS_FEE_SETTING_SUBMIT,
fee_log_ids: "", fee_log_ids: "",
user_channel: commonUserFeeVO.user_channel,
statis_period: commonUserFeeVO.statis_period,
amount_require_usdt: commonUserFeeVO.amount_require_usdt,
applicant: commonUserFeeVO.applicant,
create_time: new Date(), create_time: new Date(),
update_time: new Date(), update_time: new Date(),
} }
return one; return one;
} }
async function getFeeSetting(user_id: number | any, type: number | any) { async function getDbFeeSetting(user_id: number | any, type: number | any, user_channel: any, pair: string) {
let dbInfo = await commonUserFeeSetting.prototype.findOne({ let dbInfo = await commonUserFeeSetting.prototype.findOne({
where: { where: {
user_id: Number(user_id), user_id: Number(user_id),
type: Number(type), type: Number(type),
status: FEE_STATUS.STATUS_FEE_SETTING_NEW pair: pair,
user_channel: user_channel,
status: { [ormDB.Op.in]: [FEE_STATUS.STATUS_FEE_SETTING_SUBMIT, FEE_STATUS.STATUS_FEE_SETTING_EFFECTED] }
}, },
raw: true raw: true
}); });
return dbInfo; return dbInfo;
} }
function buildSubmitItem(pair: string, dbInfo: any, now: Date) { function buildSubmitItem(pair: string, dbInfo: any, now: Date, user_channel: number) {
let item = { let item = {
user_id: dbInfo.user_id, user_id: dbInfo.user_id,
pair: pair, pair: pair,
...@@ -489,10 +470,70 @@ function buildSubmitItem(pair: string, dbInfo: any, now: Date) { ...@@ -489,10 +470,70 @@ function buildSubmitItem(pair: string, dbInfo: any, now: Date) {
beginAt: dbInfo.begin_time, beginAt: dbInfo.begin_time,
expireAt: dbInfo.expire_time, expireAt: dbInfo.expire_time,
is_check: FEE_RATE_LOG_STATUS.CHECK_STATUS_UNCHECK, is_check: FEE_RATE_LOG_STATUS.CHECK_STATUS_UNCHECK,
comment: COMMENT_USER_FEE_SUBMIT, comment: "",
createdAt: now, createdAt: now,
updatedAt: now updatedAt: now
} }
//项目方
if (user_channel == 2) {
item.comment = COMMENT_MAKER_FEE_SUBMIT
}
else if (user_channel == 3) {
item.comment = COMMENT_KOL_FEE_SUBMIT
}
else {
item.comment = COMMENT_USER_FEE_SUBMIT
}
return item; return item;
} }
async function checkSpotPair(pair: string) {
let dbPair = await spotPairs.prototype.findOne(
{
where: {
symbol: pair,
status: 2
},
raw: true
}
);
if (!dbPair) {
logger.error('checkSpotPair.pair:' + pair);
throw ErrorCode.PAIR_NOT_EXIST;
}
}
async function checkContractPair(pair: string) {
let dbPair = await contractPairs.prototype.findAll(
{
where: {
symbol: pair,
status: 2
},
raw: true
}
);
if (!dbPair) {
logger.error('checkSpotPair.pair:' + pair);
throw ErrorCode.PAIR_NOT_EXIST;
}
}
async function getProjectMakerTradeStat(user_id: number, pair: string) {
let res = {
avg7: 0,
avg15: 0,
avgUsdt: 0,
};
let key = user_id + "_" + pair + "_projectMaker_FeeRate";
let redisData = await RedisClient.getSync(key);
if (redisData) {
let obj = JSON.parse(redisData);
res.avg7 = obj.avg7;
res.avg15 = obj.avg15;
res.avgUsdt = obj.avgUsdt;
}
return res;
}
...@@ -169,12 +169,12 @@ const postFunc = { ...@@ -169,12 +169,12 @@ const postFunc = {
'mUser/subscribe/mail/detail': mUserSubscribeCtrl.mailDetail,//发送详情 'mUser/subscribe/mail/detail': mUserSubscribeCtrl.mailDetail,//发送详情
'mUser/subscribe/mail/send/group': mUserSubscribeCtrl.maiSendGroup,//群发邮件 'mUser/subscribe/mail/send/group': mUserSubscribeCtrl.maiSendGroup,//群发邮件
//运营部-现货-费率管理-普通用户手续费 //运营部-现货-VIP管理(普通用户手续费、市商手续费)
'mUser/fee/setting/list': commonUserFeeSettingCtrl.list,//普通用户手续费列表 'mUser/fee/setting/list': commonUserFeeSettingCtrl.list,//普通用户手续费列表
'mUser/fee/setting/add': commonUserFeeSettingCtrl.add,//新增普通用户手续费 'mUser/fee/setting/add': commonUserFeeSettingCtrl.add,//新增普通用户手续费
'mUser/fee/setting/update': commonUserFeeSettingCtrl.update,//修改普通用户手续费 'mUser/fee/setting/update': commonUserFeeSettingCtrl.update,//修改普通用户手续费
'mUser/fee/setting/delete': commonUserFeeSettingCtrl.del,//删除普通用户手续费 'mUser/fee/setting/delete': commonUserFeeSettingCtrl.del,//删除普通用户手续费
'mUser/fee/setting/submit': commonUserFeeSettingCtrl.submit,//提交普通用户手续费 //'mUser/fee/setting/submit': commonUserFeeSettingCtrl.submit,//提交普通用户手续费
'mUser/fee/vip/level/list': commonUserFeeSettingCtrl.vipLevelList,//用户等级费率列表 'mUser/fee/vip/level/list': commonUserFeeSettingCtrl.vipLevelList,//用户等级费率列表
//技术部-App管理-App版本管理 //技术部-App管理-App版本管理
......
...@@ -111,12 +111,12 @@ let cmdWhiteList = { ...@@ -111,12 +111,12 @@ let cmdWhiteList = {
'mUser/subscribe/mail/send': 1, 'mUser/subscribe/mail/send': 1,
'mUser/subscribe/mail/detail': 1, 'mUser/subscribe/mail/detail': 1,
'mUser/subscribe/mail/send/group': 1, 'mUser/subscribe/mail/send/group': 1,
//运营部-现货-费率管理-普通用户手续费 //运营部-现货-VIP管理(普通用户手续费、市商手续费)
'mUser/fee/setting/list': 1, 'mUser/fee/setting/list': 1,
'mUser/fee/setting/add': 1, 'mUser/fee/setting/add': 1,
'mUser/fee/setting/update': 1, 'mUser/fee/setting/update': 1,
'mUser/fee/setting/delete': 1, 'mUser/fee/setting/delete': 1,
'mUser/fee/setting/submit': 1, //'mUser/fee/setting/submit': 1,
'mUser/fee/vip/level/list': 1, 'mUser/fee/vip/level/list': 1,
//技术部-App管理-App版本管理 //技术部-App管理-App版本管理
'tech/app/version/list': 1, 'tech/app/version/list': 1,
......
import { mainUserAsset } from "@madex/ex-ts-dao";
let blockCoin = "BIX0"; let blockCoin = "BIX0";
export const spotCheck = async function (user_id: number) { export const spotCheck = async function (user_id: number) {
//TODO:后面补齐查询现货资产逻辑 let exist = await mainUserAsset.prototype.findOne({
let exist = {}; where: {
user_id: user_id
},
raw: true
})
return exist; return exist;
} }
......
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