1
This commit is contained in:
@@ -29,21 +29,28 @@ class Country extends Base
|
||||
$page = max(1, intval($this->request->param('page', 1)));
|
||||
$perPage = max(1, min(intval($this->request->param('per_page', 20)), 100));
|
||||
|
||||
$query = Db::name('country');
|
||||
|
||||
$where = [];
|
||||
if ($keyword !== '') {
|
||||
$query->where('zh_name|en_name|code', 'like', '%' . $keyword . '%');
|
||||
$where[] = ['zh_name|en_name|code', 'like', '%' . $keyword . '%'];
|
||||
}
|
||||
if ($isHot !== '' && $isHot !== '-1') {
|
||||
$query->where('is_hot', intval($isHot));
|
||||
$where[] = ['is_hot', '=', intval($isHot)];
|
||||
}
|
||||
if ($partition !== '' && $partition !== '-1') {
|
||||
$query->where('partition', intval($partition));
|
||||
$where[] = ['partition', '=', intval($partition)];
|
||||
}
|
||||
|
||||
$total = (clone $query)->count();
|
||||
$countQuery = Db::name('country');
|
||||
foreach ($where as $w) {
|
||||
$countQuery->where($w[0], $w[1], $w[2]);
|
||||
}
|
||||
$total = $countQuery->count();
|
||||
|
||||
$list = $query
|
||||
$listQuery = Db::name('country');
|
||||
foreach ($where as $w) {
|
||||
$listQuery->where($w[0], $w[1], $w[2]);
|
||||
}
|
||||
$list = $listQuery
|
||||
->order('is_hot desc, zh_name asc')
|
||||
->page($page, $perPage)
|
||||
->select();
|
||||
|
||||
Reference in New Issue
Block a user