Index.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use think\Db;
  5. /**
  6. * 首页接口
  7. */
  8. class Index extends Api
  9. {
  10. protected $noNeedLogin = ['index'];
  11. protected $noNeedRight = ['*'];
  12. public function index(){
  13. echo 'apisuccess';
  14. exit;
  15. }
  16. //附近
  17. //是vip,且开启了隐身的,不能在内
  18. public function fujin(){
  19. $cityname = input('cityname',$this->auth->cityname);
  20. $where = [
  21. 'user.id' => ['neq',$this->auth->id],
  22. 'user.status' => 1,
  23. 'user.photo_images' => ['neq',''],
  24. 'user.cityname' => $cityname,
  25. 'power.yinshen' => 0,
  26. ];
  27. //性别
  28. $gender = input('gender','all');
  29. if($gender != 'all'){
  30. $where['user.gender'] = $gender;
  31. }
  32. //属性
  33. $attribute = input('attribute','all');
  34. if($attribute != 'all' && $attribute != 'BOTH'){
  35. $where['user.attribute'] = $attribute;
  36. }
  37. //排除黑名单的
  38. $black_ids = Db::name('user_black')->where(['uid'=>$this->auth->id])->column('black_uid');
  39. if(!empty($black_ids)){
  40. $where['user.id'] = ['NOTIN',$black_ids];
  41. }
  42. //年龄
  43. $agemin = input('agemin',18);
  44. if($agemin > 18){
  45. $where['user.birthday'] = ['lt',time()-$agemin*31536000];
  46. }
  47. $agemax = input('agemax',100);
  48. if($agemax < 100){
  49. $where['user.birthday'] = ['gt',time()-$agemax*31536000];
  50. }
  51. if($agemin > 18 && $agemax < 100){
  52. $where['user.birthday'] = ['between',[time()-$agemax*31536000,time()-$agemin*31536000]];
  53. }
  54. //距离
  55. $distancemin = input('distancemin',0);
  56. if($distancemin > 0){
  57. $where['distance'] = ['gt',$distancemin];
  58. }
  59. $distancemax = input('distancemax',0);
  60. if($distancemax > 0){
  61. $where['distance'] = ['lt',$distancemax];
  62. }
  63. if($distancemin > 0 && $distancemax > 0){
  64. $where['distance'] = ['between',[$distancemin,$distancemax]];
  65. }
  66. $field = [
  67. 'user.id',
  68. 'user.username',
  69. 'user.nickname',
  70. 'user.avatar',
  71. 'user.photo_images',
  72. 'user.gender',
  73. 'user.birthday',
  74. 'user.cityname',
  75. 'user.attribute',
  76. 'user.is_active',
  77. 'user.longitude',
  78. 'user.latitude',
  79. 'user.cityname',
  80. 'user.attribute',
  81. 'wallet.vip_endtime',
  82. '(st_distance(point (' . $this->auth->longitude . ', ' . $this->auth->latitude . '),point(user.longitude,user.latitude))*111195) as distance',
  83. ];
  84. $list = Db::name('user')->alias('user')->field($field)
  85. ->join('user_wallet wallet','user.id = wallet.user_id','LEFT')
  86. ->join('user_power power' ,'user.id = power.user_id','LEFT')
  87. ->where($where)
  88. ->order('distance asc')
  89. ->autopage()
  90. ->select();
  91. $list = list_domain_image($list,['avatar','photo_images']);
  92. foreach($list as $key => &$val){
  93. $val['age'] = birthtime_to_age($val['birthday']);
  94. $val['photo_images'] = explode(',',$val['photo_images'])[0];
  95. $val['is_vip'] = $val['vip_endtime'] > time() ? 1 : 0;
  96. $val['distance'] = bcdiv(intval($val['distance']),1000,2).'km';
  97. }
  98. $this->success(1,$list);
  99. }
  100. public function tuijian(){}
  101. }