KeywordExpansionSync.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. namespace App\Console\Commands;
  3. use App\Http\Models\PrKeywordExtend;
  4. use App\Http\Models\Site;
  5. use Illuminate\Console\Command;
  6. class KeywordExpansionSync extends Command
  7. {
  8. /**
  9. * The name and signature of the console command.
  10. *
  11. * @var string
  12. */
  13. protected $signature = 'sync:keyword_expansion';
  14. /**
  15. * The console command description.
  16. *
  17. * @var string
  18. */
  19. protected $description = 'Command description';
  20. /**
  21. * 删除备注
  22. * @return mixed
  23. */
  24. public function handle()
  25. {
  26. //每个项目最新的一次的记录的id
  27. $maxIds = PrKeywordExtend::query()->selectRaw('max(id) as id_max,site_id')
  28. ->groupBy('site_id')
  29. ->pluck('id_max', 'site_id')->toArray();
  30. //3个月内没有拓展过
  31. $list = PrKeywordExtend::query()->whereIn('id', $maxIds)->get();
  32. $ids = [];
  33. $date = date("Ym", strtotime("last day of -3 month", strtotime(date("Ym"))));
  34. foreach ($list as $value) {
  35. if ($value->ym <= $date) {
  36. $ids[] = $value->site_id;
  37. }
  38. }
  39. Site::query()
  40. ->whereIn('id', $ids)
  41. ->whereIn('status', [2, 3])
  42. ->update(['keyword_memo' => '']);
  43. //从未拓展过
  44. $date = date("Y-m-d", strtotime("last day of -3 month", strtotime(date("Y-m-d"))));
  45. $id = Site::query()
  46. ->where('online_at', '<=', $date)
  47. ->whereIn('status', [2, 3])
  48. ->pluck('id')->toArray();
  49. $ids1 = [];
  50. foreach ($id as $value) {
  51. $result = PrKeywordExtend::query()->where('site_id', $value)->first();
  52. if (empty($result)) {
  53. $ids1[] = $value;
  54. }
  55. }
  56. Site::query()
  57. ->whereIn('id', $ids1)
  58. ->whereIn('status', [2, 3])
  59. ->update(['keyword_memo' => '']);
  60. }
  61. }