Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 1 * * * * /usr/bin/node /var/www/html/uniphiData/js/recalculate_points.js
- var connection = mysql.createConnection({
- host: 'HOST',
- user: 'USER',
- password: 'PASS!',
- database: 'DATABASE'
- });
- connection.connect();
- connection.query('SELECT * FROM users', function (err, rows, fields) {
- if (err) throw err;
- rows.forEach(function (row, index) {
- connection.query('SELECT count(*) AS friends FROM users WHERE invitedByFriend = ' + row.ID, function (err2, friends, fields2) {
- if (err2) throw err2;
- var realCountFriends = friends[0].friends;
- friends = friends[0].friends * 50;
- var id = '%;' + row.ID + ';%';
- connection.query('SELECT SUM(pointsPerShare) AS shareEvent FROM events WHERE shared LIKE "' + id + '"', function (err3, pointsPerSharing, fields3) {
- if (err3) throw err3;
- if (pointsPerSharing[0].shareEvent == null)
- pointsPerSharing = 0;
- else
- pointsPerSharing = pointsPerSharing[0].shareEvent;
- 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) {
- if (err4) throw err4;
- if (pointsEntry[0].entry == null)
- pointsEntry = 0;
- else
- pointsEntry = pointsEntry[0].entry;
- 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) {
- if (err5) throw err5;
- if (pointsPrepay[0].purchase == null)
- pointsPrepay = 0;
- else
- pointsPrepay = pointsPrepay[0].purchase;
- var shareApp = row.quantitySharedApp * 20;
- var newUser = 50;
- var realCount = friends + pointsPerSharing + pointsEntry + pointsPrepay + shareApp + newUser;
- var difference = realCount - row.totalPoints;
- if (difference != 0) {
- connection.query('UPDATE users SET points = points + ' + difference + ', totalPoints = ' + realCount + ', monthPoints = monthPoints + ' + difference + ', friendsInvited = ' + realCountFriends + ' WHERE ID = ' + row.ID, function (err6, changePoints, fields6) {
- if (index == rows.length - 1) {
- connection.end();
- }
- })
- } else {
- if (index == rows.length - 1) {
- connection.end();
- }
- }
- })
- })
- })
- })
- })
- });
- Nov 17 14:55:01 name CRON[4677]: (root) CMD (/usr/local/rtm/bin/rtm 14 > /dev/null 2> /dev/null)
- 1 * * * * /path/to/file.sh
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement