mirror of
https://github.com/mohamadihsan/topuponline.git
synced 2026-12-06 11:16:28 +00:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| db57e1682a |
File diff suppressed because it is too large
Load Diff
@@ -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