Search.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. }
  41. }
  42. $this->success('success',$list);
  43. }
  44. /**
  45. *
  46. * 获取眼缘视频/影集
  47. */
  48. public function getFate($keyword = '',$page,$pageNum) {
  49. $common_where = [];
  50. $common_where['a.status'] = 1;
  51. $common_where['a.content'] = ['LIKE','%'.$keyword.'%'];
  52. $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,
  53. 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";
  54. $list = \app\common\model\Eyemargin::getDistanceList($this->auth->lng,$this->auth->lat,$field,$common_where,$this->auth->id,$page,$pageNum);
  55. return $list;
  56. }
  57. }