SettleSharing.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. <?php
  2. namespace App\Console\Commands;
  3. use App\Services\Sharing\ShareDefaults;
  4. use App\Services\Sharing\ShareSettlementService;
  5. use Carbon\Carbon;
  6. use Illuminate\Console\Command;
  7. class SettleSharing extends Command
  8. {
  9. protected $signature='share:settle {date? : 原下注日期Y-m-d,默认北京时间昨日;allow-today时默认当天} {--preview : 只读预览,不登记应付佣金} {--reconcile : 处理迟到结算和改判} {--allow-today : 允许调试结算北京时间当天,不允许未来日期} {--diagnose : 只读说明生效配置、投注明细及各项排除原因,不结算}';
  10. protected $description='每日结算新分享应付佣金,不直接入会员钱包';
  11. public function handle(ShareSettlementService $service): int
  12. {
  13. try {
  14. if ($this->option('reconcile') && $this->option('preview')) throw new \InvalidArgumentException('reconcile不支持preview,请使用日期预览');
  15. $allowToday=(bool)$this->option('allow-today');
  16. if ($this->option('reconcile') && $allowToday) throw new \InvalidArgumentException('allow-today不能与reconcile同时使用');
  17. if ($this->option('reconcile') && $this->option('diagnose')) throw new \InvalidArgumentException('diagnose不能与reconcile同时使用');
  18. $defaultDate=Carbon::now(ShareDefaults::TIMEZONE);
  19. if (!$allowToday) $defaultDate->subDay();
  20. if ($this->option('diagnose')) {
  21. $result=$service->diagnose($this->argument('date') ?: $defaultDate->toDateString());
  22. $this->line(json_encode($result,JSON_UNESCAPED_UNICODE|JSON_PRETTY_PRINT|JSON_THROW_ON_ERROR));
  23. return self::SUCCESS;
  24. }
  25. $result=$this->option('reconcile') ? $service->reconcile() : $service->settle(
  26. $this->argument('date') ?: $defaultDate->toDateString(), !(bool)$this->option('preview'), $allowToday
  27. );
  28. $this->line(json_encode($result,JSON_UNESCAPED_UNICODE|JSON_THROW_ON_ERROR)); return self::SUCCESS;
  29. } catch (\Throwable $e) { $this->error($e->getMessage()); return self::FAILURE; }
  30. }
  31. }