HousingestateController.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. namespace app\index\controller;
  3. use think\exception\ValidateException;
  4. use app\model\Config;
  5. use app\model\HousingEstate;
  6. use app\model\Tuanzhang;
  7. use think\facade\Db;
  8. class HousingestateController extends Base
  9. {
  10. public function list()
  11. {
  12. $keyword = input('post.keyword', '', 'serach_in');
  13. $config = Config::getconfig();
  14. $latitude = $this->userInfo['cityinfo']['latitude'];
  15. $longitude = $this->userInfo['cityinfo']['longitude'];
  16. if(empty($latitude)){
  17. $latitude = input('post.latitude', '', 'serach_in'); //纬度信息
  18. }
  19. if(empty($longitude)){
  20. $longitude = input('post.longitude', '', 'serach_in'); //经度信息
  21. }
  22. if (!empty($longitude) && !empty($latitude)) {
  23. $sql = "select * from (select id,weid,sort,tzid,title,city_name,district_name,area_name,house_number,image,status, ROUND(6378.138*2*ASIN(SQRT(POW(SIN(($latitude*PI()/180-`latitude`*PI()/180)/2),2)+COS($latitude*PI()/180)*COS(`latitude`*PI()/180)*POW(SIN(($longitude*PI()/180-`longitude`*PI()/180)/2),2)))*1000) AS distance from " . (new HousingEstate)->getTable() . " order by distance desc ) as a where status=1 ";
  24. } else {
  25. $sql = "select * from " . (new HousingEstate)->getTable() . " where status=1 ";
  26. }
  27. $sql .= " and `weid` = " . weid();
  28. if (trim($keyword)) {
  29. $sql .= " and `title` LIKE '%" . $keyword . "%'";
  30. }
  31. $data = Db::query($sql);
  32. foreach ($data as &$vo) {
  33. if (!empty($vo['tzid'])) {
  34. $Tuanzhang = Tuanzhang::find($vo['tzid']);
  35. if (!empty($Tuanzhang)) {
  36. $vo['tz_touxiang'] = toimg($Tuanzhang['touxiang']);
  37. $vo['community_title'] = $Tuanzhang['community_title'];
  38. $vo['tz_title'] = $Tuanzhang['title'];
  39. $vo['tz_tel'] = $Tuanzhang['tel'];
  40. }
  41. }
  42. $vo['image'] = toimg($vo['image']);
  43. if($vo['distance']){
  44. $vo['distance'] = round(($vo['distance']) / 1000, 1);
  45. }else{
  46. $vo['distance'] = 0.5;
  47. }
  48. }
  49. $res['data'] = $data;
  50. return $this->json(['data' => $res]);
  51. }
  52. }