lizhen_gitee 1 年間 前
コミット
d6a6a95f5e

+ 7 - 3
application/api/controller/Index.php

@@ -59,9 +59,13 @@ class Index extends Api
             $where['d.id'] = ['IN',$my_follow_ids];
         }
         //搜索
-        $keyworld = input('keyworld','');
-        if(!empty($keyworld)){
-            $where['d.nickname|d.goodat|keshi.name'] = ['LIKE','%'.$keyworld.'%'];
+        $keyword = input('keyword','');
+        if(!empty($keyword)){
+            $where['d.nickname|d.goodat|keshi.name'] = ['LIKE','%'.$keyword.'%'];
+
+            if($this->auth->isLogin()){
+                Db::name('user_search')->insertGetId(['user_id'=>$this->auth->id,'keyword'=>$keyword]);
+            }
         }
 
         //dump($where);

+ 36 - 0
application/api/controller/Usercenter.php

@@ -0,0 +1,36 @@
+<?php
+
+namespace app\api\controller;
+
+use app\common\controller\Api;
+use think\Db;
+
+class Usercenter extends Api
+{
+    protected $noNeedLogin = [];
+    protected $noNeedRight = ['*'];
+
+    //我的搜索历史
+    public function search_history(){
+        $list = Db::name('user_search')->where('user_id',$this->auth->id)->order('id desc')->select();
+
+        //只留最近10条
+        if(!empty($list) && count($list) > 10){
+            $list = array_chunk($list,10);
+            $list = $list[0];
+
+            $rs_ids = array_column($list,'id');
+
+            Db::name('user_search')->where('user_id',$this->auth->id)->where('id','NOT IN',$rs_ids)->delete();
+        }
+
+        $this->success(1,$list);
+    }
+
+    //清空搜索历史
+    public function search_clear(){
+        Db::name('user_search')->where('user_id',$this->auth->id)->delete();
+        $this->success(1);
+    }
+
+}