ResumeAutoRefresh.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. namespace App\Jobs\Cron;
  3. use App\Models\QueueAutoRefresh;
  4. use App\Models\Resume;
  5. use App\Services\Person\ResumeService;
  6. use Illuminate\Bus\Queueable;
  7. use Illuminate\Queue\SerializesModels;
  8. use Illuminate\Queue\InteractsWithQueue;
  9. use Illuminate\Contracts\Queue\ShouldQueue;
  10. use Illuminate\Foundation\Bus\Dispatchable;
  11. use Illuminate\Support\Facades\Cache;
  12. use Illuminate\Support\Facades\DB;
  13. use Illuminate\Support\Facades\Log;
  14. class ResumeAutoRefresh implements ShouldQueue
  15. {
  16. use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
  17. const CREATE_LIST = 'create';
  18. const UPDATE_LIST = 'update';
  19. /**
  20. * Create a new job instance.
  21. *
  22. * @return void
  23. */
  24. public function __construct()
  25. {
  26. }
  27. /**
  28. * Execute the job.
  29. *
  30. * @return void
  31. */
  32. public function handle(ResumeService $resumeService)
  33. {
  34. $resume_id = $resumeService->resumeAutoRefresh();
  35. if($resume_id){
  36. $Resume = Resume::whereIn('id', $resume_id)->get();
  37. try {
  38. Resume::whereIn('id', $resume_id)->update(['updated_at'=>date('Y-m-d H:i:s')]);
  39. QueueAutoRefresh::whereIn('pid', $resume_id)->update(['start_time'=>strtotime("+1 day")]);
  40. $utype = 2;
  41. $startTime = time();
  42. $endTime = strtotime(date('Y-m-d 23:59:59', time()));
  43. foreach ($Resume as $val){
  44. if (Cache::has($val->uid.$utype)) {
  45. $value = Cache::get($val->uid.$utype);
  46. } else {
  47. $value = 0;
  48. }
  49. Cache::put($val->uid.$utype, $value+1, intval(($endTime-$startTime)/60));
  50. }
  51. DB::commit();
  52. } catch (\Exception $e) {
  53. DB::rollback();
  54. }
  55. }
  56. }
  57. }