Commit 4aa30a4b by felix

合并用

parent 4be24ca1
<?php <?php
require_once(PLUGIN_DIR . 'Dao/SearchDao.php');
class House { class House {
public static function init_view(){ public static function init_view(){
wp_enqueue_script('jquery-ui'); wp_enqueue_script('jquery-ui');
...@@ -11,33 +12,10 @@ class House { ...@@ -11,33 +12,10 @@ class House {
}else{ }else{
global $wpdb; global $wpdb;
$context = array(); $context = array();
$citysql ="select DISTINCT cityId,cityName from"; $context["city"] = SearchDao::searchCity();
$cityRes = $wpdb->get_results($citysql.' dic_city'); $context["buildProperty"] = SearchDao::searchBuildProperty();
foreach($cityRes as $value){ $context["room"] = SearchDao::searchRoom();
$cityParams = array( $context["photoType"] = SearchDao::searchPhotoType();
"cityId" => $value->cityId,
"cityName" => $value->cityName
);
$context["city"][] = $cityParams;
}
$sql = "select * from";
$buildpropertyRes = $wpdb->get_results($sql.' dic_buildproperty');
foreach($buildpropertyRes as $v){
$buildpropertyParams = array(
"value" => $v->value,
"literal" => $v->literal
);
$context["buildproperty"] []= $buildpropertyParams;
}
$buildpropertyRes = $wpdb->get_results($sql.' dic_room');
foreach($buildpropertyRes as $v){
$roomParams = array(
"value" => $v->value,
"literal" => $v->literal
);
$context["room"] []= $roomParams;
}
House::data_insert(); House::data_insert();
Timber::render("newhouse.html",$context); Timber::render("newhouse.html",$context);
} }
...@@ -70,79 +48,82 @@ class House { ...@@ -70,79 +48,82 @@ class House {
'parking_spaces' => $_POST['parking_spaces'], 'parking_spaces' => $_POST['parking_spaces'],
'property_management' => $_POST['property_management'], 'property_management' => $_POST['property_management'],
'overview' => $_POST['overview'], 'overview' => $_POST['overview'],
'plate_id'=>$_POST["basePlateId"], 'city_id' => $_POST['baseCity'],
"room_id"=>$_POST["baseRoom"], 'district_id' => $_POST['baseAreaId'],
"property_money" =>$_POST["property_money"], 'plate_id' => $_POST["basePlateId"],
'creattime'=>date("Y-m-d H:i:s") "room_id" => $_POST["baseRoom"],
"property_money" => $_POST["property_money"],
'creattime' => date("Y-m-d H:i:s"),
'user_id' => get_current_user_id()
); );
$res = $wpdb->get_results( 'SELECT * FROM tospur_house WHERE name="'.$_POST['name'].'" and address="'.$_POST['address'].'"', OBJECT ); $res = $wpdb->get_results('SELECT * FROM tospur_house WHERE name="' . $_POST['name'] . '" and address="' . $_POST['address'] . '"', OBJECT);
if(!$res){ if (!$res) {
$houseRes = $wpdb->insert('tospur_house', $insert_tospur_house_array); $houseRes = $wpdb->insert('tospur_house', $insert_tospur_house_array);
if(!$houseRes){ if (!$houseRes) {
return 500; return 500;
} }
$houseid = $wpdb->insert_id; $houseid = $wpdb->insert_id;
} }
for ($x=0; $x<=count($uploadedfile["name"])-1; $x++) { //主力房源的图片与房子信息关联插入数据库
foreach($uploadedfile["name"] as $key=> $value) {
$uploadParam = array( $uploadParam = array(
"name"=>$uploadedfile["name"]["$x"], "name" => $uploadedfile["name"][$key],
"type"=>$uploadedfile["type"]["$x"], "type" => $uploadedfile["type"][$key],
"tmp_name"=>$uploadedfile["tmp_name"]["$x"], "tmp_name" => $uploadedfile["tmp_name"][$key],
"error"=>$uploadedfile["error"]["$x"], "error" => $uploadedfile["error"][$key],
"size"=>$uploadedfile["size"]["$x"] "size" => $uploadedfile["size"][$key]
); );
//因为file提交过来有一个空的数组,所以这里判断在filename不为空的情况下,再做后续操作 //因为file提交过来有一个空的数组,所以这里判断在filename不为空的情况下,再做后续操作
if($uploadParam["name"]!=""){ if ($uploadParam["name"] != "") {
//从wp_options中获取地址域名
$results = $wpdb->get_row( 'SELECT * FROM wp_options WHERE option_name = "home"', OBJECT );
$patharray = explode("/", $results->option_value);
$path = "/".$patharray[3]."/wp-content/uploads/2015/08/".$uploadParam['name'];
//上传图片 //上传图片
if (!function_exists('wp_handle_upload')){ if (!function_exists('wp_handle_upload')) {
require_once(ABSPATH.'wp-admin/includes/file.php'); require_once(ABSPATH . 'wp-admin/includes/file.php');
} }
$overrides = array( 'test_form' => false); $overrides = array('test_form' => false);
$movefile = wp_handle_upload($uploadParam,$overrides); $movefile = wp_handle_upload($uploadParam, $overrides);
if ( $movefile && !isset( $movefile['error'] ) ) { $str = preg_replace('#^https?://#', '', $movefile["url"]);
$length = strpos($str, "/",strpos($str, "/")+1);
$url = substr($str,$length);
if ($movefile && !isset($movefile['error'])) {
//上传成功后将图片信息存入tospur_image表 //上传成功后将图片信息存入tospur_image表
$insert_image_array = array( $insert_image_array = array(
'name' => $uploadParam['name'], 'name' => $uploadParam["name"],
'path' => $path, 'path' => $url,
'creattime' => date("Y-m-d H:i:s"), 'creattime' => date("Y-m-d H:i:s"),
'alt' => "", 'alt' => "",
'image_type' =>$uploadParam['type'] 'image_type' =>$data[$key]["type"]
); );
//插入图片表 //插入图片表
$imgRes = $wpdb->insert('tospur_image', $insert_image_array); $imgRes = $wpdb->insert('tospur_image', $insert_image_array);
if(!$imgRes){ if (!$imgRes) {
return 501; return 501;
} }
//获取插入图片的id //获取插入图片的id
$imgid = $wpdb->insert_id; $imgid = $wpdb->insert_id;
//echo "File is valid, and was successfully uploaded.\n"; //房源类型、面积与图片关联表
if($data[$key]["type"] == "0"){
$houseTypeArea = array(
'house_id' => $houseid,
"buildproperty_id" => $data["$key"]["buildProperty"],
"house_area" => $data["$key"]["housearea"],
"image_id" => $imgid
);
$houseTypeAreaRes = $wpdb->insert('a_district_area', $houseTypeArea);
if (!$houseTypeAreaRes) {
return 502;
}
}
//将房源id与图片id储存到关联表中
$house_img_array = array(
'house_id' => $houseid,
'image_id' => $imgid,
);
$houseImgRes = $wpdb->insert('a_house_image', $house_img_array);
if (!$houseImgRes) {
return 503;
}
} else { } else {
echo $movefile['error']; return $movefile['error'];
}
//房源类型、面积与图片关联表
$houseTypeArea = array(
'house_id' =>$houseid,
"buildproperty_id" => $data["$x"]["buildproperty"],
"house_area" => $data["$x"]["housearea"],
"image_id" =>$imgid
);
$houseTypeAreaRes = $wpdb->insert('a_district_area', $houseTypeArea);
if(!$houseTypeAreaRes){
return 502;
}
//将房源id与图片id储存到关联表中
$house_img_array = array(
'house_id' =>$houseid,
'image_id'=>$imgid
);
$houseImgRes = $wpdb->insert('a_house_image', $house_img_array);
if(!$houseImgRes){
return 503;
} }
} }
} }
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
最新动态:<textarea rows="3" cols="20" name="event"></textarea><br><br> 最新动态:<textarea rows="3" cols="20" name="event"></textarea><br><br>
<div id="preview"> <div id="preview">
<span>主力户型:</span> <span>主力户型:</span>
<input type="file" name="files[]" property="-1" class = "files"multiple class="browser button button-hero"> <input type="file" name="files[0]" property="0" class = "files"multiple class="browser button button-hero">
<P></P> <P></P>
</div> </div>
<br><br> <br><br>
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
<select id="baseCity" name="baseCity"> <select id="baseCity" name="baseCity">
<option value=""> 城市</option> <option value=""> 城市</option>
{% for item in city %} {% for item in city %}
<option value="{{ item.cityId }}">{{ item.cityName }}</option> <option value="{{ item.id }}">{{ item.value }}</option>
{% endfor %} {% endfor %}
</select> </select>
<select id="baseAreaId" name="baseAreaId"> <select id="baseAreaId" name="baseAreaId">
...@@ -35,7 +35,7 @@ ...@@ -35,7 +35,7 @@
<select id="baseRoom" name="baseRoom"> <select id="baseRoom" name="baseRoom">
<option value = "">建筑类型</option> <option value = "">建筑类型</option>
{% for item in room %} {% for item in room %}
<option value="{{ item.value }}">{{ item.literal }}</option> <option value="{{ item.id }}">{{ item.value }}</option>
{% endfor %} {% endfor %}
</select> </select>
</p> </p>
...@@ -58,6 +58,11 @@ ...@@ -58,6 +58,11 @@
<input type="text" name="type" value="1" hidden="hidden"> <input type="text" name="type" value="1" hidden="hidden">
</div> </div>
<div>
房源相册: <input type="button" value="新增" id="housePicture" class="button action">
<div id="picList"></div>
</div>
<input type="submit" id="submit" class="button action"> <input type="submit" id="submit" class="button action">
</form> </form>
<!-- Button trigger modal --> <!-- Button trigger modal -->
...@@ -73,34 +78,34 @@ ...@@ -73,34 +78,34 @@
<div class="modal-body" style="height: 300px;overflow: auto;"> <div class="modal-body" style="height: 300px;overflow: auto;">
<select id="cityId"> <select id="cityId">
<option value=""> 城市</option> <option value="0"> 城市</option>
{% for item in city %} {% for item in city %}
<option value="{{ item.cityId }}">{{ item.cityName }}</option> <option value="{{ item.id }}">{{ item.value }}</option>
{% endfor %} {% endfor %}
</select> </select>
<select id="areaId"> <select id="areaId">
<option value = "">区域</option> <option value = "0">区域</option>
</select> </select>
<select id="plateId"> <select id="plateId">
<option value = "">板块</option> <option value = "0">板块</option>
</select> </select>
<select id="price"> <select id="price">
<option value = "">价格</option> <option value = "0">价格</option>
</select> </select>
<select id="buildproperty"> <select id="buildProperty">
<option value = "">房型</option> <option value = "0">房型</option>
{% for item in buildproperty %} {% for item in buildProperty %}
<option value="{{ item.value }}">{{ item.literal }}</option> <option value="{{ item.id }}">{{ item.value }}</option>
{% endfor %} {% endfor %}
</select> </select>
<select id="room"> <select id="room">
<option value = "">类型</option> <option value = "0">类型</option>
{% for item in room %} {% for item in room %}
<option value="{{ item.value }}">{{ item.literal }}</option> <option value="{{ item.id }}">{{ item.value }}</option>
{% endfor %} {% endfor %}
</select> </select>
<select id="roomarea"> <select id="acreage">
<option value = "">面积</option> <option value = "0">面积</option>
</select> </select>
<input type="text" placeholder="请出入楼盘名/地段名搜索" id="searchtext"> <input type="text" placeholder="请出入楼盘名/地段名搜索" id="searchtext">
<button type="button" class="button action" id="search">搜索</button> <button type="button" class="button action" id="search">搜索</button>
...@@ -111,13 +116,6 @@ ...@@ -111,13 +116,6 @@
</div> </div>
</div> </div>
<div>
房源相册:
<div id="picList"></div>
<div>
<input type="button" value="新增" id="housePicture" class="button action">
</div>
</div>
<script> <script>
(function($){ (function($){
...@@ -125,6 +123,7 @@ ...@@ -125,6 +123,7 @@
//主力房源中选择图片file的下标 //主力房源中选择图片file的下标
var i = 0; var i = 0;
//房源相册的下标
//入住时间选择 //入住时间选择
$("#checkin").datepicker({ $("#checkin").datepicker({
...@@ -181,12 +180,12 @@ ...@@ -181,12 +180,12 @@
$("#cityId").change(function(){ $("#cityId").change(function(){
var cityId = $(this).val(); var cityId = $(this).val();
var area = $("#areaId"); var area = $("#areaId");
var roomarea =$("#roomarea"); var acreage =$("#acreage");
var price = $("#price"); var price = $("#price");
$('#areaId').find('option:not(:first-child)').remove(); $('#areaId').find('option:not(:first-child)').remove();
$('#plateId').find('option:not(:first-child)').remove(); $('#plateId').find('option:not(:first-child)').remove();
$('#price').find('option:not(:first-child)').remove(); $('#price').find('option:not(:first-child)').remove();
$('#roomarea').find('option:not(:first-child)').remove(); $('#acreage').find('option:not(:first-child)').remove();
$("#houseList").find("li").remove(); $("#houseList").find("li").remove();
//城市联动区域 //城市联动区域
...@@ -204,7 +203,7 @@ ...@@ -204,7 +203,7 @@
url: "/tospur/wp-admin/admin-ajax.php", url: "/tospur/wp-admin/admin-ajax.php",
data: "action=searchArea&cityId="+cityId, data: "action=searchArea&cityId="+cityId,
success:function(json){ success:function(json){
addOption(json,roomarea); addOption(json,acreage);
} }
}); });
//城市联动房子价格 //城市联动房子价格
...@@ -236,19 +235,19 @@ ...@@ -236,19 +235,19 @@
}); });
//推荐房源下显示图片信息以及房名 //推荐房源下显示图片信息以及房名
$("#cityId,#areaId,#plateId,#buildproperty,#room,#roomarea,#price").change(function(){ $("#cityId,#areaId,#plateId,#buildProperty,#room,#acreage,#price").change(function(){
$("#houseList").find("li").remove(); $("#houseList").find("li").remove();
var buildpropertyId = $("#buildproperty").val(); var buildPropertyId = $("#buildProperty").val();
var room = $("#room").val(); var room = $("#room").val();
var areaId = $("#areaId").val(); var areaId = $("#areaId").val();
var cityId = $("#cityId").val(); var cityId = $("#cityId").val();
var plateId = $("#plateId").val(); var plateId = $("#plateId").val();
var area = $("#roomarea").find("option:selected").text(); var acreage = $("#acreage").val();
var price = $("#price").find("option:selected").text(); var price = $("#price").val();
$.ajax({ $.ajax({
type: "GET", type: "GET",
url: "/tospur/wp-admin/admin-ajax.php", url: "/tospur/wp-admin/admin-ajax.php",
data: "action=searchHouse&cityId="+cityId+"&districtId="+areaId+"&plateId="+plateId+"&buildpropertyId="+buildpropertyId+"&roomId="+room+"&acreage="+area+"&totalPrice="+price, data: "action=searchHouse&cityId="+cityId+"&districtId="+areaId+"&plateId="+plateId+"&buildPropertyId="+buildPropertyId+"&roomId="+room+"&acreage="+acreage+"&totalPrice="+price,
success:function(json){ success:function(json){
for( for(
var i = 0; i <=json.length-1; i++){ var i = 0; i <=json.length-1; i++){
...@@ -296,20 +295,28 @@ ...@@ -296,20 +295,28 @@
}); });
$("#housePicture").click(function(){ $("#housePicture").click(function(){
var fileId = i;
var picDelet = $("<font>").append("删除").addClass("picDelet"); var picDelet = $("<font>").append("删除").addClass("picDelet");
var file = $("<input>").attr({"type":"file","id":fileId}).addClass("picFiles"); var file = $("<input>").attr({"type":"file","name":"files["+i+"]"}).addClass("picFiles");
var select = $("<select>"); var select = $("<select>").attr("name","data["+i+"][type]");
{% for item in photoType %}
select.append($("<option>").attr("value",{{item.id}}).append('{{item.value}}'));
{% endfor%}
var p = $("<p>").append(select).append(file).append(picDelet); var p = $("<p>").append(select).append(file).append(picDelet);
$("#picList").append(p); $("#picList").append(p);
i++; i++
}); });
//房源相册
$("#picList").on("change",".picFiles",function(){ $("#picList").on("change",".picFiles",function(){
readURL(this,2); readURL(this,2);
$(this).hide(); $(this).hide();
}); });
$("#picList").on("click",".picDelet",function(){
$(this).parent("p").remove();
})
$("#submit").click(function(){ $("#submit").click(function(){
if($("#housename").val()==""){ if($("#housename").val()==""){
...@@ -321,38 +328,31 @@ ...@@ -321,38 +328,31 @@
//file上传之前,显示图片的方法 //file上传之前,显示图片的方法
function readURL(input,type) { function readURL(input,type) {
if(type == 1){ if(type == 1){
var index = i;
if (input.files && input.files[0]){ if (input.files && input.files[0]){
var reader = new FileReader(); var reader = new FileReader();
reader.onload = function (e) { reader.onload = function (e) {
var img = $("<img>").attr({"id":"target","src":e.target.result,"heghit":100,"width":100}); var img = $("<img>").attr({"id":"target","src":e.target.result,"heghit":100,"width":100});
var button = $("<input>").attr({"type":"button","value":"取消","property":+index-1,"id":+index}).addClass("cancel"); var button = $("<input>").attr({"type":"button","value":"取消","property":+i,"id":+i}).addClass("cancel");
var option = $("<option>").attr({"value":""}).append("户型"); var type = $("<input>").attr({"type":"hidden","name":"data["+i+"][type]","value":0,"property":+i});
var file = $("<input>").attr({"type":"file","name":"files[]","property":+index}).addClass("files"); var file = $("<input>").attr({"type":"file","name":"files["+(i+1)+"]","property":+(i+1)}).addClass("files");
var select = $("<select>").attr({"id":"buildproperty","name":"data["+index+"][buildproperty]"}).append(option).addClass("regular-text"); var select = $("<select>").attr({"name":"data["+i+"][buildProperty]"});
var areatext = $("<input>").attr({"type":"text","placeholder":"面积","name":"data["+index+"][housearea]"}).addClass("regular-text"); {% for item in buildProperty %}
var div = $("<div>").append(select).append(areatext).append(button); select.append($("<option>").attr("value",{{item.id}}).append('{{item.value}}'));
var span = $("<span>").attr({"property":+index-1}).append(img).append(div); {% endfor%}
$.ajax({ var areatext = $("<input>").attr({"type":"text","placeholder":"面积","name":"data["+i+"][housearea]"}).addClass("regular-text");
type: "GET", var div = $("<div>").append(select).append(areatext).append(button).append(type);
url: "/tospur/wp-admin/admin-ajax.php", var span = $("<span>").attr({"property":+i}).append(img).append(div);
data: "action=searchBuildProperty",
success:function(json){
addOption(json,select)
}
});
$("form").find("#preview > p").before(file); $("form").find("#preview > p").before(file);
$("#preview > p").append(span); $("#preview > p").append(span);
i++; i++;
} }
} }
}else{ }else{
var picId = i;
if (input.files && input.files[0]){ if (input.files && input.files[0]){
var reader = new FileReader(); var reader = new FileReader();
reader.onload = function (e){ reader.onload = function (e){
var img = $("<img>").attr({"src":e.target.result,"heghit":100,"width":100,"id":picId}); var img = $("<img>").attr({"src":e.target.result,"heghit":100,"width":100});
$("#picList > p").find("input").before(img); $(input).before(img);
} }
} }
} }
...@@ -361,9 +361,13 @@ ...@@ -361,9 +361,13 @@
function addOption(json,select){ function addOption(json,select){
var selectId = select.attr("id");
for(var i = 0; i <=json.length-1; i++){ for(var i = 0; i <=json.length-1; i++){
var id = json[i]["id"]; var id = json[i]["id"];
var value = json[i]["value"]; var value = json[i]["value"];
if(selectId == "acreage" || selectId == "price"){
id = value;
}
var Option = $("<option>").attr({"value": id}).append(value); var Option = $("<option>").attr({"value": id}).append(value);
select.append(Option); select.append(Option);
} }
......
<?php
class Config {
//table name
const DIC_CITY_TABLE = 'dic_city';
const DIC_ROOM_TABLE = 'dic_room';
const DIC_BUILDPROPERTY_TABLE = 'dic_buildproperty';
const DIC_AREA_TABLE = 'dic_area';
const DIC_UNITPRICERANGE_TABLE = 'dic_unitpricerange';
const DIC_TOTALPRICE_TABLE = 'dic_totalprice';
const DIC_PHOTOTYPE_TABLE = "dic_phototype";
const TOSPUR_ORGANIZATION_TABLE = 'tospur_organization';
const TOSPUR_CONSULTANT = 'tospur_consultant';
//sync url
const user_url = 'http://218.1.67.130:8988/api/NanTongWechat/GetPropertyConsultant?cityId=1';
const other_url = 'http://218.1.67.130:8988/api/NanTongWechat/GetCommonPlate?radomPla=123456';
const organization_url = 'http://218.1.67.130:8988/api/NanTongWechat/GetOrgnaziTion?radomOrg=123456';
}
\ No newline at end of file
<?php <?php
class SearchDao{ class SearchDao{
public function __construct() {
require_once(PLUGIN_DIR . '\TCSync.php');
}
public static function ajax_serachCity(){ public static function ajax_serachCity(){
wp_send_json(SearchDao::searchCity($_GET["cityId"],$_GET['districtId'])); wp_send_json(SearchDao::searchCity($_GET["cityId"],$_GET['districtId']));
} }
...@@ -26,7 +22,7 @@ class SearchDao{ ...@@ -26,7 +22,7 @@ class SearchDao{
$params[] = $districtId; $params[] = $districtId;
$groupBy = ""; $groupBy = "";
} }
$result = $wpdb->get_results($wpdb->prepare('select '.$selectName.' from '.TCSync::DIC_CITY_TABLE.$where.$groupBy,$params)); $result = $wpdb->get_results($wpdb->prepare('select '.$selectName.' from '.Config::DIC_CITY_TABLE.$where.$groupBy,$params));
return $result; return $result;
} }
...@@ -40,7 +36,7 @@ class SearchDao{ ...@@ -40,7 +36,7 @@ class SearchDao{
if(isset($_GET['cityId'])){ if(isset($_GET['cityId'])){
$where .= " and cityId = %d"; $where .= " and cityId = %d";
} }
$result = $wpdb->get_results($wpdb->prepare('select id,priceValue as value from '.TCSync::DIC_AREA_TABLE.$where,$cityId)); $result = $wpdb->get_results($wpdb->prepare('select id,priceValue as value from '.Config::DIC_AREA_TABLE.$where,$cityId));
return $result; return $result;
} }
...@@ -50,7 +46,7 @@ class SearchDao{ ...@@ -50,7 +46,7 @@ class SearchDao{
public static function searchBuildProperty(){ public static function searchBuildProperty(){
global $wpdb; global $wpdb;
$result = $wpdb->get_results('select value as id,literal as value from '.TCSync::DIC_BUILDPROPERTY_TABLE); $result = $wpdb->get_results('select value as id,literal as value from '.Config::DIC_BUILDPROPERTY_TABLE);
return $result; return $result;
} }
...@@ -60,7 +56,7 @@ class SearchDao{ ...@@ -60,7 +56,7 @@ class SearchDao{
public static function searchRoom(){ public static function searchRoom(){
global $wpdb; global $wpdb;
$result = $wpdb->get_results('select value as id,literal as value from '.TCSync::DIC_ROOM_TABLE); $result = $wpdb->get_results('select value as id,literal as value from '.Config::DIC_ROOM_TABLE);
return $result; return $result;
} }
...@@ -74,7 +70,7 @@ class SearchDao{ ...@@ -74,7 +70,7 @@ class SearchDao{
if(isset($_GET['cityId'])){ if(isset($_GET['cityId'])){
$where .= " and cityId = %d"; $where .= " and cityId = %d";
} }
$result = $wpdb->get_results($wpdb->prepare('select id,priceValue as value from '.TCSync::DIC_UNITPRICERANGE_TABLE.$where,$cityId)); $result = $wpdb->get_results($wpdb->prepare('select id,priceValue as value from '.Config::DIC_UNITPRICERANGE_TABLE.$where,$cityId));
return $result; return $result;
} }
...@@ -88,7 +84,7 @@ class SearchDao{ ...@@ -88,7 +84,7 @@ class SearchDao{
if(isset($_GET['cityId'])){ if(isset($_GET['cityId'])){
$where .= " and cityId = ".$cityId; $where .= " and cityId = ".$cityId;
} }
$result = $wpdb->get_results($wpdb->prepare('select id,priceValue as value from '.TCSync::DIC_TOTALPRICE_TABLE.$where,$cityId)); $result = $wpdb->get_results($wpdb->prepare('select id,priceValue as value from '.Config::DIC_TOTALPRICE_TABLE.$where,$cityId));
return $result; return $result;
} }
...@@ -102,13 +98,13 @@ class SearchDao{ ...@@ -102,13 +98,13 @@ class SearchDao{
if($parentId != NULL){ if($parentId != NULL){
$where .= " and ParentId =".$parentId; $where .= " and ParentId =".$parentId;
} }
$result = $wpdb->get_results($wpdb->prepare('select Id as id,Name as name from '.TCSync::TOSPUR_ORGANIZATION_TABLE.$where,$parentId)); $result = $wpdb->get_results($wpdb->prepare('select Id as id,Name as name from '.Config::TOSPUR_ORGANIZATION_TABLE.$where,$parentId));
return $result; return $result;
} }
public static function getCityNameWithId($cityId){ public static function getCityNameWithId($cityId){
global $wpdb; global $wpdb;
$result = $wpdb->get_var($wpdb->prepare("select cityName from ".TCSync::DIC_CITY_TABLE." where cityId = %d",$cityId)); $result = $wpdb->get_var($wpdb->prepare("select cityName from ".Config::DIC_CITY_TABLE." where cityId = %d",$cityId));
if($result){ if($result){
return $result; return $result;
}else{ }else{
...@@ -120,51 +116,64 @@ class SearchDao{ ...@@ -120,51 +116,64 @@ class SearchDao{
wp_send_json(SearchDao::searchHouse($_GET["cityId"],$_GET["districtId"],$_GET["plateId"],$_GET["buildPropertyId"],$_GET["roomId"],$_GET["acreage"],$_GET["totalPrice"],$_GET["searchText"])); wp_send_json(SearchDao::searchHouse($_GET["cityId"],$_GET["districtId"],$_GET["plateId"],$_GET["buildPropertyId"],$_GET["roomId"],$_GET["acreage"],$_GET["totalPrice"],$_GET["searchText"]));
} }
public static function searchHouse($cityId = NULL,$districtId = NULL,$plateId = NULL,$buildpropertyId = NULL,$roomId = NULL,$acreage = NULL,$totalPrice = NULL,$searchText = NULL){ public static function searchHouse($cityId = 0,$districtId = 0,$plateId = 0,$buildPropertyId = 0,$roomId = 0,$acreage = 0,$totalPrice = 0,$searchText = NULL){
global $wpdb; global $wpdb;
if($acreage == "面积"){ $params = array();
$acreage = null;
}
if($totalPrice == "价格"){
$totalPrice = null;
}
$areaArray = explode("-",$acreage);
$priceArray = explode("-",$totalPrice);
$sql = "select * from tospur_house th $sql = "select * from tospur_house th
left join (select buildproperty_id,house_area,image_id,house_id as bph_id from a_district_area) ada on th.id = ada.bph_id left join (select buildproperty_id,house_area,image_id,house_id as bph_id from a_district_area) ada on th.id = ada.bph_id
left join dic_city dc on th.plate_id = dc.plateId left join dic_city dc on th.plate_id = dc.plateId
left join (select * from a_house_image group by house_id) hi on th.id = hi.house_id left join (select * from a_house_image group by house_id) hi on th.id = hi.house_id
left join (select id,name as iname,path,creattime as itime,alt,image_type from tospur_image) i on hi.image_id = i.id where 1=1"; left join (select id,name as iname,path,creattime as itime,alt,image_type from tospur_image) i on hi.image_id = i.id where 1=1";
if($cityId!=NULL ){ if($cityId!=0 ){
$sql = $sql." and cityId=".$cityId; $params[] = $cityId;
$sql = $sql." and cityId=%d";
} }
if($districtId != NULL ){ if($districtId != 0 ){
$sql = $sql." and districtId=".$districtId; $params[] = $districtId;
$sql = $sql." and districtId=%d";
} }
if($plateId != NULL){ if($plateId != 0){
$sql = $sql." and plateId=".$plateId; $params[] = $plateId;
$sql = $sql." and plateId=%d";
} }
if($buildpropertyId!=NULL){ if( $buildPropertyId != 0){
$sql = $sql." and buildproperty_id=".$buildpropertyId; $params[] = $buildPropertyId;
$sql = $sql." and buildproperty_id=%d";
} }
if($roomId!=NULL){ if($roomId!=0){
$sql = $sql." and room_id=".$roomId; $params[] = $roomId;
$sql = $sql." and room_id=%d";
} }
if($acreage!=NULL){ if($acreage!=0){
$sql = $sql." and covered_area between ". $areaArray[0]." and ". $areaArray[1]; $areaArray = explode("-",$acreage);
$params[] = $areaArray[0];
$params[] = $areaArray[1];
$sql = $sql." and covered_area between %d and %d";
} }
if($totalPrice!=NULL){ if($totalPrice!=0){
$sql = $sql." and total_price between ". $priceArray[0]." and ". $priceArray[1]; $priceArray = explode("-",$totalPrice);
$params[] = $priceArray[0];
$params[] = $priceArray[1];
$sql = $sql." and total_price between %d and %d";
} }
if($searchText!=NULL){ if($searchText!=0){
$sql = $sql." and name like '%".$searchText."%'"; $params[] = "%".$searchText."%";
$sql = $sql." and name like %s";
} }
$sql = $sql." group by bph_id order by th.creattime DESC"; $sql = $sql." group by bph_id order by th.creattime DESC";
$result = $wpdb->get_results($sql); print_r($wpdb->prepare($sql,$params));
$result = $wpdb->get_results($wpdb->prepare($sql,$params));
return $result; return $result;
} }
public static function getWorkUser(){
public static function ajax_searchPhotoType(){
wp_send_json(SearchDao::searchPhotoType());
}
public static function searchPhotoType(){
global $wpdb;
$result = $wpdb->get_results('select id,photo_name as value from '.Config::DIC_PHOTOTYPE_TABLE);
return $result;
} }
} }
\ No newline at end of file
<?php
class TCSync {
const user_url = 'http://218.1.67.130:8988/api/NanTongWechat/GetPropertyConsultant?cityId=1';
public static function user_sync(){
$response = wp_remote_post( TCSync::user_url );
$res = array(
'code' => 200,
'msg' => "success"
);
//判断请求是否成功
if( is_wp_error( $response ) || wp_remote_retrieve_response_code( $response ) !== 200 ){
$res['code'] = 500;
$res['msg'] = "get user info error";
}else{
set_time_limit(0) ;
//获取请求内容
$result = wp_remote_retrieve_body( $response );
$result = json_decode($result,true);
foreach($result['data'] as $item){
if(username_exists($item['WorkNum'])){
$user = get_user_by( "login", $item['WorkNum'] );
$userdata = array(
'ID' => $user->data->ID,
'display_name' => $item['Name']
);
$user_id = wp_update_user( $userdata ) ;
}else{
$userdata = array(
'user_login' => $item['WorkNum'],
'user_pass' => $item['WorkNumAndID'], // When creating an user, `user_pass` is expected.
'role' => 'editor',
'wp_user_level' => 7,
'display_name' => $item['Name']
);
$user_id = wp_insert_user( $userdata ) ;
}
if(is_numeric($user_id) && !is_null($item['ImageUrl'])){
update_user_meta( $user_id, "tc_image", $item['ImageUrl'] );
}
}
}
return $res;
}
}
\ No newline at end of file
<?php <?php
require_once(PLUGIN_DIR . 'Config.php');
class TCSync { class TCSync {
const user_url = 'http://218.1.67.130:8988/api/NanTongWechat/GetPropertyConsultant?cityId=1';
const other_url = 'http://218.1.67.130:8988/api/NanTongWechat/GetCommonPlate?radomPla=123456';
const organization_url = 'http://218.1.67.130:8988/api/NanTongWechat/GetOrgnaziTion?radomOrg=123456';
const DIC_CITY_TABLE = 'dic_city';
const DIC_ROOM_TABLE = 'dic_room';
const DIC_BUILDPROPERTY_TABLE = 'dic_buildproperty';
const DIC_AREA_TABLE = 'dic_area';
const DIC_UNITPRICERANGE_TABLE = 'dic_unitpricerange';
const DIC_TOTALPRICE_TABLE = 'dic_totalprice';
const TOSPUR_ORGANIZATION_TABLE = 'tospur_organization';
const TOSPUR_CONSULTANT = 'tospur_consultant';
public static function user_sync(){ public static function user_sync(){
global $wpdb; global $wpdb;
$response = wp_remote_post( TCSync::user_url ); $response = wp_remote_post( Config::user_url );
$res = array( $res = array(
'code' => 200, 'code' => 200,
'msg' => "success" 'msg' => "success"
...@@ -55,7 +43,7 @@ class TCSync { ...@@ -55,7 +43,7 @@ class TCSync {
'mobile' => $item['Mobile'], 'mobile' => $item['Mobile'],
'name' => $item['Name'] 'name' => $item['Name']
); );
$wpdb->query(TCSync::create_insert_update_sql(TCSync::TOSPUR_CONSULTANT,$info,array('id'))); $wpdb->query(TCSync::create_insert_update_sql(Config::TOSPUR_CONSULTANT,$info,array('id')));
} }
} }
} }
...@@ -64,7 +52,7 @@ class TCSync { ...@@ -64,7 +52,7 @@ class TCSync {
public static function other_sync(){ public static function other_sync(){
global $wpdb; global $wpdb;
$response = wp_remote_post( TCSync::other_url ); $response = wp_remote_post( Config::other_url );
$res = array( $res = array(
'code' => 200, 'code' => 200,
'msg' => "success" 'msg' => "success"
...@@ -80,33 +68,33 @@ class TCSync { ...@@ -80,33 +68,33 @@ class TCSync {
$result = json_decode($result,true); $result = json_decode($result,true);
//print_r($result['data']['CityList']); //print_r($result['data']['CityList']);
foreach($result['data']['CityList'] as $item){ foreach($result['data']['CityList'] as $item){
$wpdb->query(TCSync::create_insert_update_sql(TCSync::DIC_CITY_TABLE,$item,array('plateId'))); $wpdb->query(TCSync::create_insert_update_sql(Config::DIC_CITY_TABLE,$item,array('plateId')));
//print_r(TCSync::create_insert_update_sql(TCSync::CITY_TABLE,$item,array('plateId')));print_r("<br />"); //print_r(TCSync::create_insert_update_sql(Config::CITY_TABLE,$item,array('plateId')));print_r("<br />");
} }
foreach($result['data']['RoomStyle'] as $item){ foreach($result['data']['RoomStyle'] as $item){
$wpdb->query(TCSync::create_insert_update_sql(TCSync::DIC_ROOM_TABLE,$item,array('id'))); $wpdb->query(TCSync::create_insert_update_sql(Config::DIC_ROOM_TABLE,$item,array('id')));
//print_r(TCSync::create_insert_update_sql(TCSync::DIC_ROOM_TABLE,$item,array('id')));print_r("<br />"); //print_r(TCSync::create_insert_update_sql(Config::DIC_ROOM_TABLE,$item,array('id')));print_r("<br />");
} }
foreach($result['data']['BulidProperty'] as $item){ foreach($result['data']['BulidProperty'] as $item){
$wpdb->query(TCSync::create_insert_update_sql(TCSync::DIC_BUILDPROPERTY_TABLE,$item,array('id'))); $wpdb->query(TCSync::create_insert_update_sql(Config::DIC_BUILDPROPERTY_TABLE,$item,array('id')));
//print_r(TCSync::create_insert_update_sql(TCSync::DIC_BUILDPROPERTY_TABLE,$item,array('id')));print_r("<br />"); //print_r(TCSync::create_insert_update_sql(Config::DIC_BUILDPROPERTY_TABLE,$item,array('id')));print_r("<br />");
} }
foreach($result['data']['AreaRange'] as $item){ foreach($result['data']['AreaRange'] as $item){
$wpdb->query(TCSync::create_insert_update_sql(TCSync::DIC_AREA_TABLE,$item,array('id'),array('maxValue'=>'max','minValue'=>'min'))); $wpdb->query(TCSync::create_insert_update_sql(Config::DIC_AREA_TABLE,$item,array('id'),array('maxValue'=>'max','minValue'=>'min')));
//print_r(TCSync::create_insert_update_sql(TCSync::DIC_AREA,$item,array('id'),array('maxValue'=>'max','minValue'=>'min')));print_r("<br />"); //print_r(TCSync::create_insert_update_sql(Config::DIC_AREA,$item,array('id'),array('maxValue'=>'max','minValue'=>'min')));print_r("<br />");
} }
foreach($result['data']['TotalPrice'] as $item){ foreach($result['data']['TotalPrice'] as $item){
$wpdb->query(TCSync::create_insert_update_sql(TCSync::DIC_TOTALPRICE_TABLE,$item,array('id'),array('maxValue'=>'max','minValue'=>'min'))); $wpdb->query(TCSync::create_insert_update_sql(Config::DIC_TOTALPRICE_TABLE,$item,array('id'),array('maxValue'=>'max','minValue'=>'min')));
//print_r(TCSync::create_insert_update_sql(TCSync::DIC_AREA,$item,array('id'),array('maxValue'=>'max','minValue'=>'min')));print_r("<br />"); //print_r(TCSync::create_insert_update_sql(Config::DIC_AREA,$item,array('id'),array('maxValue'=>'max','minValue'=>'min')));print_r("<br />");
} }
foreach($result['data']['UnitPriceRange'] as $item){ foreach($result['data']['UnitPriceRange'] as $item){
$wpdb->query(TCSync::create_insert_update_sql(TCSync::DIC_UNITPRICERANGE_TABLE,$item,array('id'),array('maxValue'=>'max','minValue'=>'min'))); $wpdb->query(TCSync::create_insert_update_sql(Config::DIC_UNITPRICERANGE_TABLE,$item,array('id'),array('maxValue'=>'max','minValue'=>'min')));
//print_r(TCSync::create_insert_update_sql(TCSync::DIC_AREA,$item,array('id'),array('maxValue'=>'max','minValue'=>'min')));print_r("<br />"); //print_r(TCSync::create_insert_update_sql(Config::DIC_AREA,$item,array('id'),array('maxValue'=>'max','minValue'=>'min')));print_r("<br />");
} }
} }
...@@ -114,7 +102,7 @@ class TCSync { ...@@ -114,7 +102,7 @@ class TCSync {
public static function organization_sync(){ public static function organization_sync(){
global $wpdb; global $wpdb;
$response = wp_remote_post( TCSync::organization_url ); $response = wp_remote_post( Config::organization_url );
$res = array( $res = array(
'code' => 200, 'code' => 200,
'msg' => "success" 'msg' => "success"
...@@ -128,8 +116,8 @@ class TCSync { ...@@ -128,8 +116,8 @@ class TCSync {
$result = wp_remote_retrieve_body( $response ); $result = wp_remote_retrieve_body( $response );
$result = json_decode($result,true); $result = json_decode($result,true);
foreach($result['data'] as $item){ foreach($result['data'] as $item){
$wpdb->query(TCSync::create_insert_update_sql(TCSync::TOSPUR_ORGANIZATION_TABLE,$item,array('Id'))); $wpdb->query(TCSync::create_insert_update_sql(Config::TOSPUR_ORGANIZATION_TABLE,$item,array('Id')));
//print_r(TCSync::create_insert_update_sql(TCSync::DIC_AREA,$item,array('id'),array('maxValue'=>'max','minValue'=>'min')));print_r("<br />"); //print_r(TCSync::create_insert_update_sql(Config::DIC_AREA,$item,array('id'),array('maxValue'=>'max','minValue'=>'min')));print_r("<br />");
} }
} }
} }
......
...@@ -166,6 +166,7 @@ function reset_menu() ...@@ -166,6 +166,7 @@ function reset_menu()
function create_table() function create_table()
{ {
TCSync::user_sync(); //TCSync::user_sync();
//TCSync::organization_sync(); TCSync::organization_sync();
TCSync::other_sync();
} }
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