Commit 4aa30a4b by felix

合并用

parent 4be24ca1
<?php
require_once(PLUGIN_DIR . 'Dao/SearchDao.php');
class House {
public static function init_view(){
wp_enqueue_script('jquery-ui');
......@@ -11,33 +12,10 @@ class House {
}else{
global $wpdb;
$context = array();
$citysql ="select DISTINCT cityId,cityName from";
$cityRes = $wpdb->get_results($citysql.' dic_city');
foreach($cityRes as $value){
$cityParams = array(
"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;
}
$context["city"] = SearchDao::searchCity();
$context["buildProperty"] = SearchDao::searchBuildProperty();
$context["room"] = SearchDao::searchRoom();
$context["photoType"] = SearchDao::searchPhotoType();
House::data_insert();
Timber::render("newhouse.html",$context);
}
......@@ -70,79 +48,82 @@ class House {
'parking_spaces' => $_POST['parking_spaces'],
'property_management' => $_POST['property_management'],
'overview' => $_POST['overview'],
'plate_id'=>$_POST["basePlateId"],
"room_id"=>$_POST["baseRoom"],
"property_money" =>$_POST["property_money"],
'creattime'=>date("Y-m-d H:i:s")
'city_id' => $_POST['baseCity'],
'district_id' => $_POST['baseAreaId'],
'plate_id' => $_POST["basePlateId"],
"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 );
if(!$res){
$res = $wpdb->get_results('SELECT * FROM tospur_house WHERE name="' . $_POST['name'] . '" and address="' . $_POST['address'] . '"', OBJECT);
if (!$res) {
$houseRes = $wpdb->insert('tospur_house', $insert_tospur_house_array);
if(!$houseRes){
if (!$houseRes) {
return 500;
}
$houseid = $wpdb->insert_id;
}
for ($x=0; $x<=count($uploadedfile["name"])-1; $x++) {
//主力房源的图片与房子信息关联插入数据库
foreach($uploadedfile["name"] as $key=> $value) {
$uploadParam = array(
"name"=>$uploadedfile["name"]["$x"],
"type"=>$uploadedfile["type"]["$x"],
"tmp_name"=>$uploadedfile["tmp_name"]["$x"],
"error"=>$uploadedfile["error"]["$x"],
"size"=>$uploadedfile["size"]["$x"]
"name" => $uploadedfile["name"][$key],
"type" => $uploadedfile["type"][$key],
"tmp_name" => $uploadedfile["tmp_name"][$key],
"error" => $uploadedfile["error"][$key],
"size" => $uploadedfile["size"][$key]
);
//因为file提交过来有一个空的数组,所以这里判断在filename不为空的情况下,再做后续操作
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 ($uploadParam["name"] != "") {
//上传图片
if (!function_exists('wp_handle_upload')){
require_once(ABSPATH.'wp-admin/includes/file.php');
if (!function_exists('wp_handle_upload')) {
require_once(ABSPATH . 'wp-admin/includes/file.php');
}
$overrides = array( 'test_form' => false);
$movefile = wp_handle_upload($uploadParam,$overrides);
if ( $movefile && !isset( $movefile['error'] ) ) {
$overrides = array('test_form' => false);
$movefile = wp_handle_upload($uploadParam, $overrides);
$str = preg_replace('#^https?://#', '', $movefile["url"]);
$length = strpos($str, "/",strpos($str, "/")+1);
$url = substr($str,$length);
if ($movefile && !isset($movefile['error'])) {
//上传成功后将图片信息存入tospur_image表
$insert_image_array = array(
'name' => $uploadParam['name'],
'path' => $path,
'name' => $uploadParam["name"],
'path' => $url,
'creattime' => date("Y-m-d H:i:s"),
'alt' => "",
'image_type' =>$uploadParam['type']
'image_type' =>$data[$key]["type"]
);
//插入图片表
$imgRes = $wpdb->insert('tospur_image', $insert_image_array);
if(!$imgRes){
if (!$imgRes) {
return 501;
}
//获取插入图片的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 {
echo $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;
return $movefile['error'];
}
}
}
......
......@@ -14,7 +14,7 @@
最新动态:<textarea rows="3" cols="20" name="event"></textarea><br><br>
<div id="preview">
<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>
</div>
<br><br>
......@@ -23,7 +23,7 @@
<select id="baseCity" name="baseCity">
<option value=""> 城市</option>
{% for item in city %}
<option value="{{ item.cityId }}">{{ item.cityName }}</option>
<option value="{{ item.id }}">{{ item.value }}</option>
{% endfor %}
</select>
<select id="baseAreaId" name="baseAreaId">
......@@ -35,7 +35,7 @@
<select id="baseRoom" name="baseRoom">
<option value = "">建筑类型</option>
{% for item in room %}
<option value="{{ item.value }}">{{ item.literal }}</option>
<option value="{{ item.id }}">{{ item.value }}</option>
{% endfor %}
</select>
</p>
......@@ -58,6 +58,11 @@
<input type="text" name="type" value="1" hidden="hidden">
</div>
<div>
房源相册: <input type="button" value="新增" id="housePicture" class="button action">
<div id="picList"></div>
</div>
<input type="submit" id="submit" class="button action">
</form>
<!-- Button trigger modal -->
......@@ -73,34 +78,34 @@
<div class="modal-body" style="height: 300px;overflow: auto;">
<select id="cityId">
<option value=""> 城市</option>
<option value="0"> 城市</option>
{% for item in city %}
<option value="{{ item.cityId }}">{{ item.cityName }}</option>
<option value="{{ item.id }}">{{ item.value }}</option>
{% endfor %}
</select>
<select id="areaId">
<option value = "">区域</option>
<option value = "0">区域</option>
</select>
<select id="plateId">
<option value = "">板块</option>
<option value = "0">板块</option>
</select>
<select id="price">
<option value = "">价格</option>
<option value = "0">价格</option>
</select>
<select id="buildproperty">
<option value = "">房型</option>
{% for item in buildproperty %}
<option value="{{ item.value }}">{{ item.literal }}</option>
<select id="buildProperty">
<option value = "0">房型</option>
{% for item in buildProperty %}
<option value="{{ item.id }}">{{ item.value }}</option>
{% endfor %}
</select>
<select id="room">
<option value = "">类型</option>
<option value = "0">类型</option>
{% for item in room %}
<option value="{{ item.value }}">{{ item.literal }}</option>
<option value="{{ item.id }}">{{ item.value }}</option>
{% endfor %}
</select>
<select id="roomarea">
<option value = "">面积</option>
<select id="acreage">
<option value = "0">面积</option>
</select>
<input type="text" placeholder="请出入楼盘名/地段名搜索" id="searchtext">
<button type="button" class="button action" id="search">搜索</button>
......@@ -111,13 +116,6 @@
</div>
</div>
<div>
房源相册:
<div id="picList"></div>
<div>
<input type="button" value="新增" id="housePicture" class="button action">
</div>
</div>
<script>
(function($){
......@@ -125,6 +123,7 @@
//主力房源中选择图片file的下标
var i = 0;
//房源相册的下标
//入住时间选择
$("#checkin").datepicker({
......@@ -181,12 +180,12 @@
$("#cityId").change(function(){
var cityId = $(this).val();
var area = $("#areaId");
var roomarea =$("#roomarea");
var acreage =$("#acreage");
var price = $("#price");
$('#areaId').find('option:not(:first-child)').remove();
$('#plateId').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();
//城市联动区域
......@@ -204,7 +203,7 @@
url: "/tospur/wp-admin/admin-ajax.php",
data: "action=searchArea&cityId="+cityId,
success:function(json){
addOption(json,roomarea);
addOption(json,acreage);
}
});
//城市联动房子价格
......@@ -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();
var buildpropertyId = $("#buildproperty").val();
var buildPropertyId = $("#buildProperty").val();
var room = $("#room").val();
var areaId = $("#areaId").val();
var cityId = $("#cityId").val();
var plateId = $("#plateId").val();
var area = $("#roomarea").find("option:selected").text();
var price = $("#price").find("option:selected").text();
var acreage = $("#acreage").val();
var price = $("#price").val();
$.ajax({
type: "GET",
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){
for(
var i = 0; i <=json.length-1; i++){
......@@ -296,20 +295,28 @@
});
$("#housePicture").click(function(){
var fileId = i;
var picDelet = $("<font>").append("删除").addClass("picDelet");
var file = $("<input>").attr({"type":"file","id":fileId}).addClass("picFiles");
var select = $("<select>");
var file = $("<input>").attr({"type":"file","name":"files["+i+"]"}).addClass("picFiles");
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);
$("#picList").append(p);
i++;
i++
});
//房源相册
$("#picList").on("change",".picFiles",function(){
readURL(this,2);
$(this).hide();
});
$("#picList").on("click",".picDelet",function(){
$(this).parent("p").remove();
})
$("#submit").click(function(){
if($("#housename").val()==""){
......@@ -321,38 +328,31 @@
//file上传之前,显示图片的方法
function readURL(input,type) {
if(type == 1){
var index = i;
if (input.files && input.files[0]){
var reader = new FileReader();
reader.onload = function (e) {
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 option = $("<option>").attr({"value":""}).append("户型");
var file = $("<input>").attr({"type":"file","name":"files[]","property":+index}).addClass("files");
var select = $("<select>").attr({"id":"buildproperty","name":"data["+index+"][buildproperty]"}).append(option).addClass("regular-text");
var areatext = $("<input>").attr({"type":"text","placeholder":"面积","name":"data["+index+"][housearea]"}).addClass("regular-text");
var div = $("<div>").append(select).append(areatext).append(button);
var span = $("<span>").attr({"property":+index-1}).append(img).append(div);
$.ajax({
type: "GET",
url: "/tospur/wp-admin/admin-ajax.php",
data: "action=searchBuildProperty",
success:function(json){
addOption(json,select)
}
});
var button = $("<input>").attr({"type":"button","value":"取消","property":+i,"id":+i}).addClass("cancel");
var type = $("<input>").attr({"type":"hidden","name":"data["+i+"][type]","value":0,"property":+i});
var file = $("<input>").attr({"type":"file","name":"files["+(i+1)+"]","property":+(i+1)}).addClass("files");
var select = $("<select>").attr({"name":"data["+i+"][buildProperty]"});
{% for item in buildProperty %}
select.append($("<option>").attr("value",{{item.id}}).append('{{item.value}}'));
{% endfor%}
var areatext = $("<input>").attr({"type":"text","placeholder":"面积","name":"data["+i+"][housearea]"}).addClass("regular-text");
var div = $("<div>").append(select).append(areatext).append(button).append(type);
var span = $("<span>").attr({"property":+i}).append(img).append(div);
$("form").find("#preview > p").before(file);
$("#preview > p").append(span);
i++;
}
}
}else{
var picId = i;
if (input.files && input.files[0]){
var reader = new FileReader();
reader.onload = function (e){
var img = $("<img>").attr({"src":e.target.result,"heghit":100,"width":100,"id":picId});
$("#picList > p").find("input").before(img);
var img = $("<img>").attr({"src":e.target.result,"heghit":100,"width":100});
$(input).before(img);
}
}
}
......@@ -361,9 +361,13 @@
function addOption(json,select){
var selectId = select.attr("id");
for(var i = 0; i <=json.length-1; i++){
var id = json[i]["id"];
var value = json[i]["value"];
if(selectId == "acreage" || selectId == "price"){
id = value;
}
var Option = $("<option>").attr({"value": id}).append(value);
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
class SearchDao{
public function __construct() {
require_once(PLUGIN_DIR . '\TCSync.php');
}
public static function ajax_serachCity(){
wp_send_json(SearchDao::searchCity($_GET["cityId"],$_GET['districtId']));
}
......@@ -26,7 +22,7 @@ class SearchDao{
$params[] = $districtId;
$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;
}
......@@ -40,7 +36,7 @@ class SearchDao{
if(isset($_GET['cityId'])){
$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;
}
......@@ -50,7 +46,7 @@ class SearchDao{
public static function searchBuildProperty(){
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;
}
......@@ -60,7 +56,7 @@ class SearchDao{
public static function searchRoom(){
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;
}
......@@ -74,7 +70,7 @@ class SearchDao{
if(isset($_GET['cityId'])){
$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;
}
......@@ -88,7 +84,7 @@ class SearchDao{
if(isset($_GET['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;
}
......@@ -102,13 +98,13 @@ class SearchDao{
if($parentId != NULL){
$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;
}
public static function getCityNameWithId($cityId){
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){
return $result;
}else{
......@@ -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"]));
}
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;
if($acreage == "面积"){
$acreage = null;
}
if($totalPrice == "价格"){
$totalPrice = null;
}
$areaArray = explode("-",$acreage);
$priceArray = explode("-",$totalPrice);
$params = array();
$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 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 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 ){
$sql = $sql." and cityId=".$cityId;
if($cityId!=0 ){
$params[] = $cityId;
$sql = $sql." and cityId=%d";
}
if($districtId != NULL ){
$sql = $sql." and districtId=".$districtId;
if($districtId != 0 ){
$params[] = $districtId;
$sql = $sql." and districtId=%d";
}
if($plateId != NULL){
$sql = $sql." and plateId=".$plateId;
if($plateId != 0){
$params[] = $plateId;
$sql = $sql." and plateId=%d";
}
if($buildpropertyId!=NULL){
$sql = $sql." and buildproperty_id=".$buildpropertyId;
if( $buildPropertyId != 0){
$params[] = $buildPropertyId;
$sql = $sql." and buildproperty_id=%d";
}
if($roomId!=NULL){
$sql = $sql." and room_id=".$roomId;
if($roomId!=0){
$params[] = $roomId;
$sql = $sql." and room_id=%d";
}
if($acreage!=NULL){
$sql = $sql." and covered_area between ". $areaArray[0]." and ". $areaArray[1];
if($acreage!=0){
$areaArray = explode("-",$acreage);
$params[] = $areaArray[0];
$params[] = $areaArray[1];
$sql = $sql." and covered_area between %d and %d";
}
if($totalPrice!=NULL){
$sql = $sql." and total_price between ". $priceArray[0]." and ". $priceArray[1];
if($totalPrice!=0){
$priceArray = explode("-",$totalPrice);
$params[] = $priceArray[0];
$params[] = $priceArray[1];
$sql = $sql." and total_price between %d and %d";
}
if($searchText!=NULL){
$sql = $sql." and name like '%".$searchText."%'";
if($searchText!=0){
$params[] = "%".$searchText."%";
$sql = $sql." and name like %s";
}
$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;
}
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
require_once(PLUGIN_DIR . 'Config.php');
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(){
global $wpdb;
$response = wp_remote_post( TCSync::user_url );
$response = wp_remote_post( Config::user_url );
$res = array(
'code' => 200,
'msg' => "success"
......@@ -55,7 +43,7 @@ class TCSync {
'mobile' => $item['Mobile'],
'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 {
public static function other_sync(){
global $wpdb;
$response = wp_remote_post( TCSync::other_url );
$response = wp_remote_post( Config::other_url );
$res = array(
'code' => 200,
'msg' => "success"
......@@ -80,33 +68,33 @@ class TCSync {
$result = json_decode($result,true);
//print_r($result['data']['CityList']);
foreach($result['data']['CityList'] as $item){
$wpdb->query(TCSync::create_insert_update_sql(TCSync::DIC_CITY_TABLE,$item,array('plateId')));
//print_r(TCSync::create_insert_update_sql(TCSync::CITY_TABLE,$item,array('plateId')));print_r("<br />");
$wpdb->query(TCSync::create_insert_update_sql(Config::DIC_CITY_TABLE,$item,array('plateId')));
//print_r(TCSync::create_insert_update_sql(Config::CITY_TABLE,$item,array('plateId')));print_r("<br />");
}
foreach($result['data']['RoomStyle'] as $item){
$wpdb->query(TCSync::create_insert_update_sql(TCSync::DIC_ROOM_TABLE,$item,array('id')));
//print_r(TCSync::create_insert_update_sql(TCSync::DIC_ROOM_TABLE,$item,array('id')));print_r("<br />");
$wpdb->query(TCSync::create_insert_update_sql(Config::DIC_ROOM_TABLE,$item,array('id')));
//print_r(TCSync::create_insert_update_sql(Config::DIC_ROOM_TABLE,$item,array('id')));print_r("<br />");
}
foreach($result['data']['BulidProperty'] as $item){
$wpdb->query(TCSync::create_insert_update_sql(TCSync::DIC_BUILDPROPERTY_TABLE,$item,array('id')));
//print_r(TCSync::create_insert_update_sql(TCSync::DIC_BUILDPROPERTY_TABLE,$item,array('id')));print_r("<br />");
$wpdb->query(TCSync::create_insert_update_sql(Config::DIC_BUILDPROPERTY_TABLE,$item,array('id')));
//print_r(TCSync::create_insert_update_sql(Config::DIC_BUILDPROPERTY_TABLE,$item,array('id')));print_r("<br />");
}
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')));
//print_r(TCSync::create_insert_update_sql(TCSync::DIC_AREA,$item,array('id'),array('maxValue'=>'max','minValue'=>'min')));print_r("<br />");
$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(Config::DIC_AREA,$item,array('id'),array('maxValue'=>'max','minValue'=>'min')));print_r("<br />");
}
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')));
//print_r(TCSync::create_insert_update_sql(TCSync::DIC_AREA,$item,array('id'),array('maxValue'=>'max','minValue'=>'min')));print_r("<br />");
$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(Config::DIC_AREA,$item,array('id'),array('maxValue'=>'max','minValue'=>'min')));print_r("<br />");
}
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')));
//print_r(TCSync::create_insert_update_sql(TCSync::DIC_AREA,$item,array('id'),array('maxValue'=>'max','minValue'=>'min')));print_r("<br />");
$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(Config::DIC_AREA,$item,array('id'),array('maxValue'=>'max','minValue'=>'min')));print_r("<br />");
}
}
......@@ -114,7 +102,7 @@ class TCSync {
public static function organization_sync(){
global $wpdb;
$response = wp_remote_post( TCSync::organization_url );
$response = wp_remote_post( Config::organization_url );
$res = array(
'code' => 200,
'msg' => "success"
......@@ -128,8 +116,8 @@ class TCSync {
$result = wp_remote_retrieve_body( $response );
$result = json_decode($result,true);
foreach($result['data'] as $item){
$wpdb->query(TCSync::create_insert_update_sql(TCSync::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 />");
$wpdb->query(TCSync::create_insert_update_sql(Config::TOSPUR_ORGANIZATION_TABLE,$item,array('Id')));
//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()
function create_table()
{
TCSync::user_sync();
//TCSync::organization_sync();
//TCSync::user_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