[更新]代码优化

This commit is contained in:
邹景立 2017-04-22 13:44:45 +08:00
parent f4753695d4
commit aa218c9135
2 changed files with 8 additions and 7 deletions

View File

@ -44,11 +44,10 @@ class User extends BasicAdmin {
// 实例Query对象
$db = Db::name($this->table)->where('is_deleted', '0');
// 应用搜索条件
if (isset($get['username']) && $get['username'] !== '') {
$db->where('username', 'like', "%{$get['username']}%");
}
if (isset($get['phone']) && $get['phone'] !== '') {
$db->where('phone', 'like', "%{$get['phone']}%");
foreach (['username', 'phone'] as $key) {
if (isset($get[$key]) && $get[$key] !== '') {
$db->where($key, 'like', "%{$get[$key]}%");
}
}
// 实例化并显示
parent::_list($db);

View File

@ -42,8 +42,10 @@ class Fans extends BasicAdmin {
$this->title = '微信粉丝管理';
$db = Db::name($this->table);
$get = $this->request->get();
if (isset($get['nickname']) && $get['nickname'] !== '') {
$db->where('nickname', 'like', "%{$get['nickname']}%");
foreach (['nickname'] as $key) {
if (isset($get[$key]) && $get[$key] !== '') {
$db->where($key, 'like', "%{$get[$key]}%");
}
}
return parent::_list($db);
}