HousingestateController.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. $configtuanzhang = Config::getconfig('tuanzhang');
  14. $latitude = input('post.latitude', '', 'serach_in'); //纬度信息
  15. $longitude = input('post.longitude', '', 'serach_in'); //经度信息
  16. if (!empty($longitude) && !empty($latitude)) {
  17. $sql = "select * from (select id,weid,sort,tzid,title,latitude,longitude,province_name,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 asc ) as a where status=1 ";
  18. } else {
  19. $sql = "select * from " . (new HousingEstate)->getTable() . " where status=1 ";
  20. }
  21. $sql .= " and `weid` = " . weid();
  22. if (trim($keyword)) {
  23. $sql .= " and `title` LIKE '%" . $keyword . "%'";
  24. }
  25. if ($configtuanzhang['is_city_housingestate'] == 1) {
  26. if (!empty($this->userInfo['cityinfo']['province_name'])) {
  27. $sql .= " and `province_name` = '" . $this->userInfo['cityinfo']['province_name']."'";
  28. }
  29. if (!empty($this->userInfo['cityinfo']['city_name'])) {
  30. $sql .= " and `city_name` = '" . $this->userInfo['cityinfo']['city_name']."'";
  31. }
  32. if (!empty($this->userInfo['cityinfo']['district_name'])) {
  33. $sql .= " and `district_name` = '" . $this->userInfo['cityinfo']['district_name']."'";
  34. }
  35. }
  36. $data = Db::query($sql);
  37. foreach ($data as &$vo) {
  38. if (!empty($vo['tzid'])) {
  39. $Tuanzhang = Tuanzhang::find($vo['tzid']);
  40. if (!empty($Tuanzhang)) {
  41. $vo['tz_touxiang'] = toimg($Tuanzhang['touxiang']);
  42. $vo['community_title'] = $Tuanzhang['community_title'];
  43. $vo['tz_title'] = $Tuanzhang['title'];
  44. $vo['tz_tel'] = $Tuanzhang['tel'];
  45. }
  46. }
  47. $vo['image'] = toimg($vo['image']);
  48. $vo['distance'] = round(($vo['distance']) / 1000, 1);
  49. }
  50. $res['sql'] = $sql;
  51. $res['data'] = $data;
  52. return $this->json(['data' => $res]);
  53. }
  54. }