作者 lyh

jiaoben

... ... @@ -227,7 +227,7 @@ class VideoTask extends Command
}
}
//TODO::所有产品
$thumb = $this->getRecommendAndHotProducts($keyword_id,$project_id);
$thumb = $this->getRecommendAndHotProducts($keyword_id);
$keyword_arr = Keyword::where("project_id",$project_id)->where("status",1)->inRandomOrder()->take(10)->pluck('title')->toArray();
$data = [
'url'=> 'https://' . $domain.'/'.$keywordInfo['route'],
... ... @@ -243,8 +243,9 @@ class VideoTask extends Command
/**
* 关键词聚合页-推荐&热门产品
*/
public function getRecommendAndHotProducts($keyword_id,$project_id): ?array
public function getRecommendAndHotProducts($keyword_id): ?array
{
@file_put_contents(storage_path('logs/lyh_error.log'), var_export('进入', true) . PHP_EOL, FILE_APPEND);
$productIds = [];
$productsQuery = Product::where("status",1)->where("keyword_id","like","%,".$keyword_id.",%")->limit(7)->get();
if (!empty($productsQuery)){
... ...
... ... @@ -14,6 +14,7 @@ use App\Models\File\File as FileModel;
use App\Models\File\Image;
use App\Models\File\Image as ImageModel;
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;
... ... @@ -41,24 +42,58 @@ class Demo extends Command
protected $description = 'demo';
// /**
// * Execute the job.
// *
// * @return void
// */
// public function handle()
// {
// $this->param['project_id'] = 181;
// $imageModel = new ImageModel();
// //获取当前项目的所有图片
// $imageList = $imageModel->list(['project_id'=>$this->param['project_id'],'is_cos'=>1],'id',['id','path','is_cos','size']);
// if(!empty($imageList)){
// $amazonS3Service = new AmazonS3Service();
// foreach ($imageList as $k => $v){
// $amazonS3Service->syncImageFiles(getImageUrl($v['path']));
// $imageModel->edit(['is_cos'=>0],['id'=>$v['id']]);
// }
// }
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
return $this->getRecommendAndHotProducts(1970);
}
public function getRecommendAndHotProducts($keyword_id): ?array
{
@file_put_contents(storage_path('logs/lyh_error.log'), var_export('进入', true) . PHP_EOL, FILE_APPEND);
$productIds = [];
$productsQuery = Product::where("status",1)->where("keyword_id","like","%,".$keyword_id.",%")->limit(7)->get();
if (!empty($productsQuery)){
foreach ($productsQuery as $item){
$productIds[] = $item->id;
}
if (count($productIds)<7){
$product_all_id = Product::where('thumb','!=',null)->whereNotIn('id', $productIds)->where("status",Product::STATUS_ON)->inRandomOrder()->take(20 - count($productIds))->pluck('id')->toArray();
$randomData = Product::whereIn("id", $product_all_id)->get();
$products = $productsQuery->merge($randomData);
}else{
$products = $productsQuery;
}
}else{
$product_all_id = Product::where('thumb','!=',null)->where("status",Product::STATUS_ON)->inRandomOrder()->take(20)->pluck('id')->toArray();
$products = Product::whereIn("id", $product_all_id)->get();
@file_put_contents(storage_path('logs/lyh_error.log'), var_export($products, true) . PHP_EOL, FILE_APPEND);
}
$data = [];
if (!empty($products)){
foreach ($products as $item){
if(empty($item->thumb) || ($item->thumb['url'] == "")){
continue;
}
if(count($data) > 13){
break;
}
$keyword_ids = implode(',',$item->keyword_id);
if (strpos(','.$keyword_ids.',', ','.$keyword_id.',') === false) {
//不包含
$productModel = new Product();
$keyword_id_str = ','.$keyword_ids.',' . $keyword_id.',';
$productModel->edit(['keyword_id'=>$keyword_id_str],['id'=>$item->id]);
}
$data[] = ['url'=>getImageUrl($item->thumb['url']),'title'=>$item->title];
}
}
return $data;
}
//
// $fileModel = new FileModel();
// $fileList = $fileModel->list(['project_id'=>$this->param['project_id'],'is_cos'=>1],'id',['id','path','is_cos','name']);
... ...