[IMPROVED] data gathering for Auto Payout

* Using improved SQL query created by @feeleep75
* Adjusted the query to further cut down the data returned

Fixes #1159 once merged.
This commit is contained in:
Sebastian Grewe 2013-12-30 11:57:29 +01:00
parent 96d096f669
commit de302a03dc
2 changed files with 39 additions and 4 deletions

View File

@ -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

View File

@ -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();