Browse Source

首页搜索用户

lizhen_gitee 11 months ago
parent
commit
e34fb0b634
1 changed files with 20 additions and 0 deletions
  1. 20 0
      application/api/controller/Index.php

+ 20 - 0
application/api/controller/Index.php

@@ -134,6 +134,26 @@ class Index extends Api
         $this->success(1,$list);
     }
 
+    //首页搜索
+    public function search_user(){
+        $keyword = input('keyword','');
+        if(empty($keyword)){
+            $this->error();
+        }
+
+        $where = [];
+        if(is_numeric($keyword)){
+            $where['username'] = intval($keyword);
+        }else{
+            $where['nickname'] = ['LIKE','%'.trim($keyword).'%'];
+        }
+
+        $list = Db::name('user')->field('id,username,nickname,gender,avatar')->where($where)->limit(100)->select();
+        $list = list_domain_image($list,['avatar']);
+
+        $this->success(1,$list);
+    }
+