作者 lyh

gx

@@ -216,15 +216,16 @@ class VideoTask extends Command @@ -216,15 +216,16 @@ class VideoTask extends Command
216 $productIds[] = $item->id; 216 $productIds[] = $item->id;
217 } 217 }
218 if (count($productIds)<7){ 218 if (count($productIds)<7){
219 - $product_all_id = Product::where("project_id", $project_id)->whereNotIn('id', $productIds)->where("status",1)->pluck('id')->toArray();  
220 - $product_id = array_rand($product_all_id, 40-count($productIds)); 219 + $product_all_id = Product::where("project_id", $project_id)->whereNotIn('id', $productIds)->where("status",Product::STATUS_ON)->pluck('id')->toArray();
  220 + $number = 40;
  221 + $product_id = array_rand($product_all_id, min(count($product_all_id, $number-count($productIds))));
221 $randomData = Product::where("project_id", $project_id)->whereIn("id", $product_id)->get(); 222 $randomData = Product::where("project_id", $project_id)->whereIn("id", $product_id)->get();
222 $products = $productsQuery->merge($randomData); 223 $products = $productsQuery->merge($randomData);
223 }else{ 224 }else{
224 $products = $productsQuery; 225 $products = $productsQuery;
225 } 226 }
226 }else{ 227 }else{
227 - $product_all_id = Product::where("project_id", $project_id)->where("status",1)->pluck('id')->toArray(); 228 + $product_all_id = Product::where("project_id", $project_id)->where("status",Product::STATUS_ON)->pluck('id')->toArray();
228 $product_id = array_rand($product_all_id, 40); 229 $product_id = array_rand($product_all_id, 40);
229 $products = Product::where("project_id", $project_id)->whereIn("id", $product_id)->get(); 230 $products = Product::where("project_id", $project_id)->whereIn("id", $product_id)->get();
230 } 231 }