$addSql=" left join (select buildproperty_id,house_area,image_id,house_id as bph_id from ".Config::A_DISTRICT_AREA_TABLE.") ada on th.id = ada.bph_id".
" left join (select value as bp_value,literal as bp_literal from ".Config::DIC_BUILDPROPERTY_TABLE.") dbp on ada.buildproperty_id = dbp.bp_value";
$orderbySql=" group by th.id order by th.creattime DESC";
}elseif($array['houseType']==1){
$addSql=" left join (select value as bp_value,literal as bp_literal from ".Config::DIC_BUILDPROPERTY_TABLE.") dbp on if(th.buildproperty_id>5,5,buildproperty_id) = dbp.bp_value";
if($array['feature']>-1){
$addSql.=" left join (select house_id,tag_id from ".Config::A_HOUSE_TAG_TABLE.") aht on th.id = aht.house_id";
$addWhereSql=" and tag_id = ".$array['feature'];
}
$orderbySql=" order by th.creattime DESC";
}elseif($array['houseType']==2){
$addSql=" left join (select value as bp_value,literal as bp_literal from ".Config::DIC_BUILDPROPERTY_TABLE.") dbp on th.buildproperty_id = dbp.bp_value";
"ti.path,dr.literal,th.house_number,dbp.bp_literal,th.owner_name,th.owner_phone,(SELECT GROUP_CONCAT(left(tt.name,3)) from ".Config::A_HOUSE_TAG_TABLE." aht".
" LEFT JOIN ".Config::TOSPUR_TAG_TABLE." tt on tt.id = aht.tag_id".
" where aht.house_id = th.id) as tags from ".Config::TOSPUR_HOUSE_TABLE." th".
$addSql.
" left join ".Config::DIC_CITY_TABLE." dc on th.plate_id = dc.plateId".
" left join (select id as rid,value as r_value,literal from ".Config::DIC_ROOM_TABLE.") dr on th.room_id = dr.r_value".
" left join (select id as image_id,path from ".Config::TOSPUR_IMAGE_TABLE.") ti on ti.image_id = th.frontCover_id".
" where 1=1 and th.status = 1 ";
if($array['cityId']>-1){
$params[]=$array['cityId'];
$sql=$sql." and cityId=%d";
}
if($array['districtId']>-1){
$params[]=$array['districtId'];
$sql=$sql." and districtId=%d";
}
if($array['plateId']>-1){
$params[]=$array['plateId'];
$sql=$sql." and plateId=%d";
}
if($array['buildPropertyId']>-1){
$params[]=$array['buildPropertyId'];
if($array['houseType']==0){
$sql=$sql." and ada.buildproperty_id=%d";
}else{
$sql=$sql." and th.buildproperty_id=%d";
}
}
if($array['roomId']>-1){
$params[]=$array['roomId'];
$sql=$sql." and room_id=%d";
}
if($array['acreage']>-1){
$areaArray=explode("-",$array['acreage']);
$params[]=$areaArray[0];
$params[]=$areaArray[1];
if($array['houseType']==0){
$sql=$sql." and ada.house_area between %d and %d";
}else{
$sql=$sql." and covered_area between %d and %d";
}
}
if($array['unitPrice']>-1){
$priceArray=explode("-",$array['unitPrice']);
$params[]=$priceArray[0];
$params[]=$priceArray[1];
$sql=$sql." and average_price between %d and %d";
}
publicstaticfunctionajax_searchHouse()
{
$house_result=SearchDao::searchHouse(
array(
'cityId'=>$_POST['cityId'],
'districtId'=>$_POST['districtId'],
'plateId'=>$_POST['plateId'],
'buildPropertyId'=>$_POST['buildPropertyId'],
'roomId'=>$_POST['roomId'],
'acreage'=>$_POST['acreage'],
'unitPrice'=>$_POST['unitPrice'],
'totalPrice'=>$_POST['totalPrice'],
'rentalPrice'=>$_POST['rentalPrice'],
'searchText'=>$_POST['searchText'],
'houseType'=>$_POST['houseType'],
'feature'=>$_POST['feature'],
'userType'=>$_POST['userType'],
'userId'=>$_POST['userId'],
'index'=>$_POST['index']
)
);
$array=SearchDao::get_house_list($house_result);
wp_send_json($array);
exit;
}
publicstaticfunctionsearchHouse($array)
{
global$wpdb;
$params=array();
$addSql=null;
$addWhereSql=null;
$orderbySql=null;
if($array['houseType']==0){
$addSql=" left join (select buildproperty_id,house_area,image_id,house_id as bph_id from ".Config::A_DISTRICT_AREA_TABLE.") ada on th.id = ada.bph_id".
" left join (select value as bp_value,literal as bp_literal from ".Config::DIC_BUILDPROPERTY_TABLE.") dbp on ada.buildproperty_id = dbp.bp_value";
$orderbySql=" group by th.id order by th.creattime DESC";
}elseif($array['houseType']==1){
$addSql=" left join (select value as bp_value,literal as bp_literal from ".Config::DIC_BUILDPROPERTY_TABLE.") dbp on th.buildproperty_id = dbp.bp_value";
if($array['feature']>-1){
$addSql.=" left join (select house_id,tag_id from ".Config::A_HOUSE_TAG_TABLE.") aht on th.id = aht.house_id";
$addWhereSql=" and tag_id = ".$array['feature'];
}
$orderbySql=" order by th.creattime DESC";
}elseif($array['houseType']==2){
$addSql=" left join (select value as bp_value,literal as bp_literal from ".Config::DIC_BUILDPROPERTY_TABLE.") dbp on th.buildproperty_id = dbp.bp_value";
"ti.path,dr.literal,th.house_number,dbp.bp_literal,th.owner_name,th.owner_phone,(SELECT GROUP_CONCAT(left(tt.name,3)) from ".Config::A_HOUSE_TAG_TABLE." aht".
" LEFT JOIN ".Config::TOSPUR_TAG_TABLE." tt on tt.id = aht.tag_id".
" where aht.house_id = th.id) as tags from ".Config::TOSPUR_HOUSE_TABLE." th".
$addSql.
" left join ".Config::DIC_CITY_TABLE." dc on th.plate_id = dc.plateId".
" left join (select id as rid,value as r_value,literal from ".Config::DIC_ROOM_TABLE.") dr on th.room_id = dr.r_value".
" left join (select id as image_id,path from ".Config::TOSPUR_IMAGE_TABLE.") ti on ti.image_id = th.frontCover_id".
" where 1=1 and th.status = 1 ";
if($array['cityId']>-1){
$params[]=$array['cityId'];
$sql=$sql." and cityId=%d";
}
if($array['districtId']>-1){
$params[]=$array['districtId'];
$sql=$sql." and districtId=%d";
}
if($array['plateId']>-1){
$params[]=$array['plateId'];
$sql=$sql." and plateId=%d";
}
if($array['buildPropertyId']>-1){
$params[]=$array['buildPropertyId'];
if($array['houseType']==0){
$sql=$sql." and ada.buildproperty_id=%d";
}else{
$sql=$sql." and th.buildproperty_id=%d";
}
}
if($array['roomId']>-1){
$params[]=$array['roomId'];
$sql=$sql." and room_id=%d";
}
if($array['acreage']>-1){
$areaArray=explode("-",$array['acreage']);
$params[]=$areaArray[0];
$params[]=$areaArray[1];
if($array['houseType']==0){
$sql=$sql." and ada.house_area between %d and %d";
}else{
$sql=$sql." and covered_area between %d and %d";
}
}
if($array['unitPrice']>-1){
$priceArray=explode("-",$array['unitPrice']);
$params[]=$priceArray[0];
$params[]=$priceArray[1];
$sql=$sql." and average_price between %d and %d";
}
if($array['totalPrice']>-1){
$priceArray=explode("-",$array['totalPrice']);
$params[]=$priceArray[0];
$params[]=$priceArray[1];
$sql=$sql." and total_price/10000 between %d and %d";
}
if($array['rentalPrice']>-1){
$priceArray=explode("-",$array['rentalPrice']);
$params[]=$priceArray[0];
$params[]=$priceArray[1];
$sql=$sql." and rent between %d and %d";
}
if($array['houseType']>-1){
$params[]=$array['houseType'];
$sql=$sql." and house_type = %d";
}
if($array['userType']>-1&&$array['userId']>-1){
$params[]=$array['userType'];
$params[]=$array['userId'];
$sql=$sql." and id in (select house_id from ".Config::A_HOUSE_USER_TABLE." where user_type = %d and user_id = %d)";
}
if($array['searchText']!=null){
$params[]='%'.$array['searchText'].'%';
$params[]='%'.$array['searchText'].'%';
$sql=$sql." and (name like '%s' or address like '%s')";