mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-07 23:22:48 +08:00
增加随机排序支持
This commit is contained in:
@@ -15,7 +15,6 @@ use PDO;
|
|||||||
use think\Config;
|
use think\Config;
|
||||||
use think\Debug;
|
use think\Debug;
|
||||||
use think\Exception;
|
use think\Exception;
|
||||||
use think\Lang;
|
|
||||||
use think\Log;
|
use think\Log;
|
||||||
|
|
||||||
abstract class Driver
|
abstract class Driver
|
||||||
@@ -715,7 +714,7 @@ abstract class Driver
|
|||||||
*/
|
*/
|
||||||
protected function parseLimit($limit)
|
protected function parseLimit($limit)
|
||||||
{
|
{
|
||||||
return !empty($limit) ? ' LIMIT ' . $limit . ' ' : '';
|
return (!empty($limit) && false === strpos($limit, '(')) ? ' LIMIT ' . $limit . ' ' : '';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -747,6 +746,8 @@ abstract class Driver
|
|||||||
if (is_numeric($key)) {
|
if (is_numeric($key)) {
|
||||||
if (false === strpos($val, '(')) {
|
if (false === strpos($val, '(')) {
|
||||||
$array[] = $this->parseKey($val);
|
$array[] = $this->parseKey($val);
|
||||||
|
} elseif ('[rand]' == $val) {
|
||||||
|
$array[] = $this->parseRand();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$sort = in_array(strtolower(trim($val)), ['asc', 'desc']) ? ' ' . $val : '';
|
$sort = in_array(strtolower(trim($val)), ['asc', 'desc']) ? ' ' . $val : '';
|
||||||
|
|||||||
@@ -107,4 +107,14 @@ class Mysql extends Driver
|
|||||||
return $key;
|
return $key;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 随机排序
|
||||||
|
* @access protected
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
protected function parseRand()
|
||||||
|
{
|
||||||
|
return 'rand()';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -189,4 +189,14 @@ class Oracle extends Driver
|
|||||||
}
|
}
|
||||||
return $key;
|
return $key;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 随机排序
|
||||||
|
* @access protected
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
protected function parseRand()
|
||||||
|
{
|
||||||
|
return 'DBMS_RANDOM.value';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -110,4 +110,14 @@ class Pgsql extends Driver
|
|||||||
}
|
}
|
||||||
return $key;
|
return $key;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 随机排序
|
||||||
|
* @access protected
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
protected function parseRand()
|
||||||
|
{
|
||||||
|
return 'RANDOM()';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -91,4 +91,14 @@ class Sqlite extends Driver
|
|||||||
}
|
}
|
||||||
return $limitStr;
|
return $limitStr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 随机排序
|
||||||
|
* @access protected
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
protected function parseRand()
|
||||||
|
{
|
||||||
|
return 'RANDOM()';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -93,24 +93,13 @@ class Sqlsrv extends Driver
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* order分析
|
* 随机排序
|
||||||
* @access protected
|
* @access protected
|
||||||
* @param mixed $order
|
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
protected function parseOrder($order)
|
protected function parseRand()
|
||||||
{
|
{
|
||||||
$array = [];
|
return 'rand()';
|
||||||
foreach ($order as $key => $val) {
|
|
||||||
if (is_numeric($key)) {
|
|
||||||
$array[] = $this->parseKey($val);
|
|
||||||
} else {
|
|
||||||
$sort = in_array(strtolower(trim($val)), ['asc', 'desc']) ? ' ' . $val : '';
|
|
||||||
$array[] = $this->parseKey($key) . ' ' . $sort;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$order = implode(',', $array);
|
|
||||||
return !empty($order) ? ' ORDER BY ' . $order : ' ORDER BY rand()';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user