作者 lyh

修改脚本

... ... @@ -252,34 +252,14 @@ class VideoTask extends Command
$productIds[] = $item->id;
}
if (count($productIds)<7){
$product_all_id = Product::where('thumb','!=',null)->whereNotIn('id', $productIds)->where("status",Product::STATUS_ON)->pluck('id')->toArray();
$number = 40;
$array_count = count($product_all_id);
if ($array_count > 0) {
$product_id_key = array_rand($product_all_id, min($array_count, $number - count($productIds)));
foreach ($product_id_key as $value_key){
$project_id_arr[] = $product_all_id[$value_key];
}
$randomData = Product::whereIn("id", $project_id_arr)->get();
$products = $productsQuery->merge($randomData);
}
$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)->pluck('id')->toArray();
shuffle($product_all_id);
$number = 40;
$array_count = count($product_all_id);
if ($array_count > 0)
{
$project_id_arr = [];
$product_id_key = array_rand($product_all_id, min($array_count, $number-count($productIds)));
foreach ($product_id_key as $value_key){
$project_id_arr[] = $product_all_id[$value_key];
}
$products = Product::where("project_id", $project_id)->whereIn("id", $project_id_arr)->get();
}
$products = Product::where('thumb','!=',null)->where("status",Product::STATUS_ON)->inRandomOrder()->take(20)->pluck('id')->toArray();
}
$data = [];
if (!empty($products)){
... ...