6
0
Fork 0
jiqu-library-server/app/Actions/Dealer/CalculateManageSubsidiesOfC...

31 lines
797 B
PHP

<?php
namespace App\Actions\Dealer;
use App\Models\Dealer;
use App\Models\DealerManageSubsidyLog;
class CalculateManageSubsidiesOfCurrentPeriod
{
/**
* @param \App\Models\Dealer $dealer
* @return string
*/
public function handle(Dealer $dealer): string
{
$tz = now();
if ($tz->day >= 20) {
$startAt = $tz->copy()->setDay(20)->startOfDay();
} elseif ($tz->day >= 5) {
$startAt = $tz->copy()->setDay(5)->startOfDay();
} else {
$startAt = $tz->copy()->subMonthNoOverflow()->setDay(20)->startOfDay();
}
$total = DealerManageSubsidyLog::where('order_completed_at', '>=', $startAt)->where('user_id', $dealer->user_id)->sum('total_amount');
return bcmul($total, '1', 2);
}
}