diff --git a/cronjobs/payouts.php b/cronjobs/payouts.php index 10ba66c3..0c4ac0d3 100755 --- a/cronjobs/payouts.php +++ b/cronjobs/payouts.php @@ -102,8 +102,8 @@ if ($setting->getValue('disable_manual_payouts') != 1) { } if ($setting->getValue('disable_auto_payouts') != 1) { - // Fetch all users with setup AP - $users = $user->getAllAutoPayout(); + // Fetch all users balances + $users = $transaction->getAPQueue(); if (count($users) > 0) $log->logDebug(" found " . count($users) . " queued payout(s)"); // Go through users and run transactions @@ -111,8 +111,7 @@ if ($setting->getValue('disable_auto_payouts') != 1) { $log->logInfo("\tUserID\tUsername\tBalance\tThreshold\tAddress"); foreach ($users as $aUserData) { - $aBalance = $transaction->getBalance($aUserData['id']); - $dBalance = $aBalance['confirmed']; + $dBalance = $aUserData['confirmed']; $log->logInfo("\t" . $aUserData['id'] . "\t" . $aUserData['username'] . "\t" . $dBalance . "\t" . $aUserData['ap_threshold'] . "\t\t" . $aUserData['coin_address']); // Only run if balance meets threshold and can pay the potential transaction fee diff --git a/public/include/classes/transaction.class.php b/public/include/classes/transaction.class.php index 01c4d826..565497b1 100644 --- a/public/include/classes/transaction.class.php +++ b/public/include/classes/transaction.class.php @@ -272,6 +272,42 @@ class Transaction extends Base { return $result->fetch_assoc(); return $this->sqlError(); } + + /** + * Get our Auto Payout queue + * @param none + * @return data array Account settings and confirmed balances + **/ + public function getAPQueue() { + $this->debug->append("STA " . __METHOD__, 4); + $stmt = $this->mysqli->prepare(" + SELECT + a.id, + a.username, + a.ap_threshold, + a.coin_address, + IFNULL( + ROUND( + ( + SUM( IF( ( t.type IN ('Credit','Bonus') AND b.confirmations >= 120 ) OR t.type = 'Credit_PPS', t.amount, 0 ) ) - + SUM( IF( t.type IN ('Debit_MP', 'Debit_AP'), t.amount, 0 ) ) - + SUM( IF( ( t.type IN ('Donation','Fee') AND b.confirmations >= 120 ) OR ( t.type IN ('Donation_PPS', 'Fee_PPS', 'TXFee') ), t.amount, 0 ) ) + ), 8 + ), 0 + ) AS confirmed + FROM transactions AS t + LEFT JOIN blocks AS b + ON t.block_id = b.id + LEFT JOIN accounts AS a + ON t.account_id = a.id + WHERE t.archived = 0 AND a.ap_threshold > 0 + HAVING confirmed > a.ap_threshold + "); + if ($this->checkStmt($stmt) && $stmt->execute() && $result = $stmt->get_result()) + return $result->fetch_all(MYSQLI_ASSOC); + echo $this->mysqli->error; + return $this->sqlError(); + } } $transaction = new Transaction();