69 lines
1.6 KiB
PHP
69 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Console\Commands\Dealer;
|
|
|
|
use App\Admin\Services\DealerEarningService;
|
|
use App\Models\DealerEarning;
|
|
use Illuminate\Console\Command;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Throwable;
|
|
|
|
class ChannelSubsidySettleCommand extends Command
|
|
{
|
|
/**
|
|
* The name and signature of the console command.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $signature = 'dealer:channel-subsidy-settle';
|
|
|
|
/**
|
|
* The console command description.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $description = '结算签约经销商的渠道补贴';
|
|
|
|
/**
|
|
* Execute the console command.
|
|
*
|
|
* @return int
|
|
*/
|
|
public function handle()
|
|
{
|
|
while (true) {
|
|
$page = 0;
|
|
|
|
DealerEarning::channelSubsidy()->withoutPayer()->onlyPending()->chunkById(200, function ($earnings) use (&$page) {
|
|
$earnings->load(['earningable', 'user']);
|
|
|
|
foreach ($earnings as $earning) {
|
|
try {
|
|
DB::beginTransaction();
|
|
|
|
$earning->update([
|
|
'settle_at' => now(),
|
|
]);
|
|
|
|
(new DealerEarningService())->pay($earning);
|
|
|
|
DB::commit();
|
|
} catch (Throwable $e) {
|
|
DB::rollBack();
|
|
|
|
report($e);
|
|
}
|
|
}
|
|
|
|
$page++;
|
|
});
|
|
|
|
if ($page === 0) {
|
|
sleep(60);
|
|
} else {
|
|
sleep(30);
|
|
}
|
|
}
|
|
}
|
|
}
|