Files
exchange-2.0/app/Console/Commands/UpdateGroupWithTransferFee.php
T
2023-12-20 17:41:10 +08:00

75 lines
2.3 KiB
PHP

<?php
namespace App\Console\Commands;
use App\Models\SeasonalSegment;
use Illuminate\Console\Command;
use Carbon\Carbon;
use App\Classes\Modules\Companies\Services\RemovesCompanyFromSegment;
use App\Classes\ValueObjects\Constants\ApprovalStatus;
use App\Classes\ValueObjects\Constants\TransactionType;
use App\Models\Group;
use App\Models\Transaction;
use App\Models\Wallet;
use Illuminate\Support\Facades\Log;
class UpdateGroupWithTransferFee extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'updateGroupWithTransferFee';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Update group with transfer fee';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
ini_set('max_execution_time', 0);
set_time_limit(0);
$groups = Group::whereDate('updated_at', '<', Carbon::now())->get();
Log::info($groups->count());
// $groups = Group::where('id', 999)->get();
foreach ($groups as $group) {
$originalTransferFees = (float)Transaction::where('type', TransactionType::TRANSFER_FEE)->whereIn('owner_id', $group->transactions->pluck('id'))->sum('service_charge');
$correctOriginalAmount = $group->transactions()->sum('original_amount');
$correctOriginalAmount += $originalTransferFees;
$correctAmount = $group->transactions()->sum('amount');
$transferFees = $originalTransferFees / $group->currency_rate;
$correctAmount += $transferFees;
if ($group->original_amount != $correctOriginalAmount) {
// $group->original_amount = $correctOriginalAmount;
// $group->amount = $correctAmount;
// $group->save();
Log::info("Update group id: " . $group->id . " correct original amount is: " . $correctOriginalAmount . " transfer fee is " . $originalTransferFees);
} else {
Log::info("No update for group id: " . $group->id);
}
}
}
}