| 123456789101112131415161718192021222324252627282930 |
- <?php
- namespace App\Console\Commands;
- use App\Services\MemberDailyReportService;
- use Carbon\Carbon;
- use Illuminate\Console\Command;
- class MemberDailyReport extends Command
- {
- protected $signature = 'report:member-daily {date? : Y-m-d,默认今天} {--days=1 : 从 date 往前共重算几天}';
- protected $description = '生成会员每日盈亏报表';
- public function handle(MemberDailyReportService $reports): int
- {
- $date = (string) ($this->argument('date') ?: now()->toDateString());
- $parsed = Carbon::createFromFormat('!Y-m-d', $date);
- if (!$parsed || $parsed->format('Y-m-d') !== $date) {
- $this->error('日期必须是有效的 Y-m-d');
- return self::FAILURE;
- }
- $days = max(1, min(31, (int) $this->option('days')));
- for ($i = 0; $i < $days; $i++) {
- $day = $parsed->copy()->subDays($i)->toDateString();
- $this->info($day . ':' . $reports->refresh($day) . ' 行');
- }
- return self::SUCCESS;
- }
- }
|