Lae/app/Console/Commands/CalcModule.php

72 lines
1.7 KiB
PHP
Raw Normal View History

2022-09-16 11:56:58 +00:00
<?php
namespace App\Console\Commands;
2022-11-06 11:28:22 +00:00
use App\Models\Module;
2022-09-16 11:56:58 +00:00
use Illuminate\Console\Command;
class CalcModule extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'modules:calc';
/**
* The console command description.
*
* @var string
*/
2022-11-21 03:58:30 +00:00
protected $description = '获取模块的最近收益。';
2022-09-16 11:56:58 +00:00
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$this->warn('开始计算集成模块收益。');
2022-09-16 12:03:54 +00:00
$this->warn('当前时间: ' . now());
2022-09-16 11:56:58 +00:00
2022-11-19 04:37:18 +00:00
Module::chunk(100, function ($modules) {
2022-09-16 12:03:54 +00:00
foreach ($modules as $module) {
2022-11-19 04:37:18 +00:00
$this->warn('模块: ' . $module->name);
$years = $module->calculate();
2022-09-16 11:56:58 +00:00
2022-11-19 04:37:18 +00:00
foreach ($years as $year => $months) {
// 排序 months 从小到大
ksort($months);
2022-09-16 11:56:58 +00:00
2022-11-19 04:37:18 +00:00
$total = 0;
$total_should = 0;
2022-09-16 12:03:54 +00:00
2022-11-19 04:37:18 +00:00
foreach ($months as $month => $m) {
2022-11-19 05:14:51 +00:00
$total += round($m['balance'], 2);
$total_should += round($m['should_balance'], 2);
2022-11-19 04:37:18 +00:00
$this->info("{$module->name} {$year}{$month}月 实收: {$total}元 应得: {$total_should}");
}
2022-09-16 12:03:54 +00:00
}
}
});
2022-09-16 11:56:58 +00:00
2022-09-16 12:03:54 +00:00
$this->warn('计算模块收益完成。');
$this->warn('完成时间: ' . now());
2022-11-16 02:29:50 +00:00
return 1;
2022-09-16 11:56:58 +00:00
}
}