Advertisement
Guest User

Untitled

a guest
Sep 21st, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.17 KB | None | 0 0
  1. 1 * * * * /usr/bin/node /var/www/html/uniphiData/js/recalculate_points.js
  2.  
  3. var connection = mysql.createConnection({
  4. host: 'HOST',
  5. user: 'USER',
  6. password: 'PASS!',
  7. database: 'DATABASE'
  8. });
  9.  
  10. connection.connect();
  11.  
  12. connection.query('SELECT * FROM users', function (err, rows, fields) {
  13. if (err) throw err;
  14.  
  15. rows.forEach(function (row, index) {
  16. connection.query('SELECT count(*) AS friends FROM users WHERE invitedByFriend = ' + row.ID, function (err2, friends, fields2) {
  17. if (err2) throw err2;
  18.  
  19. var realCountFriends = friends[0].friends;
  20. friends = friends[0].friends * 50;
  21.  
  22. var id = '%;' + row.ID + ';%';
  23.  
  24. connection.query('SELECT SUM(pointsPerShare) AS shareEvent FROM events WHERE shared LIKE "' + id + '"', function (err3, pointsPerSharing, fields3) {
  25. if (err3) throw err3;
  26.  
  27. if (pointsPerSharing[0].shareEvent == null)
  28. pointsPerSharing = 0;
  29. else
  30. pointsPerSharing = pointsPerSharing[0].shareEvent;
  31.  
  32. connection.query('SELECT SUM(e.pointsEntry) AS entry FROM orders o, events e WHERE o.used = 1 AND o.userID = ' + row.ID + ' AND o.eventID = e.ID', function (err4, pointsEntry, fields4) {
  33.  
  34. if (err4) throw err4;
  35.  
  36. if (pointsEntry[0].entry == null)
  37. pointsEntry = 0;
  38. else
  39. pointsEntry = pointsEntry[0].entry;
  40.  
  41.  
  42. connection.query('SELECT SUM(e.pointsPrepay) AS purchase FROM orders o, events e WHERE o.guestList = 0 AND o.cheapList = 0 AND o.userID = ' + row.ID + ' AND o.eventID = e.ID', function (err5, pointsPrepay, fields5) {
  43. if (err5) throw err5;
  44.  
  45. if (pointsPrepay[0].purchase == null)
  46. pointsPrepay = 0;
  47. else
  48. pointsPrepay = pointsPrepay[0].purchase;
  49.  
  50. var shareApp = row.quantitySharedApp * 20;
  51. var newUser = 50;
  52.  
  53. var realCount = friends + pointsPerSharing + pointsEntry + pointsPrepay + shareApp + newUser;
  54. var difference = realCount - row.totalPoints;
  55.  
  56. if (difference != 0) {
  57. connection.query('UPDATE users SET points = points + ' + difference + ', totalPoints = ' + realCount + ', monthPoints = monthPoints + ' + difference + ', friendsInvited = ' + realCountFriends + ' WHERE ID = ' + row.ID, function (err6, changePoints, fields6) {
  58.  
  59. if (index == rows.length - 1) {
  60. connection.end();
  61. }
  62. })
  63. } else {
  64.  
  65. if (index == rows.length - 1) {
  66. connection.end();
  67. }
  68. }
  69.  
  70. })
  71.  
  72. })
  73.  
  74.  
  75. })
  76.  
  77.  
  78. })
  79. })
  80.  
  81. });
  82.  
  83. Nov 17 14:55:01 name CRON[4677]: (root) CMD (/usr/local/rtm/bin/rtm 14 > /dev/null 2> /dev/null)
  84.  
  85. 1 * * * * /path/to/file.sh
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement