| 123456789101112131415161718192021222324252627282930 |
- <?php
- namespace App\Console\Commands;
- use App\Services\Agent\AgentCommissionService;
- use App\Services\Agent\AgentReportService;
- use Illuminate\Console\Command;
- class AgentDailySettle extends Command
- {
- protected $signature = 'agent:settle {date? : Y-m-d,默认昨天} {--no-credit : 只生成佣金记录,不入账}';
- protected $description = '生成代理日报并结算流水/盈亏佣金';
- public function handle(AgentReportService $reports, AgentCommissionService $commissions): int
- {
- $date = (string) ($this->argument('date') ?: now()->subDay()->toDateString());
- try {
- $date = \Carbon\Carbon::createFromFormat('Y-m-d', $date)->toDateString();
- $stats = $reports->refreshDaily($date);
- $result = $commissions->settle($date, !$this->option('no-credit'));
- $this->info("代理日报 {$stats} 条,佣金新建 {$result['created']} 条,入账 {$result['credited']} 条");
- return self::SUCCESS;
- } catch (\Throwable $e) {
- $this->error($e->getMessage());
- report($e);
- return self::FAILURE;
- }
- }
- }
|