Commit 96b6d393 authored by zw's avatar zw

地图找房

parent aeec4442
......@@ -3,7 +3,9 @@
namespace app\api_broker\controller;
use app\api_broker\extend\Basic;
use app\model\GBusinessDistrict;
use app\model\GHouses;
use app\model\Regions;
use think\Request;
/**
......@@ -16,11 +18,13 @@ use think\Request;
class MapFindHouse extends Basic
{
private $gHousesModel;
private $regionsModel;
public function __construct(Request $request = null)
{
parent::__construct($request);
$this->gHousesModel = new GHouses();
$this->regionsModel = new Regions();
}
/**
......@@ -42,41 +46,59 @@ class MapFindHouse extends Basic
if (true !== $checkResult) {
return $this->response("101", $checkResult);
}
$first_spot_arr = explode(",",$params["first_spot"]);
$second_spot_arr = explode(",",$params["second_spot"] );
$first_spot_arr = explode(",", $params["first_spot"]);
$second_spot_arr = explode(",", $params["second_spot"]);
if (count($first_spot_arr) < 2 || count($second_spot_arr) < 2) {
return $this->response("101", "坐标传入有误1");
}
$conditions = [];
$conditions["latitude"] = array("between", array($second_spot_arr[0],$first_spot_arr[0]));
$conditions["longitude"] = array("between", array($second_spot_arr[1],$first_spot_arr[1]));
$conditions["latitude"] = array("between", array($second_spot_arr[0], $first_spot_arr[0]));
$conditions["longitude"] = array("between", array($second_spot_arr[1], $first_spot_arr[1]));
$field = "id,internal_title,longitude,latitude";
$result = $this->gHousesModel->getHousesListByMap($field, $conditions);
return $this->response("200", "success", $result);
}
public function getCityInfoByMap(){
public function getCityInfoByMap()
{
$params = $this->params;
/* $params = array(
"spot" => "1223,1213123",
"grade" => 1,//1 区,2商圈,3街道
"source" => 1,//来源 1b端,2c端
"city" => "上海市"//传城市就好了
);*/
/* $params = array(
"spot" => "1223,1213123",
"grade" => 2,//1 区,2商圈,3街道
"source" => 1,//来源 1b端,2c端
"city" => "上海市"//传城市就好了
);*/
$checkResult = $this->validate($params, "MapFindHouseValidate.getCityInfoByMap");
if (true !== $checkResult) {
return $this->response("101", $checkResult);
}
$conditions = [];
if($params["grade"] == 1){
$result = [];
$result["grade"] = $params["grade"];
}elseif ($params["grade"] == 2){
$disc = $this->regionsModel->getDiscByCity($params["city"]);
$disc_str = "";
foreach ($disc as $item) {
$disc_str .= $item["name"] . ",";
}
$disc_str = rtrim($disc_str, ",");
if ($params["grade"] == 1) {
$shop_arr = $this->gHousesModel->getHouseNumByDisc($disc_str);
foreach ($disc as $key => $item) {
foreach ($shop_arr as $i => $j) {
if ($item["name"] == $j["disc"]) {
$disc[$key]["num"] = $j["num"];
}
}
$field = "id,internal_title,longitude,latitude";
$result = $this->gHousesModel->getHousesListByMap($field, $conditions);
}
}
$result["list"] = $disc;
} elseif ($params["grade"] == 2) {
$businessModel = new GBusinessDistrict();
$result["list"] = $businessModel->getListByMap($params["city"]);
}
return $this->response("200", "success", $result);
}
......
......@@ -34,4 +34,11 @@ class GBusinessDistrict extends BaseModel
return $result;
}
public function getListByMap($city){
$sql = "select a.id,a.`name`,a.longitude,a.latitude,count(b.id) as num
from g_business_district as a left join g_houses as b on b.business_district_id=a.id
where a.city='".$city."' and a.longitude <> '' GROUP BY b.business_district_id HAVING num > 0";
return $this->query($sql);
}
}
......@@ -1583,4 +1583,23 @@ class GHouses extends BaseModel
return $result;
}
/**
* @param $disc_str
* @return false|\PDOStatement|string|\think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getHouseNumByDisc($disc_str){
$params["a.disc"] = array("in",$disc_str);
$result = Db::table($this->table)
->field("a.id,a.disc,count(1) as num")
->alias("a")
->where($params)
->group("a.disc")
->select();
//echo $this->getLastSql();
return $result;
}
}
......@@ -2,6 +2,7 @@
namespace app\model;
use think\Db;
use think\Model;
class Regions extends Model
......@@ -117,6 +118,8 @@ class Regions extends Model
}
return $data;
}
/**
* 根据区code获取省市区中文
*
......@@ -134,4 +137,12 @@ class Regions extends Model
$data = $province['fullName'] .'-'.$city['fullName'] .'-'.$disc['fullName'];
return $data;
}
public function getDiscByCity($city){
$sql = "select fullName as name,longitude,latitude,code as id from regions
where parentCode = (select code from regions where fullName='".$city."' and type =2) ";
return $this->query($sql);
}
}
......@@ -521,6 +521,7 @@ Route::group('broker', [
//商铺
'getShopList' => [ 'api_broker/Shop/getShopList', [ 'method' => 'get|post' ] ],
'getShopListByMap' => [ 'api_broker/MapFindHouse/getShopListByMap', [ 'method' => 'get|post' ] ],
'getCityInfoByMap' => [ 'api_broker/MapFindHouse/getCityInfoByMap', [ 'method' => 'get|post' ] ],
'getShopDetail' => [ 'api_broker/Shop/getShopDetail', [ 'method' => 'get' ] ],
'addShopFollowUp' => [ 'api_broker/Shop/addShopFollowUp', [ 'method' => 'post' ] ], //新增商铺跟进记录
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment