12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- <?php
- namespace App\Console\Commands;
- use App\Http\Models\PrKeywordExtend;
- use App\Http\Models\Site;
- use Illuminate\Console\Command;
- class KeywordExpansionSync extends Command
- {
-
- protected $signature = 'sync:keyword_expansion';
-
- protected $description = 'Command description';
-
- public function handle()
- {
-
- $maxIds = PrKeywordExtend::query()->selectRaw('max(id) as id_max,site_id')
- ->groupBy('site_id')
- ->pluck('id_max', 'site_id')->toArray();
-
- $list = PrKeywordExtend::query()->whereIn('id', $maxIds)->get();
- $ids = [];
- $date = date("Ym", strtotime("last day of -3 month", strtotime(date("Ym"))));
- foreach ($list as $value) {
- if ($value->ym <= $date) {
- $ids[] = $value->site_id;
- }
- }
- Site::query()
- ->whereIn('id', $ids)
- ->whereIn('status', [2, 3])
- ->update(['keyword_memo' => '']);
-
- $date = date("Y-m-d", strtotime("last day of -3 month", strtotime(date("Y-m-d"))));
- $id = Site::query()
- ->where('online_at', '<=', $date)
- ->whereIn('status', [2, 3])
- ->pluck('id')->toArray();
- $ids1 = [];
- foreach ($id as $value) {
- $result = PrKeywordExtend::query()->where('site_id', $value)->first();
- if (empty($result)) {
- $ids1[] = $value;
- }
- }
- Site::query()
- ->whereIn('id', $ids1)
- ->whereIn('status', [2, 3])
- ->update(['keyword_memo' => '']);
- }
- }
|