AgentDailySettle.php 1.1 KB

123456789101112131415161718192021222324252627282930
  1. <?php
  2. namespace App\Console\Commands;
  3. use App\Services\Agent\AgentCommissionService;
  4. use App\Services\Agent\AgentReportService;
  5. use Illuminate\Console\Command;
  6. class AgentDailySettle extends Command
  7. {
  8. protected $signature = 'agent:settle {date? : Y-m-d,默认昨天} {--no-credit : 只生成佣金记录,不入账}';
  9. protected $description = '生成代理日报并结算流水/盈亏佣金';
  10. public function handle(AgentReportService $reports, AgentCommissionService $commissions): int
  11. {
  12. $date = (string) ($this->argument('date') ?: now()->subDay()->toDateString());
  13. try {
  14. $date = \Carbon\Carbon::createFromFormat('Y-m-d', $date)->toDateString();
  15. $stats = $reports->refreshDaily($date);
  16. $result = $commissions->settle($date, !$this->option('no-credit'));
  17. $this->info("代理日报 {$stats} 条,佣金新建 {$result['created']} 条,入账 {$result['credited']} 条");
  18. return self::SUCCESS;
  19. } catch (\Throwable $e) {
  20. $this->error($e->getMessage());
  21. report($e);
  22. return self::FAILURE;
  23. }
  24. }
  25. }