Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
T
ts-api-demo
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wmvm
ts-api-demo
Commits
94108a6a
Commit
94108a6a
authored
Oct 14, 2024
by
ml
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
费率管理调整为VIP管理、相关逻辑调整、增加市商费率逻辑
parent
72108c1a
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
326 additions
and
314 deletions
+326
-314
errorCode.ts
src/constant/errorCode.ts
+6
-4
marketMakerConst.ts
src/constant/marketMakerConst.ts
+14
-15
commonUserFeeSetting.control.ts
src/functional/mvc/control/commonUserFeeSetting.control.ts
+37
-72
commonUserFeeSetting.service.ts
src/functional/mvc/service/commonUserFeeSetting.service.ts
+258
-217
index.ts
src/functional/router/v1/index.ts
+2
-2
access-limit.ts
src/setting/access-limit.ts
+2
-2
feeRateCheckValidUtils.ts
src/utils/feeRateCheckValidUtils.ts
+7
-2
No files found.
src/constant/errorCode.ts
View file @
94108a6a
...
...
@@ -47,7 +47,7 @@ export const ErrorCode = {
LEVEL_NOT_EXIST
:
'30043'
,
//指定等级不存在
ONLY_ONE_FEE
:
'30044'
,
//只能有一条未提交的费率设置
ONLY_UN_SUBMIT_UPDATE
:
'30045'
,
//只有未提交的记录可以修改
UID_TYPE_NOT_UPDATE
:
'30046'
,
//用户ID
和类型
不能修改
UID_TYPE_NOT_UPDATE
:
'30046'
,
//用户ID
、费率类型、交易对
不能修改
DEL_UN_SUBMIT_ACTIVE
:
'30047'
,
//只能删除未提交或未生效的记录
FEE_USED_NOT_DEL
:
'30048'
,
//费率已生效,不能删除
ONLY_UN_SUBMIT_CAN_SUBMIT
:
'30049'
,
//只有未提交的记录才能提交
...
...
@@ -57,8 +57,8 @@ export const ErrorCode = {
PWD_ILLEGAL
:
'30053'
,
//密码过短或过长
FIXED_AND_DEFAULT
:
'30054'
,
//固定和默认不能同时为是
NOT_HIDDEN_TWO
:
'30055'
,
//每种语言非隐藏并且固定的至少要有2个
COIN_TYPE_NOT_EXIST
:
'30056'
,
//
指定
币种不存在
PAIR_NOT_EXIST
:
'30057'
,
//
指定
币对不存在
COIN_TYPE_NOT_EXIST
:
'30056'
,
//币种不存在
PAIR_NOT_EXIST
:
'30057'
,
//币对不存在
LIMIT_ERROR
:
'30058'
,
//limit参数必须在10-2000之间
ADD_PAIR_TO_CORE_ERR
:
'30059'
,
//币种/交易对提交到撮合失败
SUBMIT_STATUS_ERR
:
'30060'
,
//请确认提交状态
...
...
@@ -70,7 +70,9 @@ export const ErrorCode = {
DEPOSIT_WITHDRAW_TM_EXPIRE
:
'30066'
,
//开放充值时间/开放提现时间过短
CURRENT_STATUS_NOT_APPLY
:
'30067'
,
//当前状态不可以审核
CURRENT_COIN_DATA_NOT_EXIST
:
'30068'
,
//币种管理中计价币种不存在
PAIR_EXIST
:
'30069'
,
//交易对
对
已存在
PAIR_EXIST
:
'30069'
,
//交易对已存在
ACTIVE_TM_EXPIRE
:
'30070'
,
//交易时间过短
NO_TRIGGER_DEL
:
'30071'
,
//只有未触发的任务可以删除
EXIST_ACTIVE_PAIR
:
'30072'
,
//已存在生效或即将生效的该交易对费率配置
FEE_EX_OR_DEL
:
'30073'
,
//费率设置已过期或已删除,不可以修改
}
src/constant/marketMakerConst.ts
View file @
94108a6a
export
const
FEE_TYPE
=
{
/**
* 费率类型: 全部。
*/
FEE_TYPE_ALL
:
0
,
/**
* 费率类型: 币币。
...
...
@@ -17,20 +13,11 @@ export const FEE_TYPE = {
* 费率类型: 币本位合约。
*/
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
=
{
/**
* 费率设置纪录状态: 未提交。
*/
STATUS_FEE_SETTING_NEW
:
0
,
/**
* 费率设置纪录状态: 已提交。
*/
...
...
@@ -52,4 +39,16 @@ export const FEE_STATUS = {
/**
* 普通用户手续费提交备注。
*/
export
const
COMMENT_USER_FEE_SUBMIT
=
"提交普通用户手续费"
;
\ No newline at end of file
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
src/functional/mvc/control/commonUserFeeSetting.control.ts
View file @
94108a6a
...
...
@@ -65,7 +65,11 @@ export const update = async (req: any, commonUserFeeVO: CommonUserFeeVO) => {
try
{
let
ip
=
isIp
(
req
.
ip
)
?
req
.
ip
:
'*.*.*.*'
;
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
);
return
Res3Utils
.
result
(
res
);
...
...
@@ -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) {
let
expireTime
=
commonUserFeeVO
.
expire_time
;
let
type
=
commonUserFeeVO
.
type
;
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
;
}
await
checkMaker
(
commonUserFeeVO
);
await
paramCheck
(
beginTime
,
expireTime
,
Number
(
type
),
userId
);
if
(
levelId
)
{
...
...
@@ -162,24 +149,17 @@ async function addParamValid(commonUserFeeVO: CommonUserFeeVO) {
if
(
!
vipLevelSetting
)
{
throw
ErrorCode
.
LEVEL_NOT_EXIST
;
}
commonUserFeeVO
.
spot_maker_fee
=
vipLevelSetting
.
spot_maker
;
commonUserFeeVO
.
spot_taker_fee
=
vipLevelSetting
.
spot_taker
;
commonUserFeeVO
.
contract_maker_fee
=
vipLevelSetting
.
contract_maker
;
commonUserFeeVO
.
contract_taker_fee
=
vipLevelSetting
.
contract_taker
;
if
(
type
==
FEE_TYPE
.
FEE_TYPE_SPOT
)
{
commonUserFeeVO
.
maker_fee
=
vipLevelSetting
.
spot_maker
;
commonUserFeeVO
.
taker_fee
=
vipLevelSetting
.
spot_taker
;
}
else
{
commonUserFeeVO
.
maker_fee
=
vipLevelSetting
.
contract_maker
;
commonUserFeeVO
.
taker_fee
=
vipLevelSetting
.
contract_taker
;
}
return
;
}
if
((
type
==
FEE_TYPE
.
FEE_TYPE_ALL
||
type
==
FEE_TYPE
.
FEE_TYPE_SPOT
)
&&
(
!
commonUserFeeVO
.
spot_maker_fee
||
!
commonUserFeeVO
.
spot_taker_fee
))
{
throw
ErrorCode
.
SPOT_FEE_NEED_SET
;
}
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
);
if
(
!
user
||
user
.
deleted_flag
==
1
)
{
...
...
@@ -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
...
...
@@ -242,23 +206,24 @@ async function paramCheck(beginTime: any, expireTime: any, type: number, userId:
throw
ErrorCode
.
COIN_NO_ASSETS
;
}
}
else
if
(
type
==
FEE_TYPE
.
FEE_TYPE_CONTRACT_ALL
)
{
if
(
!
await
baseUCheck
(
userId
))
{
throw
ErrorCode
.
U_NO_ASSETS
;
}
if
(
!
await
baseCoinCheck
(
userId
))
{
throw
ErrorCode
.
COIN_NO_ASSETS
;
}
}
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
;
}
async
function
checkMaker
(
commonUserFeeVO
:
CommonUserFeeVO
)
{
let
userChannel
=
commonUserFeeVO
.
user_channel
;
if
(
!
userChannel
)
{
throw
ErrorCode
.
PARAM_MISS
}
//项目方
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
(
!
a
wait
baseCoinCheck
(
userId
)
)
{
throw
ErrorCode
.
COIN_NO_ASSET
S
;
if
(
!
a
mount_require_usdt
)
{
throw
ErrorCode
.
PARAM_MIS
S
;
}
}
}
}
\ No newline at end of file
src/functional/mvc/service/commonUserFeeSetting.service.ts
View file @
94108a6a
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
{
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
*
as
feeRateSpotLogService
from
"./feeRateSpotLog.service"
;
import
*
as
feeRateContractLogService
from
"./feeRateContractLog.service"
;
import
*
as
feeRateBaseCoinContractLogService
from
"./feeRateBaseCoinContractLog.service"
;
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
{
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
{
...
...
@@ -49,13 +61,15 @@ export interface CommonUserFeeVO {
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 {
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
)
{
let
resList
=
await
commonUserFeeSetting
.
prototype
.
findAll
({
where
:
{
status
:
{
[
ormDB
.
Op
.
ne
]:
4
}
},
where
:
where
,
order
:
[[
'id'
,
'desc'
]],
raw
:
true
});
return
resList
;
}
let
where
=
Object
.
create
(
null
);
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
)
{
where
.
type
=
pageVO
.
type
;
where
[
'type'
]
=
pageVO
.
type
;
}
...
...
@@ -99,48 +122,83 @@ export async function list(pageVO: CommonUserFeePageVO) {
order
:
[[
"id"
,
"desc"
]],
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
;
}
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
)
{
let
[
spot
,
all
]
=
await
Promise
.
all
([
getFeeSetting
(
commonUserFeeVO
.
user_id
,
FEE_TYPE
.
FEE_TYPE_SPOT
),
getFeeSetting
(
commonUserFeeVO
.
user_id
,
FEE_TYPE
.
FEE_TYPE_ALL
)]);
if
(
spot
||
all
)
{
throw
ErrorCode
.
ONLY_ONE_FEE
//提交到log表
if
(
type
==
FEE_TYPE
.
FEE_TYPE_SPOT
)
{
insertDbOne
=
await
feeRateSpotLog
.
prototype
.
create
(
rateLog
,
{
transaction
:
tx
});
}
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
;
if
(
baseCoinFeeSetting
)
{
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
)]);
if
(
contract
||
contractAll
||
all
)
{
throw
ErrorCode
.
ONLY_ONE_FEE
await
commonUserFeeSetting
.
prototype
.
update
({
fee_log_ids
:
feeLogId
,
update_time
:
new
Date
()
},
{
where
:
{
id
:
dbInfo
.
id
,
},
transaction
:
tx
});
await
tx
.
commit
();
}
catch
(
e
)
{
if
(
tx
)
{
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
if
(
!
dbInfo
)
{
throw
ErrorCode
.
DATA_NOT_EXIST
}
if
(
dbInfo
.
status
!=
FEE_STATUS
.
STATUS_FEE_SETTING_NEW
)
{
throw
ErrorCode
.
ONLY_UN_SUBMIT_UPDATE
let
pair
=
dbInfo
.
pair
;
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
.
user_id
!=
commonUserFeeVO
.
user_id
||
dbInfo
.
type
!=
commonUserFeeVO
.
type
)
{
throw
ErrorCode
.
UID_TYPE_NOT_UPDATE
if
(
dbInfo
.
status
==
3
||
dbInfo
.
status
==
4
)
{
throw
ErrorCode
.
FEE_EX_OR_DEL
;
}
await
commonUserFeeSetting
.
prototype
.
update
({
pair
:
commonUserFeeVO
.
pair
,
maker_fee
:
Number
(
commonUserFeeVO
.
maker_fee
),
taker_fee
:
Number
(
commonUserFeeVO
.
taker_fee
),
begin_time
:
commonUserFeeVO
.
begin_time
,
expire_time
:
commonUserFeeVO
.
expire_time
,
remark
:
commonUserFeeVO
.
remark
,
fee_log_ids
:
""
,
update_time
:
new
Date
(),
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
});
},
{
where
:
{
id
:
Number
(
commonUserFeeVO
.
id
)
}
feeLogId
=
insertDbOne
.
id
;
}
})
//管理后台操作日志
addOptLog
(
currentUserId
,
Number
(
commonUserFeeVO
.
user_id
),
'修改用户手续费'
,
ip
,
JSON
.
stringify
(
commonUserFeeVO
),
'费率管理'
);
let
dbFeeLogIdsArr
=
dbInfo
.
fee_log_ids
.
split
(
","
);
dbFeeLogIdsArr
.
push
(
String
(
feeLogId
));
await
commonUserFeeSetting
.
prototype
.
update
({
maker_fee
:
Number
(
commonUserFeeVO
.
maker_fee
),
taker_fee
:
Number
(
commonUserFeeVO
.
taker_fee
),
begin_time
:
commonUserFeeVO
.
begin_time
,
expire_time
:
commonUserFeeVO
.
expire_time
,
remark
:
commonUserFeeVO
.
remark
,
user_channel
:
commonUserFeeVO
.
user_channel
,
statis_period
:
commonUserFeeVO
.
statis_period
,
amount_require_usdt
:
commonUserFeeVO
.
amount_require_usdt
,
applicant
:
commonUserFeeVO
.
applicant
,
update_time
:
new
Date
(),
fee_log_ids
:
feeLogId
?
dbFeeLogIdsArr
.
toString
()
:
dbInfo
.
fee_log_ids
,
},
{
where
:
{
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
),
'VIP管理'
);
return
'success'
;
}
...
...
@@ -194,19 +299,8 @@ export async function del(id: number, currentUserId: any, ip: string | undefined
}
let
status
=
dbInfo
.
status
;
let
type
=
dbInfo
.
type
;
if
(
status
!=
FEE_STATUS
.
STATUS_FEE_SETTING_NEW
&&
status
!=
FEE_STATUS
.
STATUS_FEE_SETTING_SUBMIT
)
{
throw
ErrorCode
.
DEL_UN_SUBMIT_ACTIVE
}
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'
if
(
status
==
FEE_STATUS
.
STATUS_FEE_SETTING_EFFECTED
)
{
throw
ErrorCode
.
FEE_USED_NOT_DEL
}
...
...
@@ -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'
;
}
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
()
{
let
resList
=
await
vipLevelFeeSetting
.
prototype
.
findAll
({
order
:
[[
'id'
,
'desc'
]],
...
...
@@ -414,72 +397,70 @@ export async function vipLevelList() {
}
function
dealData
(
commonUserFeeVO
:
CommonUserFeeVO
)
{
let
spotFeeSetting
,
contractFeeSetting
,
baseCoinFeeSetting
;
async
function
checkAndBuildFeeSettingItem
(
commonUserFeeVO
:
CommonUserFeeVO
)
{
let
type
=
commonUserFeeVO
.
type
;
let
pair
=
String
(
commonUserFeeVO
.
pair
);
if
(
type
==
FEE_TYPE
.
FEE_TYPE_SPOT
)
{
spotFeeSetting
=
buildOne
(
commonUserFeeVO
,
commonUserFeeVO
.
spot_maker_fee
,
commonUserFeeVO
.
spot_taker_fee
,
FEE_TYPE
.
FEE_TYPE_SPOT
)
}
else
if
(
type
==
FEE_TYPE
.
FEE_TYPE_CONTRACT
)
{
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
)
if
(
pair
!=
'all'
)
{
//校验交易对是否存在
await
checkSpotPair
(
pair
);
}
}
else
{
spotFeeSetting
=
buildOne
(
commonUserFeeVO
,
commonUserFeeVO
.
spot_maker_fee
,
commonUserFeeVO
.
spot_taker_fee
,
FEE_TYPE
.
FEE_TYPE_SPOT
)
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
)
if
(
pair
!=
'all'
)
{
//校验交易对是否存在
await
checkContractPair
(
pair
);
}
}
return
{
spotFeeSetting
,
contractFeeSetting
,
baseCoinFeeSetting
let
dbFeeSetting
=
await
getDbFeeSetting
(
commonUserFeeVO
.
user_id
,
type
,
commonUserFeeVO
.
user_channel
,
pair
);
if
(
dbFeeSetting
)
{
throw
ErrorCode
.
EXIST_ACTIVE_PAIR
;
}
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
=
{
user_id
:
commonUserFeeVO
.
user_id
,
type
:
Number
(
type
),
pair
:
SYMBOL_ALL
,
pair
:
pair
,
maker_fee
:
Number
(
maker_fee
),
taker_fee
:
Number
(
taker_fee
),
begin_time
:
commonUserFeeVO
.
begin_time
,
expire_time
:
commonUserFeeVO
.
expire_time
,
remark
:
commonUserFeeVO
.
remark
,
status
:
FEE_STATUS
.
STATUS_FEE_SETTING_
NEW
,
status
:
FEE_STATUS
.
STATUS_FEE_SETTING_
SUBMIT
,
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
(),
update_time
:
new
Date
(),
}
return
one
;
}
async
function
get
FeeSetting
(
user_id
:
number
|
any
,
type
:
number
|
any
)
{
async
function
get
DbFeeSetting
(
user_id
:
number
|
any
,
type
:
number
|
any
,
user_channel
:
any
,
pair
:
string
)
{
let
dbInfo
=
await
commonUserFeeSetting
.
prototype
.
findOne
({
where
:
{
user_id
:
Number
(
user_id
),
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
});
return
dbInfo
;
}
function
buildSubmitItem
(
pair
:
string
,
dbInfo
:
any
,
now
:
Date
)
{
function
buildSubmitItem
(
pair
:
string
,
dbInfo
:
any
,
now
:
Date
,
user_channel
:
number
)
{
let
item
=
{
user_id
:
dbInfo
.
user_id
,
pair
:
pair
,
...
...
@@ -489,10 +470,70 @@ function buildSubmitItem(pair: string, dbInfo: any, now: Date) {
beginAt
:
dbInfo
.
begin_time
,
expireAt
:
dbInfo
.
expire_time
,
is_check
:
FEE_RATE_LOG_STATUS
.
CHECK_STATUS_UNCHECK
,
comment
:
COMMENT_USER_FEE_SUBMIT
,
comment
:
""
,
createdAt
:
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
;
}
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
;
}
src/functional/router/v1/index.ts
View file @
94108a6a
...
...
@@ -169,12 +169,12 @@ const postFunc = {
'mUser/subscribe/mail/detail'
:
mUserSubscribeCtrl
.
mailDetail
,
//发送详情
'mUser/subscribe/mail/send/group'
:
mUserSubscribeCtrl
.
maiSendGroup
,
//群发邮件
//运营部-现货-
费率管理-普通用户手续费
//运营部-现货-
VIP管理(普通用户手续费、市商手续费)
'mUser/fee/setting/list'
:
commonUserFeeSettingCtrl
.
list
,
//普通用户手续费列表
'mUser/fee/setting/add'
:
commonUserFeeSettingCtrl
.
add
,
//新增普通用户手续费
'mUser/fee/setting/update'
:
commonUserFeeSettingCtrl
.
update
,
//修改普通用户手续费
'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
,
//用户等级费率列表
//技术部-App管理-App版本管理
...
...
src/setting/access-limit.ts
View file @
94108a6a
...
...
@@ -111,12 +111,12 @@ let cmdWhiteList = {
'mUser/subscribe/mail/send'
:
1
,
'mUser/subscribe/mail/detail'
:
1
,
'mUser/subscribe/mail/send/group'
:
1
,
//运营部-现货-
费率管理-普通用户手续费
//运营部-现货-
VIP管理(普通用户手续费、市商手续费)
'mUser/fee/setting/list'
:
1
,
'mUser/fee/setting/add'
:
1
,
'mUser/fee/setting/update'
:
1
,
'mUser/fee/setting/delete'
:
1
,
'mUser/fee/setting/submit'
:
1
,
//
'mUser/fee/setting/submit': 1,
'mUser/fee/vip/level/list'
:
1
,
//技术部-App管理-App版本管理
'tech/app/version/list'
:
1
,
...
...
src/utils/feeRateCheckValidUtils.ts
View file @
94108a6a
import
{
mainUserAsset
}
from
"@madex/ex-ts-dao"
;
let
blockCoin
=
"BIX0"
;
export
const
spotCheck
=
async
function
(
user_id
:
number
)
{
//TODO:后面补齐查询现货资产逻辑
let
exist
=
{};
let
exist
=
await
mainUserAsset
.
prototype
.
findOne
({
where
:
{
user_id
:
user_id
},
raw
:
true
})
return
exist
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment