正在显示
1 个修改的文件
包含
3 行增加
和
23 行删除
| @@ -252,34 +252,14 @@ class VideoTask extends Command | @@ -252,34 +252,14 @@ class VideoTask extends Command | ||
| 252 | $productIds[] = $item->id; | 252 | $productIds[] = $item->id; |
| 253 | } | 253 | } |
| 254 | if (count($productIds)<7){ | 254 | if (count($productIds)<7){ |
| 255 | - $product_all_id = Product::where('thumb','!=',null)->whereNotIn('id', $productIds)->where("status",Product::STATUS_ON)->pluck('id')->toArray(); | ||
| 256 | - $number = 40; | ||
| 257 | - $array_count = count($product_all_id); | ||
| 258 | - if ($array_count > 0) { | ||
| 259 | - $product_id_key = array_rand($product_all_id, min($array_count, $number - count($productIds))); | ||
| 260 | - foreach ($product_id_key as $value_key){ | ||
| 261 | - $project_id_arr[] = $product_all_id[$value_key]; | ||
| 262 | - } | ||
| 263 | - $randomData = Product::whereIn("id", $project_id_arr)->get(); | 255 | + $product_all_id = Product::where('thumb','!=',null)->whereNotIn('id', $productIds)->where("status",Product::STATUS_ON)->inRandomOrder()->take(20 - count($productIds))->pluck('id')->toArray(); |
| 256 | + $randomData = Product::whereIn("id", $product_all_id)->get(); | ||
| 264 | $products = $productsQuery->merge($randomData); | 257 | $products = $productsQuery->merge($randomData); |
| 265 | - } | ||
| 266 | }else{ | 258 | }else{ |
| 267 | $products = $productsQuery; | 259 | $products = $productsQuery; |
| 268 | } | 260 | } |
| 269 | }else{ | 261 | }else{ |
| 270 | - $product_all_id = Product::where('thumb','!=',null)->where("status",Product::STATUS_ON)->pluck('id')->toArray(); | ||
| 271 | - shuffle($product_all_id); | ||
| 272 | - $number = 40; | ||
| 273 | - $array_count = count($product_all_id); | ||
| 274 | - if ($array_count > 0) | ||
| 275 | - { | ||
| 276 | - $project_id_arr = []; | ||
| 277 | - $product_id_key = array_rand($product_all_id, min($array_count, $number-count($productIds))); | ||
| 278 | - foreach ($product_id_key as $value_key){ | ||
| 279 | - $project_id_arr[] = $product_all_id[$value_key]; | ||
| 280 | - } | ||
| 281 | - $products = Product::where("project_id", $project_id)->whereIn("id", $project_id_arr)->get(); | ||
| 282 | - } | 262 | + $products = Product::where('thumb','!=',null)->where("status",Product::STATUS_ON)->inRandomOrder()->take(20)->pluck('id')->toArray(); |
| 283 | } | 263 | } |
| 284 | $data = []; | 264 | $data = []; |
| 285 | if (!empty($products)){ | 265 | if (!empty($products)){ |
-
请 注册 或 登录 后发表评论