...
|
...
|
@@ -5,6 +5,7 @@ namespace app\api\controller; |
|
|
use app\api\model\Category;
|
|
|
use app\api\model\Goods;
|
|
|
use app\api\model\News;
|
|
|
use app\api\model\UserSearch;
|
|
|
use app\common\controller\Api;
|
|
|
use think\Config;
|
|
|
use think\Db;
|
...
|
...
|
@@ -246,7 +247,16 @@ class Index extends Api |
|
|
$item['line_price'] = $goods_spec['line_price'];
|
|
|
});
|
|
|
}
|
|
|
Db::name('user_search')->insert(['user_id'=>$this->auth->id,'text'=>$text,'createtime'=>time()]);
|
|
|
// 搜索记录
|
|
|
$search_text = UserSearch::where(['user_id'=>$this->auth->id,'text'=>$text])->find();
|
|
|
if($search_text){
|
|
|
$search_text->save(['updatetime' => time()]);
|
|
|
}else{
|
|
|
UserSearch::create([
|
|
|
'user_id' => $this->auth->id,
|
|
|
'text' => $text
|
|
|
]);
|
|
|
}
|
|
|
$this->success('搜索',$list);
|
|
|
}
|
|
|
|
...
|
...
|
@@ -258,17 +268,15 @@ class Index extends Api |
|
|
* @ApiReturn ({
|
|
|
'code':'1',
|
|
|
'msg':'搜索历史'
|
|
|
'data':{
|
|
|
|
|
|
'data':null
|
|
|
})
|
|
|
*/
|
|
|
public function searchHistory()
|
|
|
{
|
|
|
if ($this->auth->isLogin()){
|
|
|
$list = Db::name('user_search')
|
|
|
->where('user_id',$this->auth->id)
|
|
|
$list = UserSearch::where('user_id',$this->auth->id)
|
|
|
->limit(10)
|
|
|
->order('id','desc')
|
|
|
->order('updatetime','desc')
|
|
|
->column('text');
|
|
|
}else{
|
|
|
$list = [];
|
...
|
...
|
@@ -276,4 +284,19 @@ class Index extends Api |
|
|
$this->success('搜索历史',$list);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @ApiTitle (搜索历史-清空)
|
|
|
* @ApiMethod (POST)
|
|
|
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
|
|
|
* @ApiReturn ({
|
|
|
'code':'1',
|
|
|
'msg':'成功'
|
|
|
'data':null
|
|
|
})
|
|
|
*/
|
|
|
public function searchHistoryClear()
|
|
|
{
|
|
|
UserSearch::where('user_id',$this->auth->id)->delete();
|
|
|
$this->success('成功');
|
|
|
}
|
|
|
} |
...
|
...
|
|