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.
|
|
|
|
*
|
2022-12-11 11:47:30 +00:00
|
|
|
* @return int
|
2022-09-16 11:56:58 +00:00
|
|
|
*/
|
2023-01-10 13:42:27 +00:00
|
|
|
public function handle(): int
|
2022-09-16 11:56:58 +00:00
|
|
|
{
|
|
|
|
$this->warn('开始计算集成模块收益。');
|
2023-01-30 16:14:07 +00:00
|
|
|
$this->warn('当前时间: '.now());
|
2022-09-16 11:56:58 +00:00
|
|
|
|
2023-01-10 13:42:27 +00:00
|
|
|
(new Module)->chunk(100, function ($modules) {
|
2022-09-16 12:03:54 +00:00
|
|
|
foreach ($modules as $module) {
|
2023-01-30 16:14:07 +00:00
|
|
|
$this->warn('模块: '.$module->name);
|
2022-11-19 04:37:18 +00:00
|
|
|
$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);
|
2023-01-10 13:42:27 +00:00
|
|
|
$this->info("$module->name {$year}年 {$month}月 实收: {$total}元 应得: $total_should 元");
|
2022-11-19 04:37:18 +00:00
|
|
|
}
|
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('计算模块收益完成。');
|
2023-01-30 16:14:07 +00:00
|
|
|
$this->warn('完成时间: '.now());
|
2022-11-16 02:29:50 +00:00
|
|
|
|
|
|
|
return 1;
|
2022-09-16 11:56:58 +00:00
|
|
|
}
|
|
|
|
}
|