PlanWeek.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <?php
  2. namespace App\Console\Commands;
  3. use App\Http\Models\ScheduledTasks;
  4. use App\Http\Models\WeekTaskHistory;
  5. use App\Http\Models\WeekTaskInfo;
  6. use Illuminate\Console\Command;
  7. use Illuminate\Support\Facades\DB;
  8. class PlanWeek extends Command
  9. {
  10. /**
  11. * The name and signature of the console command.
  12. *
  13. * @var string
  14. */
  15. protected $signature = 'plan:week';
  16. /**
  17. * The console command description.
  18. *
  19. * @var string
  20. */
  21. protected $description = 'Command description';
  22. /**
  23. * Create a new command instance.
  24. *
  25. * @return void
  26. */
  27. public function __construct()
  28. {
  29. parent::__construct();
  30. }
  31. /**
  32. * Execute the console command.
  33. * 任务计划
  34. * @return mixed
  35. */
  36. public function handle()
  37. {
  38. $condMap = DB::table('week_task_cond')->pluck('name', 'id')->toArray();
  39. $itemsMap = DB::table('week_task_items')->pluck('name', 'id')->toArray();
  40. $weekInfoList = WeekTaskInfo::query()
  41. ->whereNotIn('user_type', ['wfp-web', 'wfp-design', 'wfp-exam', 'wfp-site-exam', 'wfp-site', 'wfp-seo'])
  42. ->where(['type' => 'now'])->get()->toArray();
  43. $result = [];
  44. foreach ($weekInfoList as $item) {
  45. $result[] = [
  46. 'day' => $item['day'],
  47. 'user_type' => $item['user_type'],
  48. 'describe' => $item['describe'],
  49. 'duty_id' => $item['duty_id'],
  50. 'design_id' => $item['design_id'],
  51. 'web_id' => $item['web_id'],
  52. 'cond_name' => $condMap[$item['cond_id']] ?? '',
  53. 'cond_id' => $item['cond_id'],
  54. 'cond_item_id' => $item['cond_item_id'],
  55. 'cond_item_name' => $itemsMap[$item['cond_item_id']] ?? '',
  56. 'remark' => $item['remark'],
  57. 'status' => $item['status'],
  58. 'insert_date' => date('Y-m-d'),
  59. 'slices_number' => $item['slices_number'] ?? 0,
  60. 'check_score' => $item['check_score'] ?? 0,
  61. 'created_at' => $item['created_at'] ?? null,
  62. 'updated_at' => $item['updated_at'] ?? null,
  63. 'deadline' => $item['deadline'] ?? null,
  64. 'complete' => $item['complete'] ?? null,
  65. ];
  66. }
  67. WeekTaskHistory::query()->insert($result);
  68. //获取近期的日期 排除周末
  69. $dayList = $this->getDay();
  70. //创建延迟任务
  71. $taskList = ScheduledTasks::query()->get();
  72. if (!empty($taskList->toArray())) {
  73. foreach ($taskList as $key => $value) {
  74. $diff = strtotime(date('Y-m-d')) - strtotime(substr($value->created_at, 0, 10));
  75. $day = 86400 * 3;
  76. if ($diff >= $day) {
  77. $update = [
  78. 'type' => $value->type,
  79. 'day' => $value->day,
  80. 'user_type' => $value->user_type,
  81. 'describe' => $value->describe,
  82. 'duty_id' => $value->duty_id,
  83. 'design_id' => $value->design_id,
  84. 'web_id' => $value->web_id,
  85. 'feedback' => $value->feedback,
  86. 'remark' => $value->remark,
  87. 'status' => $value->status,
  88. 'cond_id' => $value->cond_id,
  89. 'created_at' => date('Y-m-d H:i:s'),
  90. 'deadline' => $dayList[2],
  91. ];
  92. WeekTaskInfo::query()->insert($update);
  93. ScheduledTasks::query()->where('id', $value->id)->delete();
  94. }
  95. }
  96. }
  97. }
  98. public function getDay()
  99. {
  100. $days = 12;
  101. $dayList = [];
  102. for ($i = 1; $i <= $days; $i++) {
  103. $day = date('Y-m-d', strtotime(date('Y-m-d')) + 86400 * $i);
  104. $result = $this->isWeekend($day);
  105. if (!$result) {
  106. $dayList[] = $day;
  107. }
  108. }
  109. return $dayList;
  110. }
  111. public function isWeekend($date)
  112. {
  113. if ((date('w', strtotime($date)) == 6) || (date('w', strtotime($date)) == 0)) {
  114. return true;
  115. } else {
  116. return false;
  117. }
  118. }
  119. }