Index.php 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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.longitude',
  76. 'user.latitude',
  77. 'user.attribute',
  78. 'wallet.vip_endtime',
  79. '(st_distance(point (' . $this->auth->longitude . ', ' . $this->auth->latitude . '),point(user.longitude,user.latitude))*111195) as distance',
  80. 'active.requesttime',
  81. ];
  82. $list = Db::name('user')->alias('user')->field($field)
  83. ->join('user_wallet wallet','user.id = wallet.user_id','LEFT')
  84. ->join('user_power power' ,'user.id = power.user_id','LEFT')
  85. ->join('user_active active' ,'user.id = active.user_id','LEFT')
  86. ->where($where)
  87. ->order('distance asc')
  88. ->autopage()
  89. ->select();
  90. $list = list_domain_image($list,['avatar','photo_images']);
  91. foreach($list as $key => &$val){
  92. $val['age'] = birthtime_to_age($val['birthday']);
  93. $val['photo_images'] = explode(',',$val['photo_images'])[0];
  94. $val['is_vip'] = $val['vip_endtime'] > time() ? 1 : 0;
  95. $val['distance'] = bcdiv(intval($val['distance']),1000,2).'km';
  96. $val['active_info'] = $this->user_activeinfo($val['id'],$val['requesttime']);
  97. }
  98. $this->success(1,$list);
  99. }
  100. public function tuijian(){
  101. $cityname = input('cityname',$this->auth->cityname);
  102. $where = [
  103. 'user.id' => ['neq',$this->auth->id],
  104. 'user.status' => 1,
  105. 'user.photo_images' => ['neq',''],
  106. 'user.cityname' => $cityname,
  107. 'power.yinshen' => 0,
  108. ];
  109. //推荐条件
  110. $where_tuijian = [
  111. 'user.idcard_status' => 1,
  112. 'user.is_tuijian' => 1,
  113. ];
  114. if(config('site.index_tuijian_vip_limit') == 1){
  115. $where_tuijian['wallet.vip_endtime'] = ['gt',time()];
  116. }
  117. //推荐条件
  118. $where = array_merge($where,$where_tuijian);
  119. //性别
  120. $gender = input('gender','all');
  121. if($gender != 'all'){
  122. $where['user.gender'] = $gender;
  123. }
  124. //属性
  125. $attribute = input('attribute','all');
  126. if($attribute != 'all' && $attribute != 'BOTH'){
  127. $where['user.attribute'] = $attribute;
  128. }
  129. //排除黑名单的
  130. $black_ids = Db::name('user_black')->where(['uid'=>$this->auth->id])->column('black_uid');
  131. if(!empty($black_ids)){
  132. $where['user.id'] = ['NOTIN',$black_ids];
  133. }
  134. //年龄
  135. $agemin = input('agemin',18);
  136. if($agemin > 18){
  137. $where['user.birthday'] = ['lt',time()-$agemin*31536000];
  138. }
  139. $agemax = input('agemax',100);
  140. if($agemax < 100){
  141. $where['user.birthday'] = ['gt',time()-$agemax*31536000];
  142. }
  143. if($agemin > 18 && $agemax < 100){
  144. $where['user.birthday'] = ['between',[time()-$agemax*31536000,time()-$agemin*31536000]];
  145. }
  146. //距离
  147. $distancemin = input('distancemin',0);
  148. if($distancemin > 0){
  149. $where['distance'] = ['gt',$distancemin];
  150. }
  151. $distancemax = input('distancemax',0);
  152. if($distancemax > 0){
  153. $where['distance'] = ['lt',$distancemax];
  154. }
  155. if($distancemin > 0 && $distancemax > 0){
  156. $where['distance'] = ['between',[$distancemin,$distancemax]];
  157. }
  158. $field = [
  159. 'user.id',
  160. 'user.username',
  161. 'user.nickname',
  162. 'user.avatar',
  163. 'user.photo_images',
  164. 'user.gender',
  165. 'user.birthday',
  166. 'user.cityname',
  167. 'user.longitude',
  168. 'user.latitude',
  169. 'user.attribute',
  170. 'wallet.vip_endtime',
  171. '(st_distance(point (' . $this->auth->longitude . ', ' . $this->auth->latitude . '),point(user.longitude,user.latitude))*111195) as distance',
  172. 'active.requesttime',
  173. ];
  174. $list = Db::name('user')->alias('user')->field($field)
  175. ->join('user_wallet wallet','user.id = wallet.user_id','LEFT')
  176. ->join('user_power power' ,'user.id = power.user_id','LEFT')
  177. ->join('user_active active' ,'user.id = active.user_id','LEFT')
  178. ->where($where)
  179. ->order('distance asc')
  180. ->autopage()
  181. ->select();
  182. $list = list_domain_image($list,['avatar','photo_images']);
  183. foreach($list as $key => &$val){
  184. $val['age'] = birthtime_to_age($val['birthday']);
  185. $val['photo_images'] = explode(',',$val['photo_images'])[0];
  186. $val['is_vip'] = $val['vip_endtime'] > time() ? 1 : 0;
  187. $val['distance'] = bcdiv(intval($val['distance']),1000,2).'km';
  188. $val['active_info'] = $this->user_activeinfo($val['id'],$val['requesttime']);
  189. }
  190. $this->success(1,$list);
  191. }
  192. }