作者 lyh

gx

... ... @@ -18,6 +18,8 @@ use App\Models\Manage\EntryPosition;
use App\Models\Manage\ManageHr;
use App\Models\Product\Keyword;
use App\Models\Product\Product;
use App\Models\Project\DeployOptimize;
use App\Models\Project\MinorLanguages;
use App\Models\Project\Project;
use App\Models\WebSetting\WebSettingService;
use App\Services\ProjectServer;
... ... @@ -262,74 +264,29 @@ class Demo extends Command
// }
public function handle(){
// $projectModel = new Project();
// $list = $projectModel->list(['delete_status'=>0]);
// foreach ($list as $v){
ProjectServer::useProject(150);
$this->getKeywordImage();
DB::disconnect('custom_mysql');
// }
}
/**
* @remark :根据关键字获取产品主图
* @name :getKeywordList
* @author :lyh
* @method :post
* @time :2024/2/23 16:28
*/
public function getKeywordImage($keyword_id = 1,$project_id = 150){
$keywordModel = new Keyword();
$keywordInfo = $keywordModel->read(['id'=>$keyword_id]);
//TODO::所有产品
$thumb = $this->getRecommendAndHotProducts($keywordInfo['route'],$project_id);
$domainModel = new DomainInfo();
$domainInfo = $domainModel->read(['project_id'=>$project_id]);
if(!empty($domainInfo)){
$keywordInfo['route'] = $domainInfo['domain'].'/'.$keywordInfo['route'];
}
$data = [
'url'=>$keywordInfo['route'],
'title'=>$keywordInfo['title'],
'keyword_title'=>$keywordInfo['keyword_title'],
'keyword_content'=>$keywordInfo['keyword_content'],
'product_list'=>$thumb ?? []
];
dd($data);
return $data;
}
/**
* 关键词聚合页-推荐&热门产品
*/
public function getRecommendAndHotProducts($route,$project_id): ?array
{
$productIds = [];
$productKeyword = Keyword::where("project_id",$project_id)->where("route",$route)->first();
if (!empty($productKeyword)){
$productsQuery = Product::where("project_id", $project_id)->where("status",1)->where("keyword_id","like","%,".$productKeyword->id.",%")->limit(7)->get();
if (!empty($productsQuery)){
foreach ($productsQuery as $item){
$productIds[] = $item->id;
$projectModel = new DeployOptimize();
$list = $projectModel->list();
foreach ($list as $v){
$data = [];
if(!empty($v['minor_languages'])){
foreach ($v['minor_languages'] as $k1=> $v1){
if(!empty($v1['tl']) && !empty($v1['type'])){
$data[] = [
'language'=>$v1['tl'],
'type'=>$v1['type'],
'keywords'=>$v1['keywords'],
'service_day'=>$v1['service_day'],
'project_id'=>$v['project_id']
];
}
}
if (count($productIds)<7){
$randomData = Product::where("project_id", $project_id)->where("status",1)->whereNotIn('id', $productIds)->inRandomOrder()->take(13-count($productIds))->get();
$products = $productsQuery->merge($randomData);
}else{
$products = $productsQuery;
}
}else{
$products = Product::where("project_id", $project_id)->where("status",1)->inRandomOrder()->take(13)->get();
}
}
$data = [];
if (!empty($products)){
foreach ($products as $item){
$data[] = !empty($item->thumb) && $item->thumb['url'] != "" ? getImageUrl($item->thumb['url']) : "";
}
$languageModel = new MinorLanguages();
$languageModel->insert($data);
}
return $data;
}
public function printMessage()
{
$client = new Client();
... ...