Search.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use think\Db;
  5. use think\Cache;
  6. /**
  7. * 搜索
  8. */
  9. class Search extends Api
  10. {
  11. //
  12. // 无需登录的接口,*表示全部
  13. protected $noNeedLogin = ['*'];
  14. // 无需鉴权的接口,*表示全部
  15. protected $noNeedRight = ['*'];
  16. public function search(){
  17. $page = $this->request->request('page',1); // 分页
  18. $pageNum = $this->request->request('pageNum',10); // 分页
  19. $type = input('type',1);
  20. $keyword = input('keyword','');
  21. if(empty($keyword)){
  22. $this->error('请输入关键词');
  23. }
  24. if($type == 1){
  25. $list = $this->getFate($keyword,$page,$pageNum);
  26. }else{
  27. $list = Db::name('user')->where('nickname','LIKE','%'.$keyword.'%')->page($page,$pageNum)->select();
  28. }
  29. $this->success('success',$list);
  30. }
  31. /**
  32. *
  33. * 获取眼缘视频/影集
  34. */
  35. public function getFate($keyword = '',$page,$pageNum) {
  36. $common_where = [];
  37. $common_where['a.status'] = 1;
  38. $common_where['a.content'] = ['LIKE','%'.$keyword.'%'];
  39. $field = "a.*,u.avatar,u.city_name,u.district_name,u.nickname,u.is_goddess,u.is_auth,vipStatus(u.vip_duetime) as is_vip,
  40. u.age,u.constellation,u.hobby_ids,u.profession,u.declaration,u.lng,u.lat,u.mobile,u.copy_mobile,u.wechat,u.gender,u.profession";
  41. $list = \app\common\model\Eyemargin::getDistanceList($this->auth->lng,$this->auth->lat,$field,$common_where,$this->auth->id,$page,$pageNum);
  42. return $list;
  43. }
  44. }