作者 赵彬吉

update

... ... @@ -4,6 +4,8 @@ namespace App\Console\Commands\Tdk;
use App\Helper\Arr;
use App\Models\News\News;
use App\Models\News\NewsCategory;
use App\Models\Product\Keyword;
use App\Models\Project\KeywordPrefix;
use App\Models\Project\Project;
... ... @@ -71,41 +73,41 @@ class RerunSeoTdk extends Command
* @author zbj
* @date 2025/4/12
*/
public function judgeAnomalies($project_id){
dump($project_id);
$all_prefixes = $this->getAllPrefix(1, $project_id);
$all_prefixes = array_map('strtolower', $all_prefixes);
//获取当前项目的所有分类
$list = Keyword::select('title', 'seo_title', 'id')->get()->toArray();
//新闻 seo_keyword 和 分类名一样的
$ids = [];
foreach ($list as $k=>$item){
$seo_title = $item['seo_title'];
$id = $item['id'];
$title = $item['title'];
if(Str::startsWith(strtolower($seo_title), ['wholesale', 'cheap', 'buy']) && Str::contains(strtolower($seo_title), ['manufacturer', 'manufacturers', 'factory', 'factories', 'exporter', 'exporters', 'company', 'companies', 'supplier', 'suppliers'])){
$ids[] = $id;
dump($seo_title);
continue;
}
$topic_words = explode(' ', strtolower($title));
//关键词最后一个是前缀 且 有前后缀
if(in_array(Arr::last($topic_words), $all_prefixes) && $title != $seo_title){
$ids[] = $id;
dump($seo_title);
continue;
}
}
$count = count($ids);
if($count){
echo "项目{$project_id},共{$count}条需要重跑";
LogUtils::info("RerunSeoTdk: 项目{$project_id},共{$count}条需要重跑");
Keyword::whereIn('id', $ids)->update(['seo_title' => '']);
ProjectUpdateTdk::add_task($project_id);
}
}
// public function judgeAnomalies($project_id){
// dump($project_id);
// $all_prefixes = $this->getAllPrefix(1, $project_id);
// $all_prefixes = array_map('strtolower', $all_prefixes);
//
// //获取当前项目的所有分类
// $list = Keyword::select('title', 'seo_title', 'id')->get()->toArray();
// //新闻 seo_keyword 和 分类名一样的
// $ids = [];
// foreach ($list as $k=>$item){
// $seo_title = $item['seo_title'];
// $id = $item['id'];
// $title = $item['title'];
// if(Str::startsWith(strtolower($seo_title), ['wholesale', 'cheap', 'buy']) && Str::contains(strtolower($seo_title), ['manufacturer', 'manufacturers', 'factory', 'factories', 'exporter', 'exporters', 'company', 'companies', 'supplier', 'suppliers'])){
// $ids[] = $id;
// dump($seo_title);
// continue;
// }
// $topic_words = explode(' ', strtolower($title));
// //关键词最后一个是前缀 且 有前后缀
// if(in_array(Arr::last($topic_words), $all_prefixes) && $title != $seo_title){
// $ids[] = $id;
// dump($seo_title);
// continue;
// }
// }
//
// $count = count($ids);
// if($count){
// echo "项目{$project_id},共{$count}条需要重跑";
// LogUtils::info("RerunSeoTdk: 项目{$project_id},共{$count}条需要重跑");
// Keyword::whereIn('id', $ids)->update(['seo_title' => '']);
// ProjectUpdateTdk::add_task($project_id);
// }
// }
// /**
// * 判断seo_title后缀重复
... ... @@ -139,28 +141,28 @@ class RerunSeoTdk extends Command
// }
// }
// /**
// * 判断异常
// * @author zbj
// * @date 2025/4/12
// */
// public function judgeAnomalies($project_id){
// //获取当前项目的所有分类
// $categories = NewsCategory::pluck('name', 'id')->toArray();
// //新闻 seo_keyword 和 分类名一样的
// $news_ids = [];
// foreach ($categories as $category){
// $ids = News::WhereRaw("FIND_IN_SET('{$category}', `seo_keywords`)")->pluck('id')->toArray();
// $news_ids = array_unique(array_merge($news_ids, $ids));
// }
//
// $count = count($news_ids);
// if($count){
// echo "项目{$project_id},共{$count}条需要重跑";
// News::whereIn('id', $news_ids)->update(['seo_keywords' => '']);
// ProjectUpdateTdk::add_task($project_id);
// }
// }
/**
* 判断异常
* @author zbj
* @date 2025/4/12
*/
public function judgeAnomalies($project_id){
//获取当前项目的所有分类
$categories = NewsCategory::pluck('alias', 'id')->toArray();
//新闻 seo_keyword 和 分类名一样的
$news_ids = [];
foreach ($categories as $category){
$ids = News::WhereRaw("FIND_IN_SET('{$category}', `seo_keywords`)")->pluck('id')->toArray();
$news_ids = array_unique(array_merge($news_ids, $ids));
}
$count = count($news_ids);
if($count){
echo "项目{$project_id},共{$count}条需要重跑";
News::whereIn('id', $news_ids)->update(['seo_keywords' => '']);
ProjectUpdateTdk::add_task($project_id);
}
}
public function getAllPrefix($type, int $project_id = 0){
$cache_key = 'AllPrefix_' . $type . '_' . $project_id;
... ...
... ... @@ -4,6 +4,7 @@ namespace App\Http\Controllers\Api;
use App\Enums\Common\Code;
use App\Helper\Translate;
use App\Models\Domain\DomainInfo;
use App\Models\Product\Category;
use App\Models\Product\CategoryRelated;
use App\Models\Product\Product;
... ... @@ -276,6 +277,11 @@ class ProductController extends BaseController
$product = Product::whereFullText('title', $keyword)->inRandomOrder()->select(['title', 'intro', 'thumb'])->first();
if($product){
ProjectServer::useProject($project_id);
$product['url'] = (new DomainInfo())->getProjectIdDomain($project_id) . getRouteMap(RouteMap::SOURCE_PRODUCT,$product->id);
}
$this->response('success', Code::SUCCESS, $product?:[]);
}
}
... ...