diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index baa94a2..c5467e5 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -34,10 +34,16 @@ protected function schedule(Schedule $schedule) if ($currentTime->gte($nextRun->next_run_time)) { - $shopee_seller_category = ShopeeSellerCategory::where('category_id', $category->id)->where(function($query) { - $query->whereNull('last_ai_written_at') - ->orWhere('last_ai_written_at', '=', ShopeeSellerCategory::whereNotNull('last_ai_written_at')->orderBy('last_ai_written_at', 'asc')->value('last_ai_written_at')); - })->first(); + $shopee_seller_category = ShopeeSellerCategory::where('category_id', $category->id) + ->orderByRaw('ISNULL(last_ai_written_at) DESC') + ->orderBy('last_ai_written_at', 'asc') + ->orderBy('id', 'asc') + ->first(); + + // $shopee_seller_category = ShopeeSellerCategory::where('category_id', $category->id)->where(function($query) { + // $query->whereNull('last_ai_written_at') + // ->orWhere('last_ai_written_at', '=', ShopeeSellerCategory::whereNotNull('last_ai_written_at')->orderBy('last_ai_written_at', 'asc')->value('last_ai_written_at')); + // })->first(); $task = ShopeeSellerTopProductScraperJob::dispatch($shopee_seller_category->seller, $category->country_locale->country_iso, $category) ->onQueue('default')