mirror of
https://github.com/mohamadihsan/topuponline.git
synced 2026-12-06 08:56:28 +00:00
Compare commits
79 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 4495f910b0 | |||
| f7c5cf33f6 | |||
| 870d8aea46 | |||
| b46d3a5b25 | |||
| 5408639d80 | |||
| 9b2ab48e99 | |||
| a35492c124 | |||
| e1f0c60b37 | |||
| 16afd42876 | |||
| 3722be6eeb | |||
| 493f131779 | |||
| f10ff80284 | |||
| f30ee86552 | |||
| e8de33b663 | |||
| 68ebfb0ac2 | |||
| 96c46ad49c | |||
| 10e38babcd | |||
| 8bc68493cf | |||
| 2b1b14548a | |||
| 240bb5fa17 | |||
| 7676ec54ef | |||
| de0a8847b5 | |||
| 4df41a426c | |||
| 3401e425b4 | |||
| 0d29175942 | |||
| 4f03433bb2 | |||
| 1df5f97543 | |||
| a222714bcb | |||
| 2249bbbbaf | |||
| 16fbfdcae1 | |||
| 6b5f92e597 | |||
| baf99a975d | |||
| 70b9ef78cb | |||
| 4169b40e97 | |||
| 3566f63bea | |||
| 066fd49173 | |||
| 2c0ffbd9d6 | |||
| ee46232c7a | |||
| 15131cebb1 | |||
| 6ff785de5a | |||
| 8e997346d2 | |||
| 80dda817fb | |||
| 410ef5ac53 | |||
| d9d5be8921 | |||
| 574092e015 | |||
| 5ece7912f4 | |||
| 2540b1c6c0 | |||
| 4feb7a7724 | |||
| 4994278078 | |||
| c6488f7f69 | |||
| f0bbf54afc | |||
| 7c6ab450be | |||
| 1524d643c6 | |||
| 36b61697dd | |||
| 8366d9b38b | |||
| ed7e0ce127 | |||
| 8d1e2075c3 | |||
| 5df52be111 | |||
| 6e0627fb86 | |||
| 0235cdb7c0 | |||
| a64c38b928 | |||
| 99f004adf2 | |||
| 3e5d73dd56 | |||
| 4481079289 | |||
| 9bc1260bc0 | |||
| df8ad92eba | |||
| 3b8d9d20ff | |||
| 5197966807 | |||
| 966c7b1f60 | |||
| 002f1375e4 | |||
| ada8358c07 | |||
| b587640684 | |||
| 7d56ebbe77 | |||
| 015832c683 | |||
| 79a5c5951b | |||
| c54a030519 | |||
| 775b36cfd2 | |||
| b796bfdd5c | |||
| 25f66afa7b |
File diff suppressed because it is too large
Load Diff
@@ -72,8 +72,33 @@ const getReservationPending = (cardNumber, time, flag) => {
|
||||
// .where("d_expired", ">=", time)
|
||||
.where(function () {
|
||||
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;
|
||||
};
|
||||
|
||||
@@ -96,6 +121,28 @@ const getReservationPendingWithFlagCounter = (cardNumber, time, flag) => {
|
||||
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
|
||||
const getReservationPendingWithFlag = (cardNumber, time) => {
|
||||
let result = knex('trx.t_d_reservation_balance')
|
||||
@@ -108,6 +155,21 @@ const getReservationPendingWithFlag = (cardNumber, time) => {
|
||||
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
|
||||
const getBIRegulationStatus = () => {
|
||||
let result = knex('t_m_global_parameter')
|
||||
@@ -217,7 +279,7 @@ const insertLoadingBalance = async (
|
||||
balance,
|
||||
flag
|
||||
) => {
|
||||
await knex
|
||||
return await knex
|
||||
.transaction((trx) => {
|
||||
knex('trx.t_d_load_balance')
|
||||
.transacting(trx)
|
||||
@@ -321,7 +383,7 @@ const insertLoadingBalance = async (
|
||||
})
|
||||
.then((result) => {
|
||||
// console.log(result);
|
||||
return result;
|
||||
return result.rowCount;
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log(error.message);
|
||||
@@ -539,7 +601,7 @@ const updateReservationAndLoadingBalance = async (
|
||||
now,
|
||||
flag
|
||||
) => {
|
||||
await knex
|
||||
return await knex
|
||||
.transaction((trx) => {
|
||||
knex('trx.t_d_load_balance')
|
||||
.transacting(trx)
|
||||
@@ -600,7 +662,7 @@ const updateReservationAndLoadingBalance = async (
|
||||
})
|
||||
.then((result) => {
|
||||
// console.log(result);
|
||||
return result;
|
||||
return result.rowCount;
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log(error.message);
|
||||
@@ -641,11 +703,12 @@ const getLastLoadingBalanceDetailFlag = (loadBalanceId) => {
|
||||
};
|
||||
|
||||
// update
|
||||
const updateStatusReservation = (reservationNumber, now) => {
|
||||
const updateStatusReservation = (reservationNumber, now, flag) => {
|
||||
let result = knex('trx.t_d_reservation_balance')
|
||||
.update({
|
||||
c_status: 'I',
|
||||
c_status_name: 'IN PROGRESS',
|
||||
c_flag: flag,
|
||||
d_modify: now,
|
||||
i_modify: null,
|
||||
c_modify_username: null,
|
||||
@@ -723,16 +786,248 @@ const insertLoadBalanceNumber = (loadBalanceNumber) => {
|
||||
return result;
|
||||
};
|
||||
|
||||
// GET TOPUP PARTIAL STATUS FROM GLOBAL PARAMETER
|
||||
const getTopupPartialStatus = () => {
|
||||
let result = knex('t_m_global_parameter')
|
||||
.select('c_value')
|
||||
.where('c_code', 'HSM_TOPUP_PARTIAL_STAT')
|
||||
.where('c_status', 'A')
|
||||
// GET RESERVATION PENDING WITHOUT FRAUD
|
||||
const getReservationPendingWithoutFraud = (
|
||||
cardNumber,
|
||||
flag,
|
||||
reservationNumber = []
|
||||
) => {
|
||||
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();
|
||||
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 = {
|
||||
checkCardNumber,
|
||||
getPartner,
|
||||
@@ -764,5 +1059,17 @@ module.exports = {
|
||||
getAccumulationBalanceInThisMonthFromCardHistory,
|
||||
createLoadBalanceLog,
|
||||
insertLoadBalanceNumber,
|
||||
getTopupPartialStatus,
|
||||
getReservationPendingWithoutFraud,
|
||||
getFraudTransaction,
|
||||
getLastHistory,
|
||||
insertFraudTransaction,
|
||||
suspendReservation,
|
||||
checkCardHistory,
|
||||
insertFraud,
|
||||
updateFraudToReserve,
|
||||
getReservationPendingV2,
|
||||
getReservationPendingWithFlagCounterV2,
|
||||
getReservationPendingWithFlagV2,
|
||||
createDetailLoadBalanceFromReservation,
|
||||
updateReservationAndInsertLoadingBalance,
|
||||
};
|
||||
|
||||
+3
-3
@@ -8,7 +8,7 @@ let password;
|
||||
|
||||
if (process.env.SERVER_FOR == 'local') {
|
||||
host = 'localhost';
|
||||
database = 'CMS_DEV';
|
||||
database = 'postgres';
|
||||
port = 5432;
|
||||
user = 'postgres';
|
||||
password = 'postgres';
|
||||
@@ -16,8 +16,8 @@ if (process.env.SERVER_FOR == 'local') {
|
||||
host = '10.20.14.14';
|
||||
database = 'postgres';
|
||||
port = 5432;
|
||||
user = 'cms';
|
||||
password = 'Cm5kc1#2021';
|
||||
user = 'postgres';
|
||||
password = 'inhc0mmute_cms';
|
||||
} else if (process.env.SERVER_FOR == 'production') {
|
||||
host = '10.1.201.75';
|
||||
database = 'postgres';
|
||||
|
||||
Reference in New Issue
Block a user