This commit is contained in:
wangjinlei
2026-04-20 10:56:25 +08:00
parent 4417a7ea28
commit d2a6c3ff30
4 changed files with 505 additions and 141 deletions

View File

@@ -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();