Initial commit

This commit is contained in:
meusinfirmary
2025-04-22 14:31:37 +07:00
commit b7e852126c
115 changed files with 23188 additions and 0 deletions

View File

@ -0,0 +1,129 @@
const db = require(`../config/dbMysqlConn`);
const MysqlHelpers = require(`../library/LibMysqlHelper`);
class OrdersLogsTfModels {
static TYPE_TF_CHECKPOINT = 1;
static STTS_UNPAID = 0;
static STTS_PAID = 1;
static STTS_FAIL = 2;
static STTS_PENDING = 3;
static METHOD_MANUAL = 1;
static METHOD_DANA = 2;
static list(filter = {}) {
return new Promise(async (resolve, reject) => {
let params = [], select = '', where = '', join = '', order_by = '', group_by = '', limit = '';
if (filter['log_tf_id']) {
where += ' AND log_tf.id = ?';
params.push(filter['log_tf_id']);
}
if (filter['ord_id']) {
where += ' AND log_tf.ord_id = ?';
params.push(filter['ord_id']);
}
if (filter['ord_code']) {
where += ' AND log_tf.ord_code = ?';
params.push(filter['ord_code']);
}
if (filter['checkpoint_id']) {
where += ' AND log_tf.checkpoint_id = ?';
params.push(filter['checkpoint_id']);
}
if (filter['type']) {
where += ' AND log_tf.type = ?';
params.push(filter['type']);
}
if (filter['method']) {
where += ' AND log_tf.method = ?';
params.push(filter['method']);
}
if (filter['group_by']) {
group_by = filter['group_by'];
}
if (filter['limit']) {
limit = ' LIMIT ' + filter['limit'];
}
let query = `SELECT
log_tf.*
${select}
FROM t_orders_logs_tf as log_tf
${join}
WHERE log_tf.dlt is null
${where}
${group_by}
${order_by}
${limit}
;`;
try {
const conn = await MysqlHelpers.createConnection();
const result = await MysqlHelpers.query(conn, query, params);
await MysqlHelpers.releaseConnection(conn);
resolve(result);
} catch (e) {
reject(e);
}
// db.query(query, params, function (err, resp) {
// if (err) {
// reject(err);
// return false;
// }
// resolve(resp);
// return true;
// });
});
}
static bundleIns (insOrdLogsTf = {}) {
return new Promise(async (resolve, reject) => {
try {
const conn = await MysqlHelpers.createConnection();
await MysqlHelpers.createTrx(conn);
let result = undefined;
if (Object.keys(insOrdLogsTf).length > 0) result = await MysqlHelpers.queryTrx(conn, `INSERT INTO t_orders_logs_tf SET ?;`, [insOrdLogsTf]);
await MysqlHelpers.commit(conn);
resolve({
type: 'success',
result,
})
} catch (err) {
reject(err);
}
})
}
static bundleUpdt (updtOrdLogsTf = {}) {
return new Promise(async (resolve, reject) => {
try {
const conn = await MysqlHelpers.createConnection();
await MysqlHelpers.createTrx(conn);
let result = undefined;
if (Object.keys(updtOrdLogsTf).length > 0) result = await MysqlHelpers.queryTrx(conn, `UPDATE t_orders_logs_tf SET ? WHERE id = ?;`, [updtOrdLogsTf, updtOrdLogsTf.id]);
await MysqlHelpers.commit(conn);
resolve({
type: 'success',
result,
})
} catch (err) {
reject(err);
}
})
}
}
module.exports = OrdersLogsTfModels;