Search.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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 = model('user')->field('id,nickname,avatar,age,constellation,profession,gender')->where('nickname','LIKE','%'.$keyword.'%')->page($page,$pageNum)->select();
  28. if ($list) {
  29. $user_fate = Db::name('user_fate');
  30. foreach ($list as &$v) {
  31. $fate_info = $user_fate->where(['user_id' => $this->auth->id, 'fate_user_id' => $v['id'], 'createtime' => ['egt', time() - 86400]])->find();
  32. if ($fate_info) {
  33. $v['is_fate'] = 1;
  34. $v['countdown'] = $fate_info['createtime'] + 86400 - time();
  35. } else {
  36. $v['is_fate'] = 0;
  37. $v['countdown'] = 0; //倒计时时间
  38. }
  39. //是否关注
  40. $follow_info = Db::name('user_follow')->where(['user_id' => $this->auth->id, 'to_user_id' => $v['id']])->find();
  41. if ($follow_info) {
  42. $v['is_follow'] = 1;
  43. } else {
  44. $v['is_follow'] = 0;
  45. }
  46. }
  47. }
  48. }
  49. $this->success('success',$list);
  50. }
  51. /**
  52. *
  53. * 获取眼缘视频/影集
  54. */
  55. public function getFate($keyword = '',$page,$pageNum) {
  56. $common_where = [];
  57. $common_where['a.status'] = 1;
  58. $common_where['a.content'] = ['LIKE','%'.$keyword.'%'];
  59. $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,
  60. 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";
  61. $list = \app\common\model\Eyemargin::getDistanceList($this->auth->lng,$this->auth->lat,$field,$common_where,$this->auth->id,$page,$pageNum);
  62. return $list;
  63. }
  64. }