<?php
namespace App\Console\Commands;use App\Models\LedgerEntry;use App\Models\Merchant;use Illuminate\Console\Command;
class RefreshMerchantBalances extends Command {protected $signature='merchants:refresh-balances';protected $description='Refresh non-authoritative merchant balance cache';public function handle():int{Merchant::chunkById(100,function($ms){foreach($ms as $m){$last=LedgerEntry::where('merchant_id',$m->id)->where('currency',$m->currency_code)->latest('id')->value('balance_after_minor')??0;$m->forceFill(['float_balance_minor'=>$last])->save();}});return self::SUCCESS;}}
