增加随机排序支持

This commit is contained in:
thinkphp
2015-12-11 22:11:47 +08:00
parent 774736f41c
commit 7f851362b1
6 changed files with 48 additions and 18 deletions

View File

@@ -93,24 +93,13 @@ class Sqlsrv extends Driver
}
/**
* order分析
* 随机排序
* @access protected
* @param mixed $order
* @return string
*/
protected function parseOrder($order)
protected function parseRand()
{
$array = [];
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()';
return 'rand()';
}
/**