Commit aec822ac authored by 1486327116's avatar 1486327116

Merge remote-tracking branch 'origin/master'

parents ba11a1dc d1840dce
......@@ -120,10 +120,10 @@ export const changeUserSpotFee = async function (user_id, symbol, fee_model, mak
await checkFeeModel(fee_model);
let product_type = pair == 'all' ? 'spot' : 'single';
//生效的费率 与要设置的费率 比对做校验 现在分不开 现货 合约 先不校验 之后分开了 再校验
/* let feeExist = await cancelIfFeeExist(user_id, product_type, symbol, maker_fee, taker_fee);
let feeExist = await cancelIfFeeExist(user_id, product_type, symbol, maker_fee, taker_fee);
if (feeExist) {
return is_success;
}*/
}
let asset = await mainUserAsset.prototype.findOne({
where: {
user_id
......@@ -160,11 +160,10 @@ export const changeUserContractFee = async function (user_id, symbol, fee_model,
let is_success = true;
let product_type = pair == 'all' ? 'lpc' : 'single';
//生效的费率 与要设置的费率 比对做校验 现在分不开 现货 合约 先不校验 之后分开了 再校验
/*let feeExist = await cancelIfFeeExist(user_id, product_type, symbol, maker_fee, taker_fee);
let feeExist = await cancelIfFeeExist(user_id, product_type, symbol, maker_fee, taker_fee);
if (feeExist) {
return is_success;
}*/
}
if (pair) {
await checkPair(symbol, 2);
}
......
......@@ -137,9 +137,9 @@ async function addParamValid(commonUserFeeVO: CommonUserFeeVO) {
throw ErrorCode.PARAM_MISS;
}
//撮合目前只支持 all 后续支持单个币对 可放开
if (pair != 'all'){
/*if (pair != 'all'){
throw ErrorCode.PAIR_NOT_SUPPORT;
}
}*/
//校验费率范围
if (type == FEE_TYPE.FEE_TYPE_SPOT){
if (Number(makerFee) < 0.0002 || Number(takerFee) < 0.0005){
......
......@@ -153,32 +153,36 @@ export async function add(commonUserFeeVO: CommonUserFeeVO, currentUserId: any,
let pair = dbInfo.pair;
let type = dbInfo.type;
let now = new Date();
let insertDbOne: any;
let insertDbList: any;
let rateLog = await buildSubmitItem(pair, dbInfo, now, dbInfo.user_channel);
let rateLogs = await buildSubmitItems(pair, dbInfo, now, dbInfo.user_channel);
//提交到log表
if (type == FEE_TYPE.FEE_TYPE_SPOT) {
insertDbOne = await feeRateSpotLog.prototype.create(rateLog, {
transaction: tx
insertDbList = await feeRateSpotLog.prototype.bulkCreate(rateLogs, {
transaction: tx,
returning: true
});
}
else if (type == FEE_TYPE.FEE_TYPE_BASE_COIN_CONTRACT) {//币本位
insertDbOne = await feeRateBaseCoinContractLog.prototype.create(rateLog, {
transaction: tx
insertDbList = await feeRateBaseCoinContractLog.prototype.bulkCreate(rateLogs, {
transaction: tx,
returning: true
});
}
else {//U本位
insertDbOne = await feeRateContractLog.prototype.create(rateLog, {
transaction: tx
insertDbList = await feeRateContractLog.prototype.bulkCreate(rateLogs, {
transaction: tx,
returning: true
});
}
let id = insertDbOne.id;
let idsList = insertDbList.map(item => item.id);
let ids = idsList.length ? idsList.join(",") : "";
await commonUserFeeSetting.prototype.update({
fee_log_ids: id.toString(),
fee_log_ids: ids,
update_time: new Date()
}, {
where: {
......@@ -216,7 +220,7 @@ export async function update(commonUserFeeVO: CommonUserFeeVO, currentUserId: an
let pair = dbInfo.pair;
let type = dbInfo.type;
if (dbInfo.user_id != commonUserFeeVO.user_id || type != commonUserFeeVO.type || commonUserFeeVO.pair != pair) {
if (Number(dbInfo.user_id) != Number(commonUserFeeVO.user_id) || Number(type) != Number(commonUserFeeVO.type) || commonUserFeeVO.pair != pair) {
throw ErrorCode.UID_TYPE_NOT_UPDATE;
}
if (dbInfo.status == 3 || dbInfo.status == 4) {
......@@ -225,31 +229,35 @@ export async function update(commonUserFeeVO: CommonUserFeeVO, currentUserId: an
let tx;
try {
tx = await ormDB.transaction();
let feeLogId: any;
let feeLogIds: 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 = await buildSubmitItem(pair, commonUserFeeVO, new Date(), Number(commonUserFeeVO.user_channel));
if (Number(commonUserFeeVO.maker_fee) != Number(dbInfo.maker_fee) || Number(commonUserFeeVO.taker_fee) != Number(dbInfo.taker_fee)
|| datetimeUtils.trim(commonUserFeeVO.begin_time, 's').getTime() != datetimeUtils.trim(dbInfo.begin_time, 's').getTime()
|| datetimeUtils.trim(commonUserFeeVO.expire_time, 's').getTime() != datetimeUtils.trim(dbInfo.expire_time, 's').getTime()) {
let insertDbList: any;
let rateLogs = await buildSubmitItems(pair, commonUserFeeVO, new Date(), Number(commonUserFeeVO.user_channel));
//提交到log表
if (type == FEE_TYPE.FEE_TYPE_SPOT) {
insertDbOne = await feeRateSpotLog.prototype.create(rateLog, {
transaction: tx
insertDbList = await feeRateSpotLog.prototype.bulkCreate(rateLogs, {
transaction: tx,
returning: true
});
}
else if (type == FEE_TYPE.FEE_TYPE_BASE_COIN_CONTRACT) {//币本位
insertDbOne = await feeRateBaseCoinContractLog.prototype.create(rateLog, {
transaction: tx
insertDbList = await feeRateBaseCoinContractLog.prototype.bulkCreate(rateLogs, {
transaction: tx,
returning: true
});
}
else {//U本位
insertDbOne = await feeRateContractLog.prototype.create(rateLog, {
transaction: tx
insertDbList = await feeRateContractLog.prototype.bulkCreate(rateLogs, {
transaction: tx,
returning: true
});
}
feeLogId = insertDbOne.id;
let idsList = insertDbList.map(item => item.id);
feeLogIds = idsList.length ? idsList.join(",") : dbInfo.fee_log_ids;
}
......@@ -264,7 +272,7 @@ export async function update(commonUserFeeVO: CommonUserFeeVO, currentUserId: an
amount_require_usdt: commonUserFeeVO.amount_require_usdt,
applicant: commonUserFeeVO.applicant,
update_time: new Date(),
fee_log_ids: feeLogId ? feeLogId.toString() : dbInfo.fee_log_ids,
fee_log_ids: feeLogIds,
}, {
where: {
id: Number(commonUserFeeVO.id)
......@@ -461,32 +469,51 @@ async function getDbFeeSetting(user_id: number | any, type: number | any, user_c
return dbInfo;
}
async function buildSubmitItem(pair: string, dbInfo: any, now: Date, user_channel: number) {
let item = {
user_id: dbInfo.user_id,
pair: pair,
fee_model: FEE_MODEL_SPOT_DEFAULT,
maker_fee: dbInfo.maker_fee,
taker_fee: dbInfo.taker_fee,
beginAt: dbInfo.begin_time,
expireAt: dbInfo.expire_time,
is_check: FEE_RATE_LOG_STATUS.CHECK_STATUS_UNCHECK,
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
async function buildSubmitItems(pair: string, dbInfo: any, now: Date, user_channel: number) {
let type = Number(dbInfo.type);
let submitItems: any = [];
let pairs: any = [];
//全部交易对时需要查询交易对表
if (pair == 'all') {
//现货
if (type == FEE_TYPE.FEE_TYPE_SPOT) {
pairs = await getAllSpotPairs();
}
else {//合约 这里目前查询的是 contract_pairs 如果之后 币本位的交易对有单独的表 需要修改此处代码
pairs = await getAllContractPairs();
}
}
else {
item.comment = COMMENT_USER_FEE_SUBMIT
pairs.push(pair);
}
for (let onePair of pairs) {
let item = {
user_id: dbInfo.user_id,
pair: onePair,
fee_model: FEE_MODEL_SPOT_DEFAULT,
maker_fee: dbInfo.maker_fee,
taker_fee: dbInfo.taker_fee,
beginAt: dbInfo.begin_time,
expireAt: dbInfo.expire_time,
is_check: FEE_RATE_LOG_STATUS.CHECK_STATUS_UNCHECK,
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;
submitItems.push(item);
}
return submitItems;
}
async function checkSpotPair(pair: string) {
......
......@@ -298,8 +298,8 @@ async function updateImageUrl(dbRealNameInfo: any) {
let identityFrondSide = dbRealNameInfo.identity_frond_side;
if (identityFrondSide) {
if (!identityFrondSide.includes("http")) {
dbRealNameInfo.identity_frond_side_small = await ossUtils.resizeWithWaterMark(identityFrondSide, "Madex", 300);
dbRealNameInfo.identity_frond_side = await ossUtils.withWaterMark(identityFrondSide, "Madex");
dbRealNameInfo.identity_frond_side_small = await ossUtils.resizeWithWaterMark(identityFrondSide, "KTX", 200);
dbRealNameInfo.identity_frond_side = await ossUtils.withWaterMark(identityFrondSide, "KTX");
}
else {
dbRealNameInfo.identity_frond_side_small = identityFrondSide
......@@ -313,8 +313,8 @@ async function updateImageUrl(dbRealNameInfo: any) {
let identityOtherSide = dbRealNameInfo.identity_other_side;
if (identityOtherSide) {
if (!identityOtherSide.includes("http")) {
dbRealNameInfo.identity_other_side_small = await ossUtils.resizeWithWaterMark(identityOtherSide, "Madex", 300);
dbRealNameInfo.identity_other_side = await ossUtils.withWaterMark(identityOtherSide, "Madex");
dbRealNameInfo.identity_other_side_small = await ossUtils.resizeWithWaterMark(identityOtherSide, "KTX", 200);
dbRealNameInfo.identity_other_side = await ossUtils.withWaterMark(identityOtherSide, "KTX");
}
else {
dbRealNameInfo.identity_other_side_small = identityOtherSide
......@@ -329,8 +329,8 @@ async function updateImageUrl(dbRealNameInfo: any) {
let identityInHand = dbRealNameInfo.identity_in_hand;
if (identityInHand) {
if (!identityInHand.includes("http")) {
dbRealNameInfo.identity_in_hand_small = await ossUtils.resizeWithWaterMark(identityInHand, "Madex", 300);
dbRealNameInfo.identity_in_hand = await ossUtils.withWaterMark(identityInHand, "Madex");
dbRealNameInfo.identity_in_hand_small = await ossUtils.resizeWithWaterMark(identityInHand, "KTX", 200);
dbRealNameInfo.identity_in_hand = await ossUtils.withWaterMark(identityInHand, "KTX");
}
else {
dbRealNameInfo.identity_in_hand_small = identityInHand
......@@ -345,8 +345,8 @@ async function updateImageUrl(dbRealNameInfo: any) {
let latestPhoto = dbRealNameInfo.latest_photo;
if (latestPhoto) {
if (!latestPhoto.includes("http")) {
dbRealNameInfo.latest_photo_small = await ossUtils.resizeWithWaterMark(latestPhoto, "Madex", 300);
dbRealNameInfo.latest_photo = await ossUtils.withWaterMark(latestPhoto, "Madex");
dbRealNameInfo.latest_photo_small = await ossUtils.resizeWithWaterMark(latestPhoto, "KTX", 200);
dbRealNameInfo.latest_photo = await ossUtils.withWaterMark(latestPhoto, "KTX");
}
else {
dbRealNameInfo.latest_photo_small = latestPhoto
......
......@@ -2,38 +2,20 @@ let { ossUtils } = require('@madex/ex-js-common');
let { logger } = require('@madex/ex-js-public');
const sizeOf = require('image-size');
const axios = require("axios");
/**
* 获取访问链接
* @param url
*/
export const getKycImageUrl = async function (url: string) {
return await getSignatureUrl(url)
}
/**
* 获取签名后的图片链接
*
* @param url
* @param style
* @param text
* @param font_size
*/
async function getSignatureUrl(url: string, style?: string | any) {
let res: string | any;
let newUrl = url.replace(/^\/+/, '');
if (style) {
res = await ossUtils.getUrlResize(newUrl, style);
}
else {
res = await ossUtils.getUrl(newUrl);
}
return res;
}
export const resizeWithWaterMark = async function (url: string, text: string, font_size?: number) {
let style = await watermarkStyle(text, font_size ? font_size : 60)
return await getSignatureUrl(url, style);
let waterUrl = await getWatermarkUrl(url, text, font_size ? font_size : 60)
return waterUrl;
}
export const getImageWidth = async function (urlStr: string) {
let getImageWidth = async function (urlStr: string) {
try {
let response = await axios({
url: urlStr,
......@@ -51,24 +33,29 @@ export const getImageWidth = async function (urlStr: string) {
}
export const withWaterMark = async function (url: string, text: string) {
let imgUrl = await getKycImageUrl(url);
let imgUrl = await ossUtils.getUrl(url);
let imageWidth = await getImageWidth(imgUrl);
if (imageWidth <= 0) {
imageWidth = 1000;
}
let fontSize = (imageWidth / 5);
let fontSize = Math.round((imageWidth / 5));
if (fontSize > 999) {
fontSize = 999;
}
let style = await watermarkStyle(text, fontSize);
return await getSignatureUrl(url, style);
let waterUrl = await getWatermarkUrl(url, text, fontSize);
return waterUrl;
}
export const watermarkStyle = async function (text: string, font_size?: number) {
/**
* 获取带水印的图片地址
* @param url url
* @param text 水印文案
* @param size 水印大小
*/
let getWatermarkUrl = async function (url: string, text: string, size?: number) {
let base64 = Buffer.from(text).toString('base64');
let textWatermark = base64.replace("+", "-").replace('/', '_').replace("=", "");
return "/watermark,text_" + textWatermark + ",g_center,x_10,y_10,t_10,fill_1,color_FFFFFF,size_" + font_size ? font_size : "";
return ossUtils.getUrlWatermark(url, textWatermark, size);
}
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