作者 lyh

jiaoben

... ... @@ -245,14 +245,13 @@ class VideoTask extends Command
*/
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)){
$productsQuery = Product::where("status",1)->where("keyword_id","like","%,".$keyword_id.",%")->limit(13)->get();
if (count($productsQuery) > 0){
foreach ($productsQuery as $item){
$productIds[] = $item->id;
}
if (count($productIds)<7){
if (count($productIds) < 13){
$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);
... ... @@ -262,7 +261,6 @@ class VideoTask extends Command
}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)){
... ... @@ -277,7 +275,8 @@ class VideoTask extends Command
if (strpos(','.$keyword_ids.',', ','.$keyword_id.',') === false) {
//不包含
$productModel = new Product();
$keyword_id_str = ','.$keyword_ids.',' . $keyword_id.',';
$keyword_ids = !empty($keyword_ids) ? ','.$keyword_ids.',' : ',' ;
$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];
... ...
... ... @@ -14,7 +14,6 @@ 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;
... ... @@ -42,61 +41,24 @@ class Demo extends Command
protected $description = 'demo';
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
ProjectServer::useProject(110);
return $this->getRecommendAndHotProducts(1970);
DB::disconnect('custom_mysql');
}
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;
}
// /**
// * 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']]);
// }
// }
//
// $fileModel = new FileModel();
// $fileList = $fileModel->list(['project_id'=>$this->param['project_id'],'is_cos'=>1],'id',['id','path','is_cos','name']);
... ... @@ -178,4 +140,26 @@ class Demo extends Command
// }
// return true;
// }
public function handle(){
$minorLanguageModel = new MinorLanguages();
$lists = $minorLanguageModel->list();
foreach ($lists as $v){
$d = new DeployOptimize();
$info = $d->read(['project_id'=>$v['project_id']]);
if($info === false){
continue;
}
if(!empty($info['minor_keywords'])){
echo '关键字'.json_decode($info['minor_keywords']);
$minor_keywords = json_decode($info['minor_keywords']);
foreach ($minor_keywords as $v1){
$v1 = (array)$v1;
if($v['language'] == $v1['name']){
$minorLanguageModel->edit(['minor_keywords'=>$v1['keyword']],['id'=>$v['id']]);
}
}
}
}
}
}
... ...