payments: bulk op to reset a failed currency payout

Generally happen if the wallet balance is too low,
but in some cases could be also a rpc timeout (CHC),
so it require to be manually checked by the admin in the wallet tx history.
This commit is contained in:
Tanguy Pruvot 2017-11-22 10:03:31 +01:00
parent 87c7b8c481
commit 2b98f0219e
2 changed files with 37 additions and 2 deletions

View file

@ -657,6 +657,36 @@ class SiteController extends CommonController
$this->goback();
}
public function actionCancelUsersPayment()
{
if(!$this->admin) return;
$coin = getdbo('db_coins', getiparam('id'));
if ($coin) {
$amount_failed = 0.0; $cnt = 0;
$time = time() - (48 * 3600);
$failed = getdbolist('db_payouts', "idcoin=:id AND IFNULL(tx,'') = '' AND time>$time", array(':id'=>$coin->id));
if (!empty($failed)) {
foreach ($failed as $payout) {
$user = getdbo('db_accounts', $payout->account_id);
if ($user) {
$user->balance += floatval($payout->amount);
if ($user->save()) {
$amount_failed += floatval($payout->amount);
$cnt++;
}
}
$payout->delete();
}
user()->setFlash('message', "Restored $cnt failed txs to user balances, $amount_failed {$coin->symbol}");
} else {
user()->setFlash('message', 'No failed txs found');
}
} else {
user()->setFlash('error', 'Invalid coin id!');
}
$this->goback();
}
/////////////////////////////////////////////////
public function actionUser()
@ -1070,6 +1100,9 @@ class SiteController extends CommonController
public function actionGomining()
{
$algo = substr(getparam('algo'), 0, 32);
if ($algo == 'all') {
return;
}
user()->setState('yaamp-algo', $algo);
$this->redirect("/site/mining");
}

View file

@ -70,7 +70,7 @@ if (!empty($data)) foreach ($data as $row) {
$failed[$uid] = $row['failed'];
}
$list = getdbolist('db_accounts', "coinid!=6 $sqlFilter AND (".
$list = getdbolist('db_accounts', "is_locked != 1 $sqlFilter AND (".
"balance > 0 OR last_earning > (UNIX_TIMESTAMP()-60*60) OR id IN (SELECT DISTINCT account_id FROM payouts WHERE tx IS NULL)".
") ORDER BY last_earning DESC $limit");
@ -135,8 +135,10 @@ if ($coin_id) {
echo '<table class="totals">';
echo '<tr><th>Balances</th><td>'.bitcoinvaluetoa($total)." $symbol</td></tr>";
echo '<tr><th>Immature</th><td>'.bitcoinvaluetoa($totalimmat)." $symbol</td></tr>";
if ($totalfailed)
if ($totalfailed) {
echo '<tr class="red"><th>Failed</th><td>'.bitcoinvaluetoa($totalfailed)." $symbol</td></tr>";
echo '<tr><td colspan="2">'.'<a href="/site/cancelUsersPayment?id='.$coin_id.'" title="Add to balance all failed payouts">Reset all failed</a></td></tr>';
}
echo '</tr></table>';
echo '</div>';
}