sync
This commit is contained in:
@@ -2,19 +2,19 @@
|
||||
|
||||
namespace App\Jobs\Tasks;
|
||||
|
||||
use fivefilters\Readability\Configuration as ReadabilityConfiguration;
|
||||
use fivefilters\Readability\ParseException as ReadabilityParseException;
|
||||
use fivefilters\Readability\Readability;
|
||||
use App\Helpers\FirstParty\OpenAI\OpenAI;
|
||||
use App\Helpers\FirstParty\OSSUploader\OSSUploader;
|
||||
use App\Models\AiWriteup;
|
||||
use App\Models\Category;
|
||||
use App\Models\Post;
|
||||
use App\Models\PostCategory;
|
||||
use App\Models\Category;
|
||||
use App\Models\ShopeeSellerCategory;
|
||||
use App\Models\ShopeeSellerScrape;
|
||||
use App\Models\ShopeeSellerScrapedImage;
|
||||
use Exception;
|
||||
use fivefilters\Readability\Configuration as ReadabilityConfiguration;
|
||||
use fivefilters\Readability\ParseException as ReadabilityParseException;
|
||||
use fivefilters\Readability\Readability;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use LaravelFreelancerNL\LaravelIndexNow\Facades\IndexNow;
|
||||
use LaravelGoogleIndexing;
|
||||
@@ -36,8 +36,6 @@ public static function handle(ShopeeSellerScrape $shopee_seller_scrape)
|
||||
$shopee_task->shopee_seller_scrape = $shopee_seller_scrape;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// dd($shopee_task);
|
||||
|
||||
// dd($shopee_task->product_task->response);
|
||||
@@ -57,11 +55,11 @@ public static function handle(ShopeeSellerScrape $shopee_seller_scrape)
|
||||
if (is_null($ai_writeup)) {
|
||||
|
||||
$categories = [
|
||||
'Beauty',
|
||||
'Technology',
|
||||
'Home & Living',
|
||||
'Health',
|
||||
'Fitness'
|
||||
'Beauty',
|
||||
'Technology',
|
||||
'Home & Living',
|
||||
'Health',
|
||||
'Fitness',
|
||||
];
|
||||
|
||||
$ai_output = OpenAI::writeProductArticle($excerpt, $photos, $categories);
|
||||
@@ -76,11 +74,10 @@ public static function handle(ShopeeSellerScrape $shopee_seller_scrape)
|
||||
throw ($e);
|
||||
} else {
|
||||
|
||||
$picked_category = Category::where('name', $ai_output->category)->where('country_locale_id', $shopee_seller_scrape->category->country_locale_id)->first();
|
||||
$picked_category = Category::where('name', $ai_output->category)->where('country_locale_id', $shopee_seller_scrape->category->country_locale_id)->first();
|
||||
|
||||
if (is_null($picked_category))
|
||||
{
|
||||
$picked_category = $shopee_seller_scrape->category;
|
||||
if (is_null($picked_category)) {
|
||||
$picked_category = $shopee_seller_scrape->category;
|
||||
}
|
||||
|
||||
// save
|
||||
@@ -122,13 +119,12 @@ public static function handle(ShopeeSellerScrape $shopee_seller_scrape)
|
||||
$shopee_seller_scrape->last_ai_written_at = now();
|
||||
$shopee_seller_scrape->save();
|
||||
|
||||
$shopee_seller_category = ShopeeSellerCategory::where('seller', $shopee_seller_scrape->seller)->first();
|
||||
$shopee_seller_category = ShopeeSellerCategory::where('seller', $shopee_seller_scrape->seller)->first();
|
||||
|
||||
if (is_null($shopee_seller_category))
|
||||
{
|
||||
$shopee_seller_category = new ShopeeSellerCategory;
|
||||
$shopee_seller_category->seller = $shopee_seller_scrape->seller;
|
||||
$shopee_seller_category->category_id = $shopee_seller_scrape->category_id;
|
||||
if (is_null($shopee_seller_category)) {
|
||||
$shopee_seller_category = new ShopeeSellerCategory;
|
||||
$shopee_seller_category->seller = $shopee_seller_scrape->seller;
|
||||
$shopee_seller_category->category_id = $shopee_seller_scrape->category_id;
|
||||
}
|
||||
|
||||
$shopee_seller_category->last_ai_written_at = $shopee_seller_scrape->last_ai_written_at;
|
||||
@@ -169,34 +165,33 @@ private static function getProductPricingExcerpt(array $jsonLdData)
|
||||
foreach ($jsonLdData as $data) {
|
||||
// Ensure the type is "Product" before proceeding
|
||||
if (isset($data->{'@type'}) && $data->{'@type'} === 'Product') {
|
||||
|
||||
// Extract necessary data
|
||||
$lowPrice = $data->offers->lowPrice ?? null;
|
||||
$highPrice = $data->offers->highPrice ?? null;
|
||||
$price = $data->offers->price ?? null;
|
||||
$currency = $data->offers->priceCurrency ?? null;
|
||||
$sellerName = $data->offers->seller->name ?? "online store"; // default to "online store" if name is not set
|
||||
|
||||
if (!is_empty($currency))
|
||||
{
|
||||
if ($currency == 'MYR')
|
||||
{
|
||||
$currency = 'RM';
|
||||
// Extract necessary data
|
||||
$lowPrice = $data->offers->lowPrice ?? null;
|
||||
$highPrice = $data->offers->highPrice ?? null;
|
||||
$price = $data->offers->price ?? null;
|
||||
$currency = $data->offers->priceCurrency ?? null;
|
||||
$sellerName = $data->offers->seller->name ?? 'online store'; // default to "online store" if name is not set
|
||||
|
||||
if (! is_empty($currency)) {
|
||||
if ($currency == 'MYR') {
|
||||
$currency = 'RM';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Determine and format pricing sentence
|
||||
if ($lowPrice && $highPrice) {
|
||||
$lowPrice = number_format($lowPrice, 0);
|
||||
$highPrice = number_format($highPrice, 0);
|
||||
|
||||
// Determine and format pricing sentence
|
||||
if ($lowPrice && $highPrice) {
|
||||
$lowPrice = number_format($lowPrice, 0);
|
||||
$highPrice = number_format($highPrice, 0);
|
||||
return "Price Range from {$currency} {$lowPrice} to {$highPrice} in {$sellerName} online store";
|
||||
} elseif ($price) {
|
||||
$price = number_format($price, 0);
|
||||
return "Priced at {$currency} {$price} in {$sellerName} online store";
|
||||
} else {
|
||||
return "Price not stated, refer to {$sellerName} online store";
|
||||
}
|
||||
return "Price Range from {$currency} {$lowPrice} to {$highPrice} in {$sellerName} online store";
|
||||
} elseif ($price) {
|
||||
$price = number_format($price, 0);
|
||||
|
||||
return "Priced at {$currency} {$price} in {$sellerName} online store";
|
||||
} else {
|
||||
return "Price not stated, refer to {$sellerName} online store";
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user