Usercenter.php 886 B

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use think\Db;
  5. class Usercenter extends Api
  6. {
  7. protected $noNeedLogin = [];
  8. protected $noNeedRight = ['*'];
  9. //我的搜索历史
  10. public function search_history(){
  11. $list = Db::name('user_search')->where('user_id',$this->auth->id)->order('id desc')->select();
  12. //只留最近10条
  13. if(!empty($list) && count($list) > 10){
  14. $list = array_chunk($list,10);
  15. $list = $list[0];
  16. $rs_ids = array_column($list,'id');
  17. Db::name('user_search')->where('user_id',$this->auth->id)->where('id','NOT IN',$rs_ids)->delete();
  18. }
  19. $this->success(1,$list);
  20. }
  21. //清空搜索历史
  22. public function search_clear(){
  23. Db::name('user_search')->where('user_id',$this->auth->id)->delete();
  24. $this->success();
  25. }
  26. }