2
私はチッピングゲームを作成しました。ユーザーは値を推測でき、12時間後に現在のUSD/EURレートがAPIリクエストによって取得され、 (1人の勝者は、n人のユーザーが同じ金額を払って、すべてが勝つ)。(laravel eloquent)最も近い値を取得する(チッピングゲーム)
データベースから「最も近い」ヒントを取得するにはどうすればよいですか?
foreach ($rounds_closed as $round_closed)
{
//get latest rate
$amount = 458.12;
//set transaction as processed and set latest rate
$round_closed->update([
'status' => 2,
'win_tip' => $amount,
]);
//get lucky winners
//here I would need eloquent code to choose the "nearest" winners
$winners_transactions = Transaction::where('round_id', $round_closed->id)->where('assessment', $round_closed->win_tip)->get();
//if we have at least one winner
if ($winners_transactions->count() > 0)
{
//calculate their win amount
$sum = $round_closed->transactions->sum('amount');
$fee = $sum * 0.10;
$sum = $sum - $fee;
$sum = number_format($sum/$winners_transactions->count(), 8, '.', '');
foreach ($winners_transactions as $winner_transaction)
{
//mark transaction as payed out
$winner_transaction->update([
'payout' => 1,
]);
//payout user
}
}
}