public function getList($type) { $list = Db::name('video')->field('id')->where('name','like', "%{$type}%")->select(); if (empty($type)) { $list = Db::name('video')->field('id')->select(); } $count = count($list); $rand_list=range(0, $count-1); // unset($rand_list[0]); $num = 10; if($count < $num){$num = $count-1;} //判断是否取得条数大于查询到的条数 $rand_list = array_rand($rand_list, $num); //随机取几条 $tuijian_array = array(); foreach ((array)$rand_list as $key) { $tuijian_array[] = $list[$key]["id"]; //将随机出来的键取值 } $randArr = Db::name('video')->where('id','in', $tuijian_array)->select(); foreach ($randArr as &$value){ $value["count"] = mt_rand(3000, 7000); } return $randArr; }