Browse Source

[更新]代码优化

邹景立 8 years ago
parent
commit
aa218c9135
2 changed files with 8 additions and 7 deletions
  1. 4 5
      application/admin/controller/User.php
  2. 4 2
      application/wechat/controller/Fans.php

+ 4 - 5
application/admin/controller/User.php

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

+ 4 - 2
application/wechat/controller/Fans.php

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