mirror of
https://github.com/mohamadihsan/topuponline.git
synced 2026-12-06 22:06:27 +00:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| db57e1682a |
@@ -86,38 +86,38 @@ const loadingBalanceRequest = async (req, res) => {
|
|||||||
`${uniqueCode} checking production card number or not...`
|
`${uniqueCode} checking production card number or not...`
|
||||||
);
|
);
|
||||||
|
|
||||||
// if (process.env.SERVER_FOR == 'production') {
|
if (process.env.SERVER_FOR == 'production') {
|
||||||
// if (card_number.substring(0, 1) != '1') {
|
if (card_number.substring(0, 1) != '1') {
|
||||||
// result = {
|
result = {
|
||||||
// code: '400',
|
code: '400',
|
||||||
// message: "It's not production card number.",
|
message: "It's not production card number.",
|
||||||
// data: {},
|
data: {},
|
||||||
// };
|
};
|
||||||
|
|
||||||
// // log warn
|
// log warn
|
||||||
// winston.logger.warn(
|
winston.logger.warn(
|
||||||
// `${uniqueCode} RESPONSE check reservation: ${JSON.stringify(result)}`
|
`${uniqueCode} RESPONSE check reservation: ${JSON.stringify(result)}`
|
||||||
// );
|
);
|
||||||
|
|
||||||
// return res.status(200).json(result);
|
return res.status(200).json(result);
|
||||||
// }
|
}
|
||||||
// } else {
|
} else {
|
||||||
// if (card_number.substring(0, 1) == '1') {
|
if (card_number.substring(0, 1) == '1') {
|
||||||
// result = {
|
result = {
|
||||||
// code: '400',
|
code: '400',
|
||||||
// message:
|
message:
|
||||||
// "It's production card number. Please use the development card number.",
|
"It's production card number. Please use the development card number.",
|
||||||
// data: {},
|
data: {},
|
||||||
// };
|
};
|
||||||
|
|
||||||
// // log warn
|
// log warn
|
||||||
// winston.logger.warn(
|
winston.logger.warn(
|
||||||
// `${uniqueCode} RESPONSE check reservation: ${JSON.stringify(result)}`
|
`${uniqueCode} RESPONSE check reservation: ${JSON.stringify(result)}`
|
||||||
// );
|
);
|
||||||
|
|
||||||
// return res.status(200).json(result);
|
return res.status(200).json(result);
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
|
|
||||||
// time
|
// time
|
||||||
let now = moment().format('YYYY-MM-DD HH:mm:ss');
|
let now = moment().format('YYYY-MM-DD HH:mm:ss');
|
||||||
@@ -192,69 +192,13 @@ const loadingBalanceRequest = async (req, res) => {
|
|||||||
winston.logger.debug(`${uniqueCode} checking reservation pending...`);
|
winston.logger.debug(`${uniqueCode} checking reservation pending...`);
|
||||||
|
|
||||||
// get total reservation pending
|
// get total reservation pending
|
||||||
let getReservationPending = await model.getReservationPendingV2(
|
let getReservationPending = await model.getReservationPending(
|
||||||
card_number,
|
card_number,
|
||||||
now,
|
now,
|
||||||
flag
|
flag
|
||||||
);
|
);
|
||||||
|
|
||||||
// cek disini apakah sebelumnya topup
|
|
||||||
const cardHistory = await model.checkCardHistory(card_number);
|
|
||||||
|
|
||||||
if (cardHistory.length > 0) {
|
|
||||||
if (cardHistory.i_log_name == 21 && cardHistory.c_source == 'CMS') {
|
|
||||||
if (getReservationPending.length > 0) {
|
|
||||||
// insert semua reserve balance ke fraud
|
|
||||||
const dataFraud = [];
|
|
||||||
const rsv = [];
|
|
||||||
for (const item of getReservationPending) {
|
|
||||||
rsv.push(item.c_reservation_no);
|
|
||||||
dataFraud.push({
|
|
||||||
c_card_number: item.c_card_number,
|
|
||||||
c_reservation_no: item.c_reservation_no,
|
|
||||||
i_reservation_amount: item.i_reservation_amount,
|
|
||||||
c_reservation_status: item.c_status,
|
|
||||||
c_reservation_flag: item.c_flag,
|
|
||||||
c_reservation_ref_no: item.c_ref_no,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
winston.logger.debug(
|
|
||||||
`${uniqueCode} INSERT TO trx.t_d_froud ${JSON.stringify(dataFraud)}`
|
|
||||||
);
|
|
||||||
const fraud = await model.insertFraud(dataFraud);
|
|
||||||
// log debug
|
|
||||||
winston.logger.debug(
|
|
||||||
`${uniqueCode} RESERVE NUMBER FROM trx.t_d_froud ${JSON.stringify(
|
|
||||||
fraud
|
|
||||||
)}`
|
|
||||||
);
|
|
||||||
winston.logger.debug(
|
|
||||||
`${uniqueCode} reserve number ${JSON.stringify(rsv)}`
|
|
||||||
);
|
|
||||||
|
|
||||||
// update reserve balance
|
|
||||||
await model.updateFraudToReserve(rsv);
|
|
||||||
} else {
|
|
||||||
result = {
|
|
||||||
code: '414',
|
|
||||||
message: "reservation doesn't exist",
|
|
||||||
data: {},
|
|
||||||
};
|
|
||||||
|
|
||||||
// log warn
|
|
||||||
winston.logger.warn(
|
|
||||||
`${uniqueCode} RESPONSE load balance validate: ${JSON.stringify(
|
|
||||||
result
|
|
||||||
)}`
|
|
||||||
);
|
|
||||||
|
|
||||||
return res.status(200).json(result);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// get total reservation pending with compare flag counter on card and the reservation transaction
|
// get total reservation pending with compare flag counter on card and the reservation transaction
|
||||||
// where status != -1
|
|
||||||
let getReservationPendingWithFlagCounter =
|
let getReservationPendingWithFlagCounter =
|
||||||
await model.getReservationPendingWithFlagCounter(card_number, now, flag);
|
await model.getReservationPendingWithFlagCounter(card_number, now, flag);
|
||||||
|
|
||||||
@@ -267,22 +211,13 @@ const loadingBalanceRequest = async (req, res) => {
|
|||||||
// await model.getReservationPendingWithFlag(card_number, now);
|
// await model.getReservationPendingWithFlag(card_number, now);
|
||||||
|
|
||||||
if (getReservationPendingWithFlagCounter.length > 0) {
|
if (getReservationPendingWithFlagCounter.length > 0) {
|
||||||
if (lastFlag) {
|
if (lastFlag && parseInt(lastFlag) <= parseInt(flag)) {
|
||||||
if (parseInt(lastFlag) <= parseInt(flag)) {
|
|
||||||
let reservationNumberPendingSuccessLoaded = [];
|
let reservationNumberPendingSuccessLoaded = [];
|
||||||
let loadBalanceNumberPendingSuccessLoaded = [];
|
let loadBalanceNumberPendingSuccessLoaded = [];
|
||||||
let totalReservationAmount = 0;
|
|
||||||
|
|
||||||
getReservationPendingWithFlagCounter.forEach((element) => {
|
getReservationPendingWithFlagCounter.forEach((element) => {
|
||||||
reservationNumberPendingSuccessLoaded.push(
|
reservationNumberPendingSuccessLoaded.push(element.c_reservation_no);
|
||||||
element.c_reservation_no
|
loadBalanceNumberPendingSuccessLoaded.push(element.c_load_balance_no);
|
||||||
);
|
|
||||||
if (element.c_load_balance_no) {
|
|
||||||
loadBalanceNumberPendingSuccessLoaded.push(
|
|
||||||
element.c_load_balance_no
|
|
||||||
);
|
|
||||||
}
|
|
||||||
totalReservationAmount += parseInt(element.i_reservation_amount);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// log debug
|
// log debug
|
||||||
@@ -299,9 +234,7 @@ const loadingBalanceRequest = async (req, res) => {
|
|||||||
card_number,
|
card_number,
|
||||||
balance,
|
balance,
|
||||||
flag,
|
flag,
|
||||||
uniqueCode,
|
uniqueCode
|
||||||
totalReservationAmount,
|
|
||||||
uid
|
|
||||||
);
|
);
|
||||||
|
|
||||||
if (insertUpdate) {
|
if (insertUpdate) {
|
||||||
@@ -342,7 +275,6 @@ const loadingBalanceRequest = async (req, res) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// log debug
|
// log debug
|
||||||
// winston.logger.debug(`${uniqueCode} updating flag to server...`);
|
// winston.logger.debug(`${uniqueCode} updating flag to server...`);
|
||||||
@@ -354,7 +286,7 @@ const loadingBalanceRequest = async (req, res) => {
|
|||||||
winston.logger.debug(`${uniqueCode} checking reservation pending...`);
|
winston.logger.debug(`${uniqueCode} checking reservation pending...`);
|
||||||
|
|
||||||
// reget total reservation pending
|
// reget total reservation pending
|
||||||
getReservationPending = await model.getReservationPendingV2(
|
getReservationPending = await model.getReservationPending(
|
||||||
card_number,
|
card_number,
|
||||||
now,
|
now,
|
||||||
flag
|
flag
|
||||||
@@ -377,6 +309,7 @@ const loadingBalanceRequest = async (req, res) => {
|
|||||||
return res.status(200).json(result);
|
return res.status(200).json(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let partialTopup = false;
|
||||||
let totalReservation = 0;
|
let totalReservation = 0;
|
||||||
let amountTopup = 0;
|
let amountTopup = 0;
|
||||||
let reservationNumber = [];
|
let reservationNumber = [];
|
||||||
@@ -407,11 +340,6 @@ const loadingBalanceRequest = async (req, res) => {
|
|||||||
return res.status(200).json(result);
|
return res.status(200).json(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
// log debug
|
|
||||||
winston.logger.debug(
|
|
||||||
`${uniqueCode} checking the card number in list fraud transaction or not...`
|
|
||||||
);
|
|
||||||
|
|
||||||
// log debug
|
// log debug
|
||||||
winston.logger.debug(`${uniqueCode} checking total topup amount...`);
|
winston.logger.debug(`${uniqueCode} checking total topup amount...`);
|
||||||
|
|
||||||
@@ -439,6 +367,12 @@ const loadingBalanceRequest = async (req, res) => {
|
|||||||
// get BI regulation status
|
// get BI regulation status
|
||||||
const getBIRegulationStatus = await model.getBIRegulationStatus();
|
const getBIRegulationStatus = await model.getBIRegulationStatus();
|
||||||
if (getBIRegulationStatus.c_value == 'A') {
|
if (getBIRegulationStatus.c_value == 'A') {
|
||||||
|
// log debug
|
||||||
|
winston.logger.debug(`${uniqueCode} checking topup partial status...`);
|
||||||
|
|
||||||
|
// check topup partial status
|
||||||
|
const getTopupPartialStatus = await model.getTopupPartialStatus();
|
||||||
|
|
||||||
// log debug
|
// log debug
|
||||||
winston.logger.debug(`${uniqueCode} checking max balance on the card...`);
|
winston.logger.debug(`${uniqueCode} checking max balance on the card...`);
|
||||||
|
|
||||||
@@ -449,6 +383,58 @@ const loadingBalanceRequest = async (req, res) => {
|
|||||||
parseInt(balance) + parseInt(amountTopup) >
|
parseInt(balance) + parseInt(amountTopup) >
|
||||||
parseInt(getMaxAmountOnTheCard.c_value)
|
parseInt(getMaxAmountOnTheCard.c_value)
|
||||||
) {
|
) {
|
||||||
|
// if topup partial is active
|
||||||
|
if (getTopupPartialStatus.c_value == 'A') {
|
||||||
|
// reset reservation data
|
||||||
|
partialTopup = true;
|
||||||
|
totalReservation = 0;
|
||||||
|
amountTopup = 0;
|
||||||
|
reservationNumber = [];
|
||||||
|
reservationNumberTemp = [];
|
||||||
|
i = 0;
|
||||||
|
|
||||||
|
// sum amount can be topup
|
||||||
|
getReservationPending.forEach((rsv) => {
|
||||||
|
if (
|
||||||
|
parseInt(balance) + parseInt(amountTopup) <=
|
||||||
|
parseInt(getMaxAmountOnTheCard.c_value)
|
||||||
|
) {
|
||||||
|
amountTopup += parseInt(rsv.i_reservation_amount);
|
||||||
|
if (
|
||||||
|
amountTopup > parseInt(getMaxAmountOnTheCard.c_value) ||
|
||||||
|
parseInt(balance) + amountTopup >
|
||||||
|
parseInt(getMaxAmountOnTheCard.c_value)
|
||||||
|
) {
|
||||||
|
amountTopup =
|
||||||
|
amountTopup - parseInt(rsv.i_reservation_amount);
|
||||||
|
i--;
|
||||||
|
} else {
|
||||||
|
reservationNumber.push(rsv.c_reservation_no);
|
||||||
|
reservationNumberTemp.push(rsv.c_reservation_no);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
});
|
||||||
|
|
||||||
|
totalReservation = i;
|
||||||
|
if (totalReservation == 0) {
|
||||||
|
result = {
|
||||||
|
code: '414',
|
||||||
|
message:
|
||||||
|
"reservation doesn't exist. Lowest amount exceeds the maximum balance",
|
||||||
|
data: {},
|
||||||
|
};
|
||||||
|
|
||||||
|
// log warn
|
||||||
|
winston.logger.warn(
|
||||||
|
`${uniqueCode} RESPONSE load balance validate: ${JSON.stringify(
|
||||||
|
result
|
||||||
|
)}`
|
||||||
|
);
|
||||||
|
|
||||||
|
return res.status(200).json(result);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
result = {
|
result = {
|
||||||
code: '416',
|
code: '416',
|
||||||
message: 'your card number has reached the maximum balance',
|
message: 'your card number has reached the maximum balance',
|
||||||
@@ -465,6 +451,7 @@ const loadingBalanceRequest = async (req, res) => {
|
|||||||
return res.status(200).json(result);
|
return res.status(200).json(result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// log debug
|
// log debug
|
||||||
winston.logger.debug(`${uniqueCode} checking max topup per month...`);
|
winston.logger.debug(`${uniqueCode} checking max topup per month...`);
|
||||||
@@ -489,6 +476,58 @@ const loadingBalanceRequest = async (req, res) => {
|
|||||||
parseInt(accumulatedBalance) + parseInt(amountTopup) >
|
parseInt(accumulatedBalance) + parseInt(amountTopup) >
|
||||||
parseInt(getMaxTopupPerMonth.c_value)
|
parseInt(getMaxTopupPerMonth.c_value)
|
||||||
) {
|
) {
|
||||||
|
// if topup partial is active
|
||||||
|
if (getTopupPartialStatus.c_value == 'A') {
|
||||||
|
// reset reservation data
|
||||||
|
partialTopup = true;
|
||||||
|
totalReservation = 0;
|
||||||
|
amountTopup = 0;
|
||||||
|
reservationNumber = [];
|
||||||
|
reservationNumberTemp = [];
|
||||||
|
i = 0;
|
||||||
|
|
||||||
|
// sum amount can be topup
|
||||||
|
getReservationPending.forEach((rsv) => {
|
||||||
|
if (
|
||||||
|
parseInt(balance) + parseInt(amountTopup) <=
|
||||||
|
parseInt(getMaxAmountOnTheCard.c_value)
|
||||||
|
) {
|
||||||
|
amountTopup += parseInt(rsv.i_reservation_amount);
|
||||||
|
if (
|
||||||
|
amountTopup > parseInt(getMaxAmountOnTheCard.c_value) ||
|
||||||
|
parseInt(balance) + amountTopup >
|
||||||
|
parseInt(getMaxAmountOnTheCard.c_value)
|
||||||
|
) {
|
||||||
|
amountTopup =
|
||||||
|
amountTopup - parseInt(rsv.i_reservation_amount);
|
||||||
|
i--;
|
||||||
|
} else {
|
||||||
|
reservationNumber.push(rsv.c_reservation_no);
|
||||||
|
reservationNumberTemp.push(rsv.c_reservation_no);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
});
|
||||||
|
|
||||||
|
totalReservation = i;
|
||||||
|
if (totalReservation == 0) {
|
||||||
|
result = {
|
||||||
|
code: '417',
|
||||||
|
message:
|
||||||
|
"reservation doesn't exist. Lowest amount exceeds the limit top up for this month",
|
||||||
|
data: {},
|
||||||
|
};
|
||||||
|
|
||||||
|
// log warn
|
||||||
|
winston.logger.warn(
|
||||||
|
`${uniqueCode} RESPONSE load balance validate: ${JSON.stringify(
|
||||||
|
result
|
||||||
|
)}`
|
||||||
|
);
|
||||||
|
|
||||||
|
return res.status(200).json(result);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
result = {
|
result = {
|
||||||
code: '417',
|
code: '417',
|
||||||
message: 'your card number has been limit top up for this month',
|
message: 'your card number has been limit top up for this month',
|
||||||
@@ -506,23 +545,16 @@ const loadingBalanceRequest = async (req, res) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// log debug
|
// log debug
|
||||||
winston.logger.debug(
|
winston.logger.debug(
|
||||||
`${uniqueCode} updating status reservation to in progress...${reservationNumberTemp}, ${now}, ${flag}`
|
`${uniqueCode} updating status reservation to in progress...`
|
||||||
);
|
);
|
||||||
|
|
||||||
// update status to in progress
|
// update status to in progress
|
||||||
let updateStatusReservation = await model.updateStatusReservation(
|
await model.updateStatusReservation(reservationNumberTemp, now);
|
||||||
reservationNumberTemp,
|
|
||||||
now,
|
|
||||||
flag
|
|
||||||
);
|
|
||||||
|
|
||||||
// log debug
|
|
||||||
winston.logger.debug(`${uniqueCode} XXXXX ${updateStatusReservation}`);
|
|
||||||
|
|
||||||
if (updateStatusReservation) {
|
|
||||||
result = {
|
result = {
|
||||||
code: '00',
|
code: '00',
|
||||||
message: 'reservation exists',
|
message: 'reservation exists',
|
||||||
@@ -530,33 +562,14 @@ const loadingBalanceRequest = async (req, res) => {
|
|||||||
amount: amountTopup,
|
amount: amountTopup,
|
||||||
total_reservation: totalReservation,
|
total_reservation: totalReservation,
|
||||||
reservation_number: reservationNumber,
|
reservation_number: reservationNumber,
|
||||||
|
partial_topup: partialTopup,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
// log info
|
// log info
|
||||||
winston.logger.info(
|
winston.logger.info(
|
||||||
`${uniqueCode} RESPONSE load balance validate: ${JSON.stringify(
|
`${uniqueCode} RESPONSE load balance validate: ${JSON.stringify(result)}`
|
||||||
result
|
|
||||||
)}`
|
|
||||||
);
|
);
|
||||||
} else {
|
|
||||||
result = {
|
|
||||||
code: '434',
|
|
||||||
message: '[434] Failed, please try again later',
|
|
||||||
data: {
|
|
||||||
amount: amountTopup,
|
|
||||||
total_reservation: totalReservation,
|
|
||||||
reservation_number: reservationNumber,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
// log info
|
|
||||||
winston.logger.info(
|
|
||||||
`${uniqueCode} RESPONSE load balance validate: ${JSON.stringify(
|
|
||||||
result
|
|
||||||
)}`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return res.json(result);
|
return res.json(result);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -624,38 +637,38 @@ const loadingBalance = async (req, res) => {
|
|||||||
`${uniqueCode} checking production card number or not...`
|
`${uniqueCode} checking production card number or not...`
|
||||||
);
|
);
|
||||||
|
|
||||||
// if (process.env.SERVER_FOR == 'production') {
|
if (process.env.SERVER_FOR == 'production') {
|
||||||
// if (card_number.substring(0, 1) != '1') {
|
if (card_number.substring(0, 1) != '1') {
|
||||||
// result = {
|
result = {
|
||||||
// code: '400',
|
code: '400',
|
||||||
// message: "It's not production card number.",
|
message: "It's not production card number.",
|
||||||
// data: {},
|
data: {},
|
||||||
// };
|
};
|
||||||
|
|
||||||
// // log warn
|
// log warn
|
||||||
// winston.logger.warn(
|
winston.logger.warn(
|
||||||
// `${uniqueCode} RESPONSE check reservation: ${JSON.stringify(result)}`
|
`${uniqueCode} RESPONSE check reservation: ${JSON.stringify(result)}`
|
||||||
// );
|
);
|
||||||
|
|
||||||
// return res.status(200).json(result);
|
return res.status(200).json(result);
|
||||||
// }
|
}
|
||||||
// } else {
|
} else {
|
||||||
// if (card_number.substring(0, 1) == '1') {
|
if (card_number.substring(0, 1) == '1') {
|
||||||
// result = {
|
result = {
|
||||||
// code: '400',
|
code: '400',
|
||||||
// message:
|
message:
|
||||||
// "It's production card number. Please use the development card number.",
|
"It's production card number. Please use the development card number.",
|
||||||
// data: {},
|
data: {},
|
||||||
// };
|
};
|
||||||
|
|
||||||
// // log warn
|
// log warn
|
||||||
// winston.logger.warn(
|
winston.logger.warn(
|
||||||
// `${uniqueCode} RESPONSE check reservation: ${JSON.stringify(result)}`
|
`${uniqueCode} RESPONSE check reservation: ${JSON.stringify(result)}`
|
||||||
// );
|
);
|
||||||
|
|
||||||
// return res.status(200).json(result);
|
return res.status(200).json(result);
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
|
|
||||||
// time
|
// time
|
||||||
let now = moment().format('YYYY-MM-DD HH:mm:ss');
|
let now = moment().format('YYYY-MM-DD HH:mm:ss');
|
||||||
@@ -768,7 +781,7 @@ const loadingBalance = async (req, res) => {
|
|||||||
amountTopup += parseInt(rsv.i_reservation_amount);
|
amountTopup += parseInt(rsv.i_reservation_amount);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (parseInt(amount) != parseInt(amountTopup)) {
|
if (amount != amountTopup) {
|
||||||
result = {
|
result = {
|
||||||
code: '418',
|
code: '418',
|
||||||
message: 'topup amount is different',
|
message: 'topup amount is different',
|
||||||
@@ -1052,8 +1065,8 @@ const loadingBalanceInsert = async (param) => {
|
|||||||
let now = moment().format('YYYY-MM-DD HH:mm:ss');
|
let now = moment().format('YYYY-MM-DD HH:mm:ss');
|
||||||
let today = moment().format('YYYY-MM-DD');
|
let today = moment().format('YYYY-MM-DD');
|
||||||
|
|
||||||
// log warn
|
// log debug
|
||||||
winston.logger.warn(`${uniqueCode} checking partner...`);
|
winston.logger.debug(`${uniqueCode} checking partner...`);
|
||||||
|
|
||||||
// get partner, merchant, terminal from tid
|
// get partner, merchant, terminal from tid
|
||||||
let getPartner = await model.getPartner(mid, tid);
|
let getPartner = await model.getPartner(mid, tid);
|
||||||
@@ -1072,8 +1085,8 @@ const loadingBalanceInsert = async (param) => {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
// log warn
|
// log debug
|
||||||
winston.logger.warn(`${uniqueCode} checking reservation status...`);
|
winston.logger.debug(`${uniqueCode} checking reservation status...`);
|
||||||
|
|
||||||
// check reservation status
|
// check reservation status
|
||||||
for (let index = 0; index < reservation_number.length; index++) {
|
for (let index = 0; index < reservation_number.length; index++) {
|
||||||
@@ -1081,7 +1094,6 @@ const loadingBalanceInsert = async (param) => {
|
|||||||
reservation_number[index]
|
reservation_number[index]
|
||||||
);
|
);
|
||||||
|
|
||||||
// if reservation doesn't exist or has been canceled
|
|
||||||
if (!reservationStatus) {
|
if (!reservationStatus) {
|
||||||
result = {
|
result = {
|
||||||
code: '414',
|
code: '414',
|
||||||
@@ -1099,14 +1111,10 @@ const loadingBalanceInsert = async (param) => {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
// if there are reservation with status active
|
|
||||||
if (reservationStatus.c_status == 'A') {
|
if (reservationStatus.c_status == 'A') {
|
||||||
// if there are reservation on load balance table transaction but before process on reservation failed update to LOADED
|
var reservationLoaded = await model.findReservationLoaded(
|
||||||
let reservationLoaded = await model.findReservationLoaded(
|
|
||||||
reservationStatus.i_reservation_balance
|
reservationStatus.i_reservation_balance
|
||||||
);
|
);
|
||||||
|
|
||||||
if (reservationLoaded) {
|
|
||||||
let loadBalanceNumberExisting = reservationLoaded.c_load_balance_no;
|
let loadBalanceNumberExisting = reservationLoaded.c_load_balance_no;
|
||||||
let loadDate = reservationLoaded.d_load_balance;
|
let loadDate = reservationLoaded.d_load_balance;
|
||||||
result = {
|
result = {
|
||||||
@@ -1129,67 +1137,15 @@ const loadingBalanceInsert = async (param) => {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// log warn
|
// log debug
|
||||||
winston.logger.warn(`${uniqueCode} checking last log history...`);
|
winston.logger.debug(`${uniqueCode} checking reservation pending...`);
|
||||||
|
|
||||||
// get last history by card number
|
// get total reservation pending
|
||||||
let lastHistory = await model.getLastHistory(card_number);
|
let getReservationPending = await model.getReservationPending(
|
||||||
|
|
||||||
if (lastHistory) {
|
|
||||||
// if last history card is topup 21 = log name id for topup and source is CMS, that mean topup with online source)
|
|
||||||
if (lastHistory.i_log_name == 21 && lastHistory.c_source == 'CMS') {
|
|
||||||
// log warn
|
|
||||||
winston.logger.warn(`${uniqueCode} inserting fraud transaction...`);
|
|
||||||
|
|
||||||
// insert reservation transaction to fraud table
|
|
||||||
await model.insertFraudTransaction(reservation_number);
|
|
||||||
|
|
||||||
// log warn
|
|
||||||
winston.logger.warn(`${uniqueCode} suspending reservation...`);
|
|
||||||
|
|
||||||
// update reservation with suspend status
|
|
||||||
await model.suspendReservation(reservation_number, now);
|
|
||||||
|
|
||||||
result = {
|
|
||||||
code: '432',
|
|
||||||
message: 'your card number has fraud transaction',
|
|
||||||
data: {},
|
|
||||||
};
|
|
||||||
|
|
||||||
// log warn
|
|
||||||
winston.logger.warn(
|
|
||||||
`${uniqueCode} RESPONSE load balance insert: ${JSON.stringify(
|
|
||||||
result
|
|
||||||
)}`
|
|
||||||
);
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// log warn
|
|
||||||
winston.logger.warn(`${uniqueCode} checking fraud transaction...`);
|
|
||||||
|
|
||||||
// get data fraud by card number and status fraud is not closed
|
|
||||||
let fraudTransaction = await model.getFraudTransaction(card_number);
|
|
||||||
let fraudReservationNumber = [];
|
|
||||||
|
|
||||||
if (fraudTransaction.length > 0) {
|
|
||||||
fraudTransaction.forEach((rsv) => {
|
|
||||||
fraudReservationNumber.push(rsv.c_reservation_no);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// log warn
|
|
||||||
winston.logger.warn(`${uniqueCode} checking reservation pending...`);
|
|
||||||
|
|
||||||
// get total reservation pending without fraud
|
|
||||||
let getReservationPending = await model.getReservationPendingWithoutFraud(
|
|
||||||
card_number,
|
card_number,
|
||||||
flag,
|
now,
|
||||||
fraudReservationNumber
|
flag
|
||||||
);
|
);
|
||||||
|
|
||||||
if (getReservationPending.length < 1) {
|
if (getReservationPending.length < 1) {
|
||||||
@@ -1207,8 +1163,8 @@ const loadingBalanceInsert = async (param) => {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
// log warn
|
// log debug
|
||||||
winston.logger.warn(`${uniqueCode} checking total topup amount...`);
|
winston.logger.debug(`${uniqueCode} checking total topup amount...`);
|
||||||
|
|
||||||
// check total topup and request topup
|
// check total topup and request topup
|
||||||
let amountTopup = 0;
|
let amountTopup = 0;
|
||||||
@@ -1216,7 +1172,7 @@ const loadingBalanceInsert = async (param) => {
|
|||||||
amountTopup += parseInt(rsv.i_reservation_amount);
|
amountTopup += parseInt(rsv.i_reservation_amount);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (parseInt(amount) != parseInt(amountTopup)) {
|
if (amount != amountTopup) {
|
||||||
result = {
|
result = {
|
||||||
code: '418',
|
code: '418',
|
||||||
message: 'topup amount is different',
|
message: 'topup amount is different',
|
||||||
@@ -1249,8 +1205,8 @@ const loadingBalanceInsert = async (param) => {
|
|||||||
? parseInt(getLoadBalanceSequence.i_load_balance_no_seq) + 1
|
? parseInt(getLoadBalanceSequence.i_load_balance_no_seq) + 1
|
||||||
: 1;
|
: 1;
|
||||||
|
|
||||||
// log warn
|
// log debug
|
||||||
winston.logger.warn(`${uniqueCode} generating load balance number...`);
|
winston.logger.debug(`${uniqueCode} generating load balance number...`);
|
||||||
|
|
||||||
loadBalanceNumber = await generateLoadBalanceNumber(
|
loadBalanceNumber = await generateLoadBalanceNumber(
|
||||||
getPartner,
|
getPartner,
|
||||||
@@ -1258,11 +1214,6 @@ const loadingBalanceInsert = async (param) => {
|
|||||||
loadBalanceNoSequence
|
loadBalanceNoSequence
|
||||||
);
|
);
|
||||||
|
|
||||||
// log warn
|
|
||||||
winston.logger.warn(
|
|
||||||
`${uniqueCode} load balance number is ${loadBalanceNumber}.`
|
|
||||||
);
|
|
||||||
|
|
||||||
if (maxLoop > 20) {
|
if (maxLoop > 20) {
|
||||||
// create log
|
// create log
|
||||||
winston.logger.error(
|
winston.logger.error(
|
||||||
@@ -1324,13 +1275,8 @@ const loadingBalanceInsert = async (param) => {
|
|||||||
winston.logger.debug(`${uniqueCode} getting reservation detail...`);
|
winston.logger.debug(`${uniqueCode} getting reservation detail...`);
|
||||||
|
|
||||||
let detail = [];
|
let detail = [];
|
||||||
reservation_number = [];
|
for (let index = 0; index < reservation_number.length; index++) {
|
||||||
for (let index = 0; index < getReservationPending.length; index++) {
|
let reservation = await model.findReservation(reservation_number[index]);
|
||||||
reservation_number.push(getReservationPending[index].c_reservation_no);
|
|
||||||
|
|
||||||
let reservation = await model.findReservation(
|
|
||||||
getReservationPending[index].c_reservation_no
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!reservation) {
|
if (!reservation) {
|
||||||
result = {
|
result = {
|
||||||
@@ -1391,11 +1337,11 @@ const loadingBalanceInsert = async (param) => {
|
|||||||
`${uniqueCode} checking load balance transaction has been exists or not...`
|
`${uniqueCode} checking load balance transaction has been exists or not...`
|
||||||
);
|
);
|
||||||
|
|
||||||
// log warn
|
// log debug
|
||||||
winston.logger.warn(`${uniqueCode} inserting load balance transaction...`);
|
winston.logger.debug(`${uniqueCode} inserting load balance transaction...`);
|
||||||
|
|
||||||
// insert transaction
|
// insert transaction
|
||||||
let insertLoadingBalance = await model.insertLoadingBalance(
|
await model.insertLoadingBalance(
|
||||||
data,
|
data,
|
||||||
detail,
|
detail,
|
||||||
reservation_number,
|
reservation_number,
|
||||||
@@ -1407,22 +1353,6 @@ const loadingBalanceInsert = async (param) => {
|
|||||||
flag
|
flag
|
||||||
);
|
);
|
||||||
|
|
||||||
// log warn
|
|
||||||
winston.logger.warn(
|
|
||||||
`${uniqueCode} AAAAAAAAAAAAAAAAAA [DATA] : ${JSON.stringify(
|
|
||||||
data
|
|
||||||
)} [DETAIL] : ${JSON.stringify(detail)} [RSV] : ${JSON.stringify(
|
|
||||||
reservation_number
|
|
||||||
)} [NOW] : ${JSON.stringify(now)} [WRITE STATUS] : ${JSON.stringify(
|
|
||||||
write_status
|
|
||||||
)} [CARD NUMBER] : ${JSON.stringify(
|
|
||||||
card_number
|
|
||||||
)} [UID] : ${JSON.stringify(uid)} [BALANCE] : ${JSON.stringify(
|
|
||||||
balance
|
|
||||||
)} [FLAG] : ${JSON.stringify(flag)}`
|
|
||||||
);
|
|
||||||
|
|
||||||
if (insertLoadingBalance > 0) {
|
|
||||||
result = {
|
result = {
|
||||||
code: '00',
|
code: '00',
|
||||||
message: write_status
|
message: write_status
|
||||||
@@ -1437,20 +1367,6 @@ const loadingBalanceInsert = async (param) => {
|
|||||||
winston.logger.info(
|
winston.logger.info(
|
||||||
`${uniqueCode} RESPONSE load balance insert: ${JSON.stringify(result)}`
|
`${uniqueCode} RESPONSE load balance insert: ${JSON.stringify(result)}`
|
||||||
);
|
);
|
||||||
} else {
|
|
||||||
result = {
|
|
||||||
code: '433',
|
|
||||||
message: '[433] Failed, please try again later',
|
|
||||||
data: {
|
|
||||||
load_balance_number: loadBalanceNumber,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
// log warn
|
|
||||||
winston.logger.warn(
|
|
||||||
`${uniqueCode} RESPONSE load balance insert: ${JSON.stringify(result)}`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -1980,9 +1896,7 @@ const updateReservationAndLoadingBalance = async (
|
|||||||
cardNumber,
|
cardNumber,
|
||||||
balance,
|
balance,
|
||||||
flag,
|
flag,
|
||||||
uniqueCode,
|
uniqueCode
|
||||||
totalReservationAmount,
|
|
||||||
uid
|
|
||||||
) => {
|
) => {
|
||||||
try {
|
try {
|
||||||
// log debug
|
// log debug
|
||||||
@@ -1995,18 +1909,17 @@ const updateReservationAndLoadingBalance = async (
|
|||||||
|
|
||||||
// get load balance
|
// get load balance
|
||||||
let dataLoadingBalance = null;
|
let dataLoadingBalance = null;
|
||||||
let dataLoadingBalanceDetail = [];
|
|
||||||
|
|
||||||
if (loadBalanceNumber.length > 0) {
|
|
||||||
let getLastLoadingBalanceFlag = await model.getLastLoadingBalanceFlag(
|
let getLastLoadingBalanceFlag = await model.getLastLoadingBalanceFlag(
|
||||||
loadBalanceNumber
|
loadBalanceNumber
|
||||||
);
|
);
|
||||||
if (getLastLoadingBalanceFlag) {
|
if (getLastLoadingBalanceFlag) {
|
||||||
dataLoadingBalance = getLastLoadingBalanceFlag;
|
dataLoadingBalance = getLastLoadingBalanceFlag;
|
||||||
}
|
} else {
|
||||||
|
// insert new load balance transaction by data on card and update data reservation
|
||||||
}
|
}
|
||||||
|
|
||||||
// get detail load balance
|
// get detail load balance
|
||||||
|
let dataLoadingBalanceDetail = [];
|
||||||
if (dataLoadingBalance) {
|
if (dataLoadingBalance) {
|
||||||
// log debug
|
// log debug
|
||||||
winston.logger.debug(
|
winston.logger.debug(
|
||||||
@@ -2022,12 +1935,12 @@ const updateReservationAndLoadingBalance = async (
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (dataLoadingBalance && dataLoadingBalanceDetail.length > 0) {
|
||||||
// time
|
// time
|
||||||
let now = moment().format('YYYY-MM-DD HH:mm:ss');
|
let now = moment().format('YYYY-MM-DD HH:mm:ss');
|
||||||
let today = moment().format('YYYY-MM-DD');
|
let today = moment().format('YYYY-MM-DD');
|
||||||
let getPartner = await model.getPartner(mid, tid);
|
let getPartner = await model.getPartner(mid, tid);
|
||||||
|
|
||||||
if (dataLoadingBalance && dataLoadingBalanceDetail.length > 0) {
|
|
||||||
let data = {
|
let data = {
|
||||||
c_load_balance_no: dataLoadingBalance.c_load_balance_no,
|
c_load_balance_no: dataLoadingBalance.c_load_balance_no,
|
||||||
d_load_balance: dataLoadingBalance.d_load_balance,
|
d_load_balance: dataLoadingBalance.d_load_balance,
|
||||||
@@ -2107,176 +2020,8 @@ const updateReservationAndLoadingBalance = async (
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
// insert new load balance transaction by data on card and update data reservation
|
|
||||||
|
|
||||||
// log debug
|
|
||||||
winston.logger.debug(
|
|
||||||
`${uniqueCode} generating and insert new data load balance...`
|
|
||||||
);
|
|
||||||
|
|
||||||
// generate load balance number
|
|
||||||
let newLoadBalanceNumber;
|
|
||||||
let getLoadBalanceSequence;
|
|
||||||
let loadBalanceNoSequence;
|
|
||||||
let maxLoop = 0;
|
|
||||||
do {
|
|
||||||
// log debug
|
|
||||||
winston.logger.debug(
|
|
||||||
`${uniqueCode} getting loading balance sequence...`
|
|
||||||
);
|
|
||||||
|
|
||||||
// get loading balance
|
|
||||||
getLoadBalanceSequence = await model.getLoadBalanceSequence(
|
|
||||||
getPartner,
|
|
||||||
today
|
|
||||||
);
|
|
||||||
loadBalanceNoSequence = getLoadBalanceSequence
|
|
||||||
? parseInt(getLoadBalanceSequence.i_load_balance_no_seq) + 1
|
|
||||||
: 1;
|
|
||||||
|
|
||||||
// log warn
|
|
||||||
winston.logger.warn(`${uniqueCode} generating load balance number...`);
|
|
||||||
|
|
||||||
newLoadBalanceNumber = await generateLoadBalanceNumber(
|
|
||||||
getPartner,
|
|
||||||
moment(today).format('YYMMDD'),
|
|
||||||
loadBalanceNoSequence
|
|
||||||
);
|
|
||||||
|
|
||||||
// log warn
|
|
||||||
winston.logger.warn(
|
|
||||||
`${uniqueCode} load balance number is ${newLoadBalanceNumber}.`
|
|
||||||
);
|
|
||||||
|
|
||||||
if (maxLoop > 20) {
|
|
||||||
// create log
|
|
||||||
winston.logger.error(
|
|
||||||
`500 internal server error (max loop) - backend server | ${error.message}`
|
|
||||||
);
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
maxLoop++;
|
|
||||||
} while (newLoadBalanceNumber == 'XX');
|
|
||||||
|
|
||||||
let dataLoadBalance = {
|
|
||||||
c_load_balance_no: newLoadBalanceNumber,
|
|
||||||
d_load_balance: now,
|
|
||||||
c_ref_no: null,
|
|
||||||
i_partner: getPartner.i_partner,
|
|
||||||
c_partner_code: getPartner.partner_code,
|
|
||||||
c_partner_name: getPartner.partner_name,
|
|
||||||
i_merchant: getPartner.i_merchant,
|
|
||||||
c_merchant_code: getPartner.merchant_code,
|
|
||||||
c_merchant_name: getPartner.merchant_name,
|
|
||||||
c_mid: getPartner.mid,
|
|
||||||
i_terminal: getPartner.i_terminal,
|
|
||||||
c_terminal_code: getPartner.terminal_code,
|
|
||||||
c_terminal_name: getPartner.terminal_name,
|
|
||||||
c_tid: getPartner.tid,
|
|
||||||
c_card_number: cardNumber,
|
|
||||||
i_topup_amount: totalReservationAmount,
|
|
||||||
m_balance: balance,
|
|
||||||
c_return_sap: null,
|
|
||||||
i_load_balance_no_seq: loadBalanceNoSequence,
|
|
||||||
c_idm: uid,
|
|
||||||
c_status: 'A',
|
|
||||||
c_status_name: 'SUCCESS',
|
|
||||||
d_create: now,
|
|
||||||
i_create: null,
|
|
||||||
c_create_username: null,
|
|
||||||
c_create_fullname: null,
|
|
||||||
d_modify: null,
|
|
||||||
i_modify: null,
|
|
||||||
c_modify_username: null,
|
|
||||||
c_modify_fullname: null,
|
|
||||||
d_delete: null,
|
|
||||||
i_delete: null,
|
|
||||||
c_delete_username: null,
|
|
||||||
c_delete_fullname: null,
|
|
||||||
};
|
|
||||||
|
|
||||||
// create detaial load balance
|
|
||||||
let detailLoadBalance =
|
|
||||||
await model.createDetailLoadBalanceFromReservation(reservationNumber);
|
|
||||||
|
|
||||||
// log debug
|
|
||||||
winston.logger.debug(
|
|
||||||
`${uniqueCode} detail load balance with reservation no : ${JSON.stringify(
|
|
||||||
reservationNumber
|
|
||||||
)}`
|
|
||||||
);
|
|
||||||
|
|
||||||
if (detailLoadBalance.length > 0) {
|
|
||||||
// log warn
|
|
||||||
winston.logger.warn(
|
|
||||||
`${uniqueCode} AAAAAAAAAAAAAAAAAA1111 [DATA] : ${JSON.stringify(
|
|
||||||
reservationNumber
|
|
||||||
)} [LB] : ${JSON.stringify(dataLoadBalance)} [LBD] : ${JSON.stringify(
|
|
||||||
detailLoadBalance
|
|
||||||
)} [NOW] : ${JSON.stringify(now)} [FLAG] : ${JSON.stringify(flag)}`
|
|
||||||
);
|
|
||||||
|
|
||||||
// log debug
|
|
||||||
winston.logger.debug(
|
|
||||||
`${uniqueCode} updating reservation and insert new load balance transaction...`
|
|
||||||
);
|
|
||||||
|
|
||||||
// update reservation and load balance transaction
|
|
||||||
let updateReservationAndInsertLoadingBalance =
|
|
||||||
await model.updateReservationAndInsertLoadingBalance(
|
|
||||||
reservationNumber,
|
|
||||||
dataLoadBalance,
|
|
||||||
detailLoadBalance,
|
|
||||||
now,
|
|
||||||
flag
|
|
||||||
);
|
|
||||||
|
|
||||||
// log debug
|
|
||||||
winston.logger.debug(
|
|
||||||
`${uniqueCode} status insert new load balance and update reservation : ${JSON.stringify(
|
|
||||||
updateReservationAndInsertLoadingBalance
|
|
||||||
)}`
|
|
||||||
);
|
|
||||||
|
|
||||||
// if (updateReservationAndInsertLoadingBalance > 0) {
|
|
||||||
// // log debug
|
|
||||||
// winston.logger.debug(
|
|
||||||
// `${uniqueCode} inserting log for card history...`
|
|
||||||
// );
|
|
||||||
|
|
||||||
// // log card history
|
|
||||||
// await model.createLoadBalanceLog({
|
|
||||||
// i_log_name:21,
|
|
||||||
// d_log: dataLoadingBalance.d_load_balance,
|
|
||||||
// c_card_number: cardNumber,
|
|
||||||
// c_source: 'CMS',
|
|
||||||
// c_location: getPartner ? getPartner.partner_name : null,
|
|
||||||
// m_balance_before: parseInt(dataLoadingBalance.m_balance),
|
|
||||||
// m_amount: parseInt(dataLoadingBalance.i_topup_amount),
|
|
||||||
// m_balance_after: parseInt(balance),
|
|
||||||
// j_new_data: { data: data, detail: dataLoadingBalanceDetail },
|
|
||||||
// j_old_data: null,
|
|
||||||
// c_note: `LOAD BALANCE ${dataLoadingBalance.i_topup_amount} FROM ${
|
|
||||||
// getPartner ? getPartner.partner_name : null
|
|
||||||
// } SUCCESSFULLY`,
|
|
||||||
// c_status: 'S',
|
|
||||||
// d_created: now,
|
|
||||||
// i_create: null,
|
|
||||||
// c_create_username: 'HSM',
|
|
||||||
// c_create_fullname: 'HARDWARE SECURE MODULE',
|
|
||||||
// c_category: 'T',
|
|
||||||
// });
|
|
||||||
// } else {
|
|
||||||
// return false;
|
|
||||||
// }
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// create log
|
// create log
|
||||||
winston.logger.error(
|
winston.logger.error(
|
||||||
|
|||||||
@@ -72,33 +72,8 @@ const getReservationPending = (cardNumber, time, flag) => {
|
|||||||
// .where("d_expired", ">=", time)
|
// .where("d_expired", ">=", time)
|
||||||
.where(function () {
|
.where(function () {
|
||||||
this.orWhere('c_flag', flag).orWhere('c_flag', '-1');
|
this.orWhere('c_flag', flag).orWhere('c_flag', '-1');
|
||||||
});
|
})
|
||||||
|
.orderBy('i_reservation_amount', 'asc');
|
||||||
return result;
|
|
||||||
};
|
|
||||||
const getReservationPendingV2 = (cardNumber, time, flag) => {
|
|
||||||
let result = knex('trx.t_d_reservation_balance')
|
|
||||||
// .sum("i_reservation_amount as total_reservation_amount")
|
|
||||||
// .count("* as total_reservation")
|
|
||||||
.select(
|
|
||||||
'i_reservation_amount',
|
|
||||||
'c_reservation_no',
|
|
||||||
'c_flag',
|
|
||||||
'd_reservation',
|
|
||||||
'c_ref_no',
|
|
||||||
'c_card_number',
|
|
||||||
'c_status'
|
|
||||||
)
|
|
||||||
.where('c_card_number', cardNumber)
|
|
||||||
.whereIn('c_status', ['P', 'I'])
|
|
||||||
// .where("d_expired", ">=", time)
|
|
||||||
.whereRaw(
|
|
||||||
`c_reservation_no NOT IN (SELECT c_reservation_no FROM trx.t_d_fraud tdf WHERE tdf.c_status = 'A' AND tdf.c_card_number = '${cardNumber}')`
|
|
||||||
)
|
|
||||||
.where(function () {
|
|
||||||
this.orWhere('c_flag', flag).orWhere('c_flag', '-1');
|
|
||||||
});
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -121,28 +96,6 @@ const getReservationPendingWithFlagCounter = (cardNumber, time, flag) => {
|
|||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
// GET RESERVATION PENDING WITH COMPARE FLAG COUNTER
|
|
||||||
const getReservationPendingWithFlagCounterV2 = (cardNumber, time, flag) => {
|
|
||||||
let result = knex('trx.t_d_reservation_balance')
|
|
||||||
// .sum("i_reservation_amount as total_reservation_amount")
|
|
||||||
// .count("* as total_reservation")
|
|
||||||
.select(
|
|
||||||
'i_reservation_amount',
|
|
||||||
'c_reservation_no',
|
|
||||||
'c_flag',
|
|
||||||
'c_load_balance_no'
|
|
||||||
)
|
|
||||||
.where('c_card_number', cardNumber)
|
|
||||||
.whereIn('c_status', ['P', 'I'])
|
|
||||||
.whereRaw('??::INT < ??', ['c_flag', parseInt(flag)])
|
|
||||||
.whereRaw(
|
|
||||||
`c_reservation_no NOT IN (SELECT c_reservation_no FROM trx.t_d_fraud tdf WHERE tdf.c_status = 'A' AND tdf.c_card_number = '${cardNumber}')`
|
|
||||||
)
|
|
||||||
// .where("d_expired", ">=", time)
|
|
||||||
.where('c_flag', '!=', '-1');
|
|
||||||
return result;
|
|
||||||
};
|
|
||||||
|
|
||||||
// GET RESERVATION PENDING WITH FLAG
|
// GET RESERVATION PENDING WITH FLAG
|
||||||
const getReservationPendingWithFlag = (cardNumber, time) => {
|
const getReservationPendingWithFlag = (cardNumber, time) => {
|
||||||
let result = knex('trx.t_d_reservation_balance')
|
let result = knex('trx.t_d_reservation_balance')
|
||||||
@@ -155,21 +108,6 @@ const getReservationPendingWithFlag = (cardNumber, time) => {
|
|||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
// GET RESERVATION PENDING WITH FLAG
|
|
||||||
const getReservationPendingWithFlagV2 = (cardNumber, time) => {
|
|
||||||
let result = knex('trx.t_d_reservation_balance')
|
|
||||||
// .sum("i_reservation_amount as total_reservation_amount")
|
|
||||||
// .count("* as total_reservation")
|
|
||||||
.select('i_reservation_amount', 'c_reservation_no', 'c_flag')
|
|
||||||
.where('c_card_number', cardNumber)
|
|
||||||
.whereIn('c_status', ['P', 'I'])
|
|
||||||
.whereRaw(
|
|
||||||
`c_reservation_no NOT IN (SELECT c_reservation_no FROM trx.t_d_fraud tdf WHERE tdf.c_status = 'A' AND tdf.c_card_number = '${cardNumber}')`
|
|
||||||
)
|
|
||||||
.whereNotNull('c_flag_code');
|
|
||||||
return result;
|
|
||||||
};
|
|
||||||
|
|
||||||
// GET BI REGULATION STATUS FROM GLOBAL PARAMETER
|
// GET BI REGULATION STATUS FROM GLOBAL PARAMETER
|
||||||
const getBIRegulationStatus = () => {
|
const getBIRegulationStatus = () => {
|
||||||
let result = knex('t_m_global_parameter')
|
let result = knex('t_m_global_parameter')
|
||||||
@@ -279,7 +217,7 @@ const insertLoadingBalance = async (
|
|||||||
balance,
|
balance,
|
||||||
flag
|
flag
|
||||||
) => {
|
) => {
|
||||||
return await knex
|
await knex
|
||||||
.transaction((trx) => {
|
.transaction((trx) => {
|
||||||
knex('trx.t_d_load_balance')
|
knex('trx.t_d_load_balance')
|
||||||
.transacting(trx)
|
.transacting(trx)
|
||||||
@@ -383,7 +321,7 @@ const insertLoadingBalance = async (
|
|||||||
})
|
})
|
||||||
.then((result) => {
|
.then((result) => {
|
||||||
// console.log(result);
|
// console.log(result);
|
||||||
return result.rowCount;
|
return result;
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
console.log(error.message);
|
console.log(error.message);
|
||||||
@@ -601,7 +539,7 @@ const updateReservationAndLoadingBalance = async (
|
|||||||
now,
|
now,
|
||||||
flag
|
flag
|
||||||
) => {
|
) => {
|
||||||
return await knex
|
await knex
|
||||||
.transaction((trx) => {
|
.transaction((trx) => {
|
||||||
knex('trx.t_d_load_balance')
|
knex('trx.t_d_load_balance')
|
||||||
.transacting(trx)
|
.transacting(trx)
|
||||||
@@ -662,7 +600,7 @@ const updateReservationAndLoadingBalance = async (
|
|||||||
})
|
})
|
||||||
.then((result) => {
|
.then((result) => {
|
||||||
// console.log(result);
|
// console.log(result);
|
||||||
return result.rowCount;
|
return result;
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
console.log(error.message);
|
console.log(error.message);
|
||||||
@@ -703,12 +641,11 @@ const getLastLoadingBalanceDetailFlag = (loadBalanceId) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// update
|
// update
|
||||||
const updateStatusReservation = (reservationNumber, now, flag) => {
|
const updateStatusReservation = (reservationNumber, now) => {
|
||||||
let result = knex('trx.t_d_reservation_balance')
|
let result = knex('trx.t_d_reservation_balance')
|
||||||
.update({
|
.update({
|
||||||
c_status: 'I',
|
c_status: 'I',
|
||||||
c_status_name: 'IN PROGRESS',
|
c_status_name: 'IN PROGRESS',
|
||||||
c_flag: flag,
|
|
||||||
d_modify: now,
|
d_modify: now,
|
||||||
i_modify: null,
|
i_modify: null,
|
||||||
c_modify_username: null,
|
c_modify_username: null,
|
||||||
@@ -786,248 +723,16 @@ const insertLoadBalanceNumber = (loadBalanceNumber) => {
|
|||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
// GET RESERVATION PENDING WITHOUT FRAUD
|
// GET TOPUP PARTIAL STATUS FROM GLOBAL PARAMETER
|
||||||
const getReservationPendingWithoutFraud = (
|
const getTopupPartialStatus = () => {
|
||||||
cardNumber,
|
let result = knex('t_m_global_parameter')
|
||||||
flag,
|
.select('c_value')
|
||||||
reservationNumber = []
|
.where('c_code', 'HSM_TOPUP_PARTIAL_STAT')
|
||||||
) => {
|
.where('c_status', 'A')
|
||||||
if (reservationNumber.length > 0) {
|
|
||||||
let rsv = ``;
|
|
||||||
if (reservationNumber.length > 0) {
|
|
||||||
for (let index = 0; index < reservationNumber.length; index++) {
|
|
||||||
if (index > 0) {
|
|
||||||
rsv = rsv + `,`;
|
|
||||||
}
|
|
||||||
|
|
||||||
rsv = `'` + rsv + reservationNumber[index] + `'`;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let result = knex('trx.t_d_reservation_balance')
|
|
||||||
.select(
|
|
||||||
'trx.t_d_reservation_balance.i_reservation_amount',
|
|
||||||
'trx.t_d_reservation_balance.c_reservation_no',
|
|
||||||
'trx.t_d_reservation_balance.c_flag'
|
|
||||||
)
|
|
||||||
.where('trx.t_d_reservation_balance.c_card_number', cardNumber)
|
|
||||||
.whereIn('trx.t_d_reservation_balance.c_status', ['P', 'I'])
|
|
||||||
.whereRaw(
|
|
||||||
`trx.t_d_reservation_balance.c_reservation_no NOT IN (SELECT c_reservation_no FROM trx.t_d_fraud WHERE trx.t_d_fraud.c_status = 'A' AND trx.t_d_fraud.c_reservation_no IN (${rsv}))`
|
|
||||||
)
|
|
||||||
// .where("d_expired", ">=", time)
|
|
||||||
.where(function () {
|
|
||||||
this.orWhere('trx.t_d_reservation_balance.c_flag', flag).orWhere(
|
|
||||||
'trx.t_d_reservation_balance.c_flag',
|
|
||||||
'-1'
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
return result;
|
|
||||||
} else {
|
|
||||||
let result = knex('trx.t_d_reservation_balance')
|
|
||||||
// .sum("i_reservation_amount as total_reservation_amount")
|
|
||||||
// .count("* as total_reservation")
|
|
||||||
.select('i_reservation_amount', 'c_reservation_no', 'c_flag')
|
|
||||||
.where('c_card_number', cardNumber)
|
|
||||||
.whereIn('c_status', ['P', 'I'])
|
|
||||||
// .where("d_expired", ">=", time)
|
|
||||||
.where(function () {
|
|
||||||
this.orWhere('c_flag', flag).orWhere('c_flag', '-1');
|
|
||||||
});
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// GET FRAUD TRANSACTION
|
|
||||||
const getFraudTransaction = (cardNumber) => {
|
|
||||||
let result = knex('trx.t_d_fraud')
|
|
||||||
.where('c_card_number', cardNumber)
|
|
||||||
.where('c_status', '!=', 'X');
|
|
||||||
return result;
|
|
||||||
};
|
|
||||||
|
|
||||||
// GET FRAUD TRANSACTION
|
|
||||||
const getLastHistory = (cardNumber) => {
|
|
||||||
let result = knex('log.t_log_card')
|
|
||||||
.where('c_card_number', cardNumber)
|
|
||||||
.whereIn('i_log_name', [21, 90])
|
|
||||||
.where('c_source', 'CMS')
|
|
||||||
.where('c_status', 'S')
|
|
||||||
.orderBy('d_log', 'desc')
|
|
||||||
.first();
|
.first();
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
// INSERT FRAUD TRANSACTION
|
|
||||||
const insertFraudTransaction = (reservationNumber) => {
|
|
||||||
let rsv = ``;
|
|
||||||
if (reservationNumber.length > 0) {
|
|
||||||
for (let index = 0; index < reservationNumber.length; index++) {
|
|
||||||
if (index > 0) {
|
|
||||||
rsv = rsv + `,`;
|
|
||||||
}
|
|
||||||
|
|
||||||
rsv = `'` + rsv + reservationNumber[index] + `'`;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let result = knex
|
|
||||||
.into(
|
|
||||||
knex.raw('?? (??, ??, ??, ??, ??, ??)', [
|
|
||||||
'trx.t_d_fraud',
|
|
||||||
'c_card_number',
|
|
||||||
'c_reservation_no',
|
|
||||||
'i_reservation_amount',
|
|
||||||
'c_reservation_status',
|
|
||||||
'c_reservation_flag',
|
|
||||||
'c_reservation_ref_no',
|
|
||||||
])
|
|
||||||
)
|
|
||||||
.insert(function () {
|
|
||||||
this.select(
|
|
||||||
'c_card_number',
|
|
||||||
'c_reservation_no',
|
|
||||||
'i_reservation_amount',
|
|
||||||
'c_status',
|
|
||||||
'c_flag',
|
|
||||||
'c_ref_no'
|
|
||||||
)
|
|
||||||
.from('trx.t_d_reservation_balance')
|
|
||||||
.whereIn(
|
|
||||||
'trx.t_d_reservation_balance.c_reservation_no',
|
|
||||||
reservationNumber
|
|
||||||
)
|
|
||||||
.whereRaw(
|
|
||||||
`trx.t_d_reservation_balance.c_reservation_no NOT IN (SELECT c_reservation_no FROM trx.t_d_fraud WHERE trx.t_d_fraud.c_status = 'A' AND trx.t_d_fraud.c_reservation_no IN (${rsv}))`
|
|
||||||
);
|
|
||||||
});
|
|
||||||
return result;
|
|
||||||
};
|
|
||||||
|
|
||||||
// SUSPEND RESERVATION
|
|
||||||
const suspendReservation = (reservationNumber, datetime) => {
|
|
||||||
let result = knex('trx.t_d_reservation_balance')
|
|
||||||
.update({
|
|
||||||
c_status: 'S',
|
|
||||||
c_status_name: 'SUSPEND',
|
|
||||||
d_modify: datetime,
|
|
||||||
})
|
|
||||||
.whereIn('c_reservation_no', reservationNumber);
|
|
||||||
return result;
|
|
||||||
};
|
|
||||||
// CHECK HISTORY CARD
|
|
||||||
const checkCardHistory = (c_card_number) => {
|
|
||||||
let result = knex('log.t_log_card')
|
|
||||||
// .select(['i_log_name', 'c_source'])
|
|
||||||
.where('c_card_number', c_card_number)
|
|
||||||
.where('c_source', 'CMS')
|
|
||||||
.whereIn('i_log_name', ['21', '90'])
|
|
||||||
.orderBy('d_log', 'DESC')
|
|
||||||
.first();
|
|
||||||
|
|
||||||
return result;
|
|
||||||
};
|
|
||||||
|
|
||||||
// INSERT FRAUD
|
|
||||||
const insertFraud = (data) => {
|
|
||||||
let result = knex('trx.t_d_fraud').insert(data, ['c_reservation_no']);
|
|
||||||
|
|
||||||
return result;
|
|
||||||
};
|
|
||||||
|
|
||||||
// UPDATE RESERVE BALANCE
|
|
||||||
const updateFraudToReserve = (reserve_no) => {
|
|
||||||
let result = knex('trx.t_d_reservation_balance')
|
|
||||||
.update({
|
|
||||||
c_status: 'S',
|
|
||||||
c_status_name: 'SUSPEND',
|
|
||||||
})
|
|
||||||
.whereIn('c_reservation_no', reserve_no);
|
|
||||||
|
|
||||||
return result;
|
|
||||||
};
|
|
||||||
|
|
||||||
// CREATE DETAIL LOAD BALANCE FROM RESERVATION
|
|
||||||
const createDetailLoadBalanceFromReservation = (reservationNumber) => {
|
|
||||||
let result = knex('trx.t_d_reservation_balance')
|
|
||||||
.whereIn('c_reservation_no', reservationNumber)
|
|
||||||
.where('c_status', '!=', 'X');
|
|
||||||
|
|
||||||
return result;
|
|
||||||
};
|
|
||||||
|
|
||||||
// UPDATE RESERVATION AND LOADING BALANCE CASE FAILED WRITE BEFORE
|
|
||||||
const updateReservationAndInsertLoadingBalance = async (
|
|
||||||
reservationNumber,
|
|
||||||
dataLoadBalance,
|
|
||||||
detailLoadBalance,
|
|
||||||
now,
|
|
||||||
flag
|
|
||||||
) => {
|
|
||||||
return await knex
|
|
||||||
.transaction((trx) => {
|
|
||||||
knex('trx.t_d_load_balance')
|
|
||||||
.transacting(trx)
|
|
||||||
.insert(dataLoadBalance)
|
|
||||||
.returning('i_load_balance')
|
|
||||||
.then((detail) => {
|
|
||||||
let id = detail[0];
|
|
||||||
let loadDetail = [];
|
|
||||||
detailLoadBalance.forEach((element) => {
|
|
||||||
loadDetail.push({
|
|
||||||
i_load_balance: id,
|
|
||||||
i_reservation_balance: element.i_reservation_balance,
|
|
||||||
c_reservation_no: element.c_reservation_no,
|
|
||||||
i_amount: element.i_reservation_amount,
|
|
||||||
i_issuer: element.i_issuer,
|
|
||||||
i_issuer_code: element.i_issuer_code,
|
|
||||||
i_issuer_name: element.i_issuer_name,
|
|
||||||
i_issuer_fee: element.i_issuer_fee,
|
|
||||||
i_channel: element.i_channel,
|
|
||||||
i_channel_code: element.i_channel_code,
|
|
||||||
i_channel_name: element.i_channel_name,
|
|
||||||
i_channel_fee: element.i_channel_fee,
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
// insert detail load balance
|
|
||||||
return knex('trx.t_d_load_balance_detail')
|
|
||||||
.transacting(trx)
|
|
||||||
.insert(loadDetail);
|
|
||||||
})
|
|
||||||
.then(() => {
|
|
||||||
// update reservation
|
|
||||||
return knex('trx.t_d_reservation_balance')
|
|
||||||
.transacting(trx)
|
|
||||||
.update({
|
|
||||||
d_load_balance: dataLoadBalance.d_load_balance,
|
|
||||||
c_load_balance_no: dataLoadBalance.c_load_balance_no,
|
|
||||||
c_flag: flag,
|
|
||||||
c_flag_code: null,
|
|
||||||
c_status: 'A',
|
|
||||||
c_status_name: 'LOADED',
|
|
||||||
d_modify: now,
|
|
||||||
i_modify: null,
|
|
||||||
c_modify_username: null,
|
|
||||||
c_modify_fullname: null,
|
|
||||||
})
|
|
||||||
.whereIn('c_reservation_no', reservationNumber);
|
|
||||||
})
|
|
||||||
.then(trx.commit)
|
|
||||||
.catch(trx.rollback);
|
|
||||||
})
|
|
||||||
.then((result) => {
|
|
||||||
console.log(result);
|
|
||||||
return result.rowCount;
|
|
||||||
})
|
|
||||||
.catch((error) => {
|
|
||||||
console.log(error.message);
|
|
||||||
return error.message;
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
checkCardNumber,
|
checkCardNumber,
|
||||||
getPartner,
|
getPartner,
|
||||||
@@ -1059,17 +764,5 @@ module.exports = {
|
|||||||
getAccumulationBalanceInThisMonthFromCardHistory,
|
getAccumulationBalanceInThisMonthFromCardHistory,
|
||||||
createLoadBalanceLog,
|
createLoadBalanceLog,
|
||||||
insertLoadBalanceNumber,
|
insertLoadBalanceNumber,
|
||||||
getReservationPendingWithoutFraud,
|
getTopupPartialStatus,
|
||||||
getFraudTransaction,
|
|
||||||
getLastHistory,
|
|
||||||
insertFraudTransaction,
|
|
||||||
suspendReservation,
|
|
||||||
checkCardHistory,
|
|
||||||
insertFraud,
|
|
||||||
updateFraudToReserve,
|
|
||||||
getReservationPendingV2,
|
|
||||||
getReservationPendingWithFlagCounterV2,
|
|
||||||
getReservationPendingWithFlagV2,
|
|
||||||
createDetailLoadBalanceFromReservation,
|
|
||||||
updateReservationAndInsertLoadingBalance,
|
|
||||||
};
|
};
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
+3
-3
@@ -8,7 +8,7 @@ let password;
|
|||||||
|
|
||||||
if (process.env.SERVER_FOR == 'local') {
|
if (process.env.SERVER_FOR == 'local') {
|
||||||
host = 'localhost';
|
host = 'localhost';
|
||||||
database = 'postgres';
|
database = 'CMS_DEV';
|
||||||
port = 5432;
|
port = 5432;
|
||||||
user = 'postgres';
|
user = 'postgres';
|
||||||
password = 'postgres';
|
password = 'postgres';
|
||||||
@@ -16,8 +16,8 @@ if (process.env.SERVER_FOR == 'local') {
|
|||||||
host = '10.20.14.14';
|
host = '10.20.14.14';
|
||||||
database = 'postgres';
|
database = 'postgres';
|
||||||
port = 5432;
|
port = 5432;
|
||||||
user = 'postgres';
|
user = 'cms';
|
||||||
password = 'inhc0mmute_cms';
|
password = 'Cm5kc1#2021';
|
||||||
} else if (process.env.SERVER_FOR == 'production') {
|
} else if (process.env.SERVER_FOR == 'production') {
|
||||||
host = '10.1.201.75';
|
host = '10.1.201.75';
|
||||||
database = 'postgres';
|
database = 'postgres';
|
||||||
|
|||||||
Reference in New Issue
Block a user