Guest User

Untitled

a guest
Feb 19th, 2019
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. 'use strict'
  2.  
  3. const mariadb = require('mariadb');
  4.  
  5. const pool = mariadb.createPool({
  6. host: 'localhost',
  7. user: 'root',
  8. password: 'yourpassword',
  9. database: 'lotto',
  10. connectionLimit: 5
  11. });
  12.  
  13. async function check(req, callback) {
  14. let conn;
  15. try {
  16. conn = await pool.getConnection();
  17. const rows = await conn.query("SELECT A.*,B.LOTTO_NAME FROM LOTTO.LOTTO_DB A " +
  18. "INNER JOIN LOTTO.LOTTO_NAME B ON A.LOTTO_TYPE=B.LOTTO_TYPE " +
  19. "WHERE ID='" + req.lotto.lottoType + "' " +
  20. "AND (A.LOTTO_TYPE<>3 AND A.LOTTO_TYPE<>4 AND A.LOTTO_TYPE<>5 AND NUMBER='" + req.lotto.lottoBarcode + "'" +
  21. " OR (A.LOTTO_TYPE=3 AND NUMBER='" + req.lotto.lottoBarcode.substring(0, 3) + "') " +
  22. " OR (A.LOTTO_TYPE=4 AND NUMBER='" + req.lotto.lottoBarcode.substring(3, 6) + "') " +
  23. " OR (A.LOTTO_TYPE=5 AND NUMBER='" + req.lotto.lottoBarcode.substring(4, 6) + "') " +
  24. ")");
  25.  
  26. let result = "";
  27. let message = "";
  28.  
  29. if (rows.length <= 0) {
  30. result = "0";
  31. message = "ไม่ถูกรางวัลใดๆ";
  32. } else {
  33. result = rows[0].LOTTO_TYPE;
  34. message = rows[0].LOTTO_NAME;
  35. }
  36.  
  37. let jsonout = {
  38. rewardType: result,
  39. message: message
  40. };
  41.  
  42. callback(jsonout);
  43. } catch (err) {
  44. throw err;
  45. } finally {
  46. if (conn) return conn.end();
  47. }
  48. }
  49.  
  50. module.exports = {
  51. check
  52. };
Add Comment
Please, Sign In to add comment