HistorySyncDrugReportCommand.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. namespace App\Console\Commands;
  3. use App\Models\DrugReportInfo;
  4. use App\Servers\HistoryDrugReportService;
  5. use Carbon\Carbon;
  6. use Illuminate\Console\Command;
  7. use App\Facades\Servers\Logs\Log;
  8. class HistorySyncDrugReportCommand extends Command
  9. {
  10. protected $signature = 'drug-report-history';
  11. protected $description = '操作日志同步更新药检报告数据';
  12. public function handle(HistoryDrugReportService $service): int
  13. {
  14. Log::info('drug-report-history','操作历史同步开始');
  15. $time = time();
  16. $lastTime = cache('drug:report:history:time');
  17. $lastTime = 0;
  18. if (empty($lastTime)){
  19. $startTime = Carbon::yesterday()->startOfDay()->format('Y-m-d');
  20. }else{
  21. $startTime = date('Y-m-d', $lastTime);
  22. }
  23. $endTime = date('Y-m-d', $time);
  24. $page = 1;
  25. $pageSize = 20;
  26. Log::info('drug-report-history','操作历史同步开始', ['startTime'=>$startTime, 'endTime'=>$endTime]);
  27. $count = $service->syncDrugReport( $startTime, $endTime, $page, $pageSize, $lastTime);
  28. cache(['drug:report:history:time'=>$time]);
  29. Log::info('drug-report-history','操作历史同步结束:'.$count, ['startTime'=>$startTime, 'endTime'=>$endTime]);
  30. return 0;
  31. }
  32. }