Commit 5ef36e0c by shz

tospur

parent 43362bae
......@@ -39,15 +39,8 @@ class newHouseList extends WP_List_Table
case 'parking_spaces':
case 'property_management':
case 'property_money':
return $item[$column_name];
case 'valid':
if ($item[$column_name]) {
return '<button data-valid="0" data-score-id="' . $item['id'] . '">设为无效</button>';
} else {
return '<button data-valid="1" data-score-id="' . $item['id'] . '">设为有效</button>';
}
default:
return print_r($item, true); //Show the whole array for troubleshooting purposes
return '<a href="' . admin_url() . 'admin.php?page=newHouse&edit=true&id=' . $item['id'] . '">' . $item[$column_name] . '</a>';
}
}
......@@ -173,7 +166,7 @@ class newHouseList extends WP_List_Table
$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
where 1=1 ";
where 1=1 and house_type=0";
if($_POST["listCity"]!=0 ){
$sql = $sql." and city_id=".$_POST["listCity"];
}
......
<?php
require_once(PLUGIN_DIR . 'Dao/SearchDao.php');
require_once(PLUGIN_DIR . 'Dao/InsertDao.php');
require_once(PLUGIN_DIR . 'Tools/Image.php');
class RentHouse{
//二手房信息
public static function rentHouse_html(){
wp_enqueue_script('bootstrapjs');
wp_enqueue_style('bootstrapcss');
global $wpdb;
$type = $_POST["type"];
$context = array();
//获取新房信息,存入tospur_house表
$insert_tospur_house_array = array(
'name' => $_POST['housename'],
'house_number' =>$_POST['house_number'],
'rent'=>$_POST['rent'],
'buildproperty_id'=>$_POST['buildproperty_id'],
'covered_area' =>$_POST['covered_area'],
'floor' =>$_POST['floor'],
'faceto'=>$_POST['faceto'],
'decoration' => $_POST['decoration'],
'age'=>$_POST['age'],
'matching_facilities'=>$_POST['matching_facilities'],
'flat'=>$_POST['flat'],
'suite'=>$_POST["suite"],
'overview' => $_POST['overview'],
'city_id' => $_POST['baseCity'],
'district_id' => $_POST['baseAreaId'],
'plate_id' => $_POST["basePlateId"],
'address' => $_POST['address'],
'community_name'=>$_POST['community_name'],
'traffic' => $_POST['traffic'],
'periphery' => $_POST['periphery'],
'status' =>$_POST['status'],
'house_type' => 2
);
if($type==3){
$wpdb->query("START TRANSACTION");
if(isset($_POST['houseId'])){
$result = RentHouse::data_update($_POST['houseId'],$insert_tospur_house_array);
if($result != 202){
$wpdb->query("ROLLBACK");
print_r($wpdb->last_error);;
echo "租房房源修改失败";
}else{
$wpdb->query("COMMIT");
echo "租房房源修改成功";
}
}else {
$result = RentHouse::rentHouseData_insert($insert_tospur_house_array);
if ($result != 200) {
$wpdb->query("ROLLBACK");
print_r($wpdb->last_error);;
echo "租房房源新增失败";
} else {
$wpdb->query("COMMIT");
echo "租房房源新增成功";
}
}
exit;
}else if(isset($_GET['edit'])){
$context['houseId'] = $_GET['id'];
$context = array_merge($context,SearchDao::getDetailInfo($_GET['id']));
$context["district"] = SearchDao::searchCity($context['result']->city_id);
$context["plate"] = SearchDao::searchCity($context['result']->city_id,$context['result']->district_id);
}
$context["city"] = SearchDao::searchCity();
$context["buildProperty"] = SearchDao::searchBuildProperty();
$context["room"] = SearchDao::searchRoom();
$context["photoType"] = SearchDao::searchPhotoType();
Timber::render("rentHouse.html",$context);
}
public static function rentHouseData_insert($params)
{
global $wpdb;
//图片信息
$uploadedfile = $_FILES['files'];
//房源与类型以及面积信息
$data = $_POST["data"];
$res = $wpdb->get_results('SELECT * FROM tospur_house WHERE flat="' .$_POST['flat'] . '" and suite="' . $_POST["suite"] . '" and house_type=2', OBJECT);
if(!$res){
$houseId = InsertDao::insert_tospur_house($params);
//主力房源的图片与房子信息关联插入数据库
if(isset($uploadedfile["name"])){
foreach($uploadedfile["name"] as $key=> $value) {
$uploadParam = array(
"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"] != "") {
//上传图片
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);
$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' => $url,
'creattime' => date("Y-m-d H:i:s"),
'alt' => "",
'image_type' =>$data[$key]["type"]
);
//插入图片表
$imgId =InsertDao::insert_tospur_image($insert_image_array);
$house_img_array = array(
'house_id' => $houseId,
'image_id' => $imgId,
);
$houseImgRes =InsertDao::insert_a_house_image($house_img_array);
} else {
return $movefile['error'];
echo "插入图片失败";
}
}
}
}
//插入推荐房源id与添加新房id到关联表a_house_recommend
if(isset($data["recommend"])){
foreach($data["recommend"] as $value){
$a_house_recommendArray = array(
"house_id" => $houseId,
"recommend_id" =>$value
);
$a_house_recommendRes =InsertDao::insert_a_house_recommend($a_house_recommendArray);
if($a_house_recommendRes == 504){
echo"推荐房源信息插入失败";
}
}
}
//插入推荐置业顾问user_id与新房id到关联表a_house_recommend
if($data["recConsultant"]){
foreach($data["recConsultant"] as $val){
$a_house_userArray = array(
"user_id" => $val,
"house_id" => $houseId,
"user_type" =>1
);
$a_house_userRes = InsertDao::insert_a_house_user($a_house_userArray);
if($a_house_userRes == 505){
echo"推荐置业顾问信息插入失败";
}
}
}
}else{
return 508;
}
return 200;
}
public static function data_update($houseId,$params){
global $wpdb;
$data = $_POST["data"];
$res = $wpdb->update(Config::TOSPUR_HOUSE_TABLE,$params,array("id" => $houseId));
if($res){
if($data["recConsultant"]){
foreach($data["recConsultant"] as $val){
$a_house_userArray = array(
"user_id" => $val,
"house_id" => $houseId,
"user_type" =>1
);
$a_house_userRes = $wpdb->update(Config::A_HOUSE_USER_TABLE,$a_house_userArray,array("house_id" => $houseId));
if(!$a_house_userRes){
return 513;
}
}
}
if(isset($data["recommend"])){
$delRes =$wpdb->delete( Config::A_HOUSE_RECOMMEND_TABLE, array( 'house_id'=>$houseId));
if($delRes){
foreach($data["recommend"] as $value){
$a_house_recommendArray = array(
"house_id" => $houseId,
"recommend_id" =>$value
);
$a_house_recommendRes =InsertDao::insert_a_house_recommend($a_house_recommendArray);
}
}
}
}else{
return 512;
}
return 202;
}
}
......@@ -9,35 +9,7 @@ class SecHandHouse{
wp_enqueue_style('bootstrapcss');
global $wpdb;
$type = $_POST["type"];
if($type==2){
$wpdb->query("START TRANSACTION");
$result = SecHandHouse::secHouseData_insert();
if($result != 200){
$wpdb->query("ROLLBACK");
print_r($wpdb->last_error);;
echo "二手房房源新增失败";
}else{
$wpdb->query("COMMIT");
echo "二手房房源新增成功";
}
exit;
}else{
$context = array();
$context["city"] = SearchDao::searchCity();
$context["buildProperty"] = SearchDao::searchBuildProperty();
$context["photoType"] = SearchDao::searchPhotoType();
Timber::render("secHandHouse.html",$context);
}
}
public static function secHouseData_insert()
{
global $wpdb;
//图片信息
$uploadedfile = $_FILES['files'];
//房源与类型以及面积信息
$data = $_POST["data"];
//获取新房信息,存入tospur_house表
$context = array();
$insert_tospur_house_array = array(
'name' => $_POST['housename'],
'house_number' =>$_POST['house_number'],
......@@ -52,15 +24,66 @@ class SecHandHouse{
'flat'=>$_POST['flat'],
'suite'=>$_POST["suite"],
'overview' => $_POST['overview'],
'city_id' => $_POST['baseCity'],
'district_id' => $_POST['baseAreaId'],
'plate_id' => $_POST["basePlateId"],
'address' => $_POST['address'],
'community_name'=>$_POST['community_name'],
'traffic' => $_POST['traffic'],
'periphery' => $_POST['periphery'],
'status' =>$_POST['status'],
'house_type' => 1
);
$res = $wpdb->get_results('SELECT * FROM tospur_house WHERE flat="' .$_POST['flat'] . '" and suite="' . $_POST["suite"] . '" and house_type=1', OBJECT);
if($type==2){
$wpdb->query("START TRANSACTION");
if(isset($_POST['houseId'])){
$result = SecHandHouse::data_update($_POST['houseId'],$insert_tospur_house_array);
if($result != 201){
$wpdb->query("ROLLBACK");
print_r($wpdb->last_error);;
echo "二手房房源修改失败";
}else{
$wpdb->query("COMMIT");
echo "二手房房源修改成功";
}
}else {
$result = SecHandHouse::secHouseData_insert($insert_tospur_house_array);
if ($result != 200) {
$wpdb->query("ROLLBACK");
print_r($wpdb->last_error);;
echo "二手房房源新增失败";
} else {
$wpdb->query("COMMIT");
echo "二手房房源新增成功";
}
}
exit;
}else if(isset($_GET['edit'])){
$context['houseId'] = $_GET['id'];
$context = array_merge($context,SearchDao::getDetailInfo($_GET['id']));
$context["district"] = SearchDao::searchCity($context['result']->city_id);
$context["plate"] = SearchDao::searchCity($context['result']->city_id,$context['result']->district_id);
}
$context["city"] = SearchDao::searchCity();
$context["buildProperty"] = SearchDao::searchBuildProperty();
$context["room"] = SearchDao::searchRoom();
$context["photoType"] = SearchDao::searchPhotoType();
Timber::render("secHandHouse.html",$context);
}
public static function secHouseData_insert($params)
{
global $wpdb;
//图片信息
$uploadedfile = $_FILES['files'];
//房源与类型以及面积信息
$data = $_POST["data"];
//获取新房信息,存入tospur_house表
$res = $wpdb->get_results('SELECT * FROM tospur_house WHERE name="'.$params['name'].'" flat="' .$_POST['flat'] . '" and suite="' . $_POST["suite"] . '" and house_type=1', OBJECT);
if(!$res){
$houseId = InsertDao::insert_tospur_house($insert_tospur_house_array);
$houseId = InsertDao::insert_tospur_house($params);
//主力房源的图片与房子信息关联插入数据库
if(isset($uploadedfile["name"])){
foreach($uploadedfile["name"] as $key=> $value) {
......@@ -138,5 +161,44 @@ class SecHandHouse{
}
return 200;
}
public static function data_update($houseId,$params){
global $wpdb;
$data = $_POST["data"];
$res = $wpdb->update(Config::TOSPUR_HOUSE_TABLE,$params,array("id" => $houseId));
if($res){
if($data["recConsultant"]){
foreach($data["recConsultant"] as $val){
$a_house_userArray = array(
"user_id" => $val,
"house_id" => $houseId,
"user_type" =>1
);
$a_house_userRes = $wpdb->update(Config::A_HOUSE_USER_TABLE,$a_house_userArray,array("house_id" => $houseId));
if(!$a_house_userRes){
return 511;
}
}
}
if(isset($data["recommend"])){
$delRes =$wpdb->delete( Config::A_HOUSE_RECOMMEND_TABLE, array( 'house_id'=>$houseId));
if($delRes){
foreach($data["recommend"] as $value){
$a_house_recommendArray = array(
"house_id" => $houseId,
"recommend_id" =>$value
);
$a_house_recommendRes =InsertDao::insert_a_house_recommend($a_house_recommendArray);
$wpdb->show_errors();
$wpdb->print_error();
}
}
}
}else{
return 510;
}
return 201;
}
}
<!DOCTYPE HTML>
<html>
<head>
{% set title = houseId?"修改二手房房源":"添加二手房房源" %}
<meta charset="utf-8">
<title>添加二手房房源</title>
<title>{{title}}</title>
</head>
<body>
<h2 class="title">添加二手房房源</h2>
<h2 class="title">{{title}}</h2>
<form action="" method="POST" enctype="multipart/form-data">
<table class="form-table">
<tbody>
<tr>
<th><label for="housename">房源名:</label></th>
<td> <input name="housename" id="housename" type="text" value="" class="regular-text code"></td>
</tr>
<tr>
<th><label for="community_name">房源编号:</label></th>
<td> <input name="house_number" id="house_number" type="text" value="" class="regular-text code"></td>
<td> <input name="housename" id="housename" type="text" value="{{result.name}}" class="regular-text code"></td>
</tr>
<tr>
<th><label for="total_price">售价</label></th>
<td> <input name="total_price" id="total_price" type="text" value="" class="regular-text code"></td>
<td> <input name="total_price" id="total_price" type="text" value="{{result.total_price}}" class="regular-text code"></td>
</tr>
<tr>
<th><label for="average_price">单价</label></th>
<td> <input name="average_price" id="average_price" type="text" value="" class="regular-text code"></td>
<td> <input name="average_price" id="average_price" type="text" value="{{result.average_price}}" class="regular-text code"></td>
</tr>
</tbody>
</table>
......@@ -34,44 +31,71 @@
<th><label for="from">户型</label></th>
<td>
<select id="buildproperty_id" name="buildproperty_id">
<option value="-1"> 户型</option>
{% for item in buildProperty %}
<option value="{{ item.id }}">{{ item.value }}</option>
<option {{ item.id == result.buildproperty_id?"selected":"" }} value="{{ item.id }}">{{ item.value }}</option>
{% endfor %}
</select>
</td>
</tr>
<tr>
<th><label for="covered_area">面积</label></th>
<td> <input name="covered_area" type="text" value="" class="regular-text code"></td>
<td> <input name="covered_area" type="text" value="{{result.covered_area}}" class="regular-text code"></td>
</tr>
<tr>
<th><label for="check_in_time">楼层:</label></th>
<td> <input name="floor" type="text" value="" class="regular-text code"></td>
<th><label for="floor">楼层:</label></th>
<td> <input name="floor" type="text" value="{{result.floor}}" class="regular-text code"></td>
</tr>
<tr>
<th><label for="property_age">朝向:</label></th>
<td> <input name="faceto" type="text" value="" class="regular-text code"></td>
<th><label for="faceto">朝向:</label></th>
<td> <input name="faceto" type="text" value="{{result.faceto}}" class="regular-text code"></td>
</tr>
<tr>
<th><label for="decoration">装修状况</label></th>
<td> <input name="decoration" type="text" value="" class="regular-text code"></td>
<td> <input name="decoration" type="text" value="{{result.decoration}}" class="regular-text code"></td>
</tr>
<tr>
<th><label for="age">建筑年代</label></th>
<td> <input name="age" type="text" value="{{result.age}}" class="regular-text code"></td>
</tr>
<tr>
<th><label for="acreage">年代</label></th>
<td> <input name="age" type="text" value="" class="regular-text code"></td>
<th><label for="flat">楼号</label></th>
<td> <input name="flat" type="text" value="{{result.flat}}" class="regular-text code"></td>
</tr>
<tr>
<th><label for="volume_rate">楼号</label></th>
<td> <input name="flat" type="text" value="" class="regular-text code"></td>
<th><label for="suite"></label></th>
<td> <input name="suite" type="text" value="{{result.suite}}" class="regular-text code"></td>
</tr>
<tr>
<th><label for="greening_rate"></label></th>
<td> <input name="suite" type="text" value="" class="regular-text code"></td>
<th><label for="overview">房源点评</label></th>
<td> <textarea name="overview" rows="4" cols="40" class="large-text code">{{result.overview}}
</textarea></td>
</tr>
<tr>
<th><label for="property_money">房源点评</label></th>
<td> <textarea name="overview" rows="4" cols="40" class="large-text code"></textarea></td>
<th><label for="from">所属地区</label></th>
<td>
<select id="baseCity" name="baseCity">
<option value=""> 城市</option>
{% for item in city %}
<option {{ item.id == result.city_id?"selected":"" }} value="{{ item.id }}">{{ item.value }}</option>
{% endfor %}
</select>
<select id="baseAreaId" name="baseAreaId">
<option value = "">区域</option>
{% if district %}
{% for item in district %}
<option {{ item.id == result.district_id?"selected":"" }} value="{{ item.id }}">{{ item.value }}</option>
{% endfor %}
{% endif %}
</select>
<select id="basePlateId" name="basePlateId">
<option value = "">板块</option>
{% if district %}
{% for item in plate %}
<option {{ item.id == result.plate_id?"selected":"" }} value="{{ item.id }}">{{ item.value }}</option>
{% endfor %}
{% endif %}
</select>
</td>
</tr>
</tbody>
</table>
......@@ -80,19 +104,19 @@
<tbody>
<tr>
<th><label for="address">地址</label></th>
<td> <input name="address" type="text" value="" class="regular-text code"></td>
<td> <input name="address" type="text" value="{{result.address}}" class="regular-text code"></td>
</tr>
<tr>
<th><label for="address">小区名称</label></th>
<td> <input name="community_name" type="text" value="" class="regular-text code"></td>
<td> <input name="community_name" type="text" value="{{result.community_name}}" class="regular-text code"></td>
</tr>
<tr>
<th><label for="traffic">交通线路</label></th>
<td> <input name="traffic" type="text" value="" class="regular-text code"></td>
<td> <input name="traffic" type="text" value="{{result.traffic}}" class="regular-text code"></td>
</tr>
<tr>
<th><label for="periphery">周边配套</label></th>
<td> <input name="periphery" type="text" value="" class="regular-text code"></td>
<td> <input name="periphery" type="text" value="{{result.periphery}}" class="regular-text code"></td>
</tr>
</tbody>
</table>
......@@ -110,7 +134,7 @@
</td>
</tr>
<tr>
<th><label for="traffic">推荐房源</label></th>
<th><label for="recommend">推荐房源</label></th>
<td>
<div id="houseImg"></div><br />
<button type="button" class="button action" data-toggle="modal" data-target="#myModal">
......@@ -119,7 +143,7 @@
</td>
</tr>
<tr>
<th><label for="periphery">置业顾问</label></th>
<th><label for="consultant">置业顾问</label></th>
<td>
<div id="consultantImg"></div><br />
<button type="button" class="button action" data-toggle="modal" data-target="#myConsultant">
......@@ -141,6 +165,10 @@
</tbody>
</table>
<input type="text" name="type" value="2" hidden="hidden">
{% if houseId %}
<input type="text" name="houseId" value="{{houseId}}" hidden="hidden">
{% endif %}
<input type="submit" id="submit" class="button action">
</form>
......
......@@ -3,6 +3,9 @@
class Config {
//table name
const A_DISTRICT_AREA_TABLE = 'a_district_area';
const A_HOUSE_IMAGE_TABLE = 'a_house_image';
const A_HOUSE_RECOMMEND_TABLE = 'a_house_recommend';
const A_HOUSE_USER_TABLE = 'a_house_user';
const DIC_CITY_TABLE = 'dic_city';
const DIC_ROOM_TABLE = 'dic_room';
const DIC_BUILDPROPERTY_TABLE = 'dic_buildproperty';
......
......@@ -5,6 +5,9 @@ class InsertDao{
global $wpdb;
$houseRes = $wpdb->insert(Config::TOSPUR_HOUSE_TABLE, $params);
$houseId = $wpdb->insert_id;
if(!SearchDao::setHouseNumber($houseId,$params['house_type'],$params['city_id'])){
return 510;
}
if($houseRes){
return $houseId;
}else{
......
<?php
require_once(PLUGIN_DIR . 'Config.php');
class Core {
}
\ No newline at end of file
......@@ -18,6 +18,7 @@ function tospur_init()
require_once(PLUGIN_DIR . 'Admin/House.php');
require_once(PLUGIN_DIR . 'Admin/newHouseList.php');
require_once(PLUGIN_DIR . 'Admin/secHandHouse.php');
require_once(PLUGIN_DIR . 'Admin/secHandHouseList.php');
require_once('consultant_score.php');
require_once('view_house.php');
add_action('admin_menu', 'reset_menu');
......@@ -130,7 +131,8 @@ function reset_menu()
add_menu_page("sync", "同步数据", "manage_options", "1", "do_sync");
add_menu_page('nesHouseList','新房列表', 'activate_plugins', 'newHouseList', 'newHouseList', 'dashicons-menu', 6);
add_submenu_page('newHouseList', 'newHouse_title', '添加新房', 'activate_plugins', 'newHouse', 'House::init_view');
add_menu_page('secHandHouse','二手房', 'activate_plugins', 'secHandHouse', 'SecHandHouse::secHandHouse_html', 'dashicons-menu', 7);
add_menu_page('secHandHouseList','二手房列表', 'activate_plugins', 'secHandHouseList', 'secHandHouseList', 'dashicons-menu', 7);
add_submenu_page('secHandHouseList', 'newHouse_title', '添加二手房', 'activate_plugins', 'secHandHouse', 'SecHandHouse::secHandHouse_html');
//移除更新信息
remove_action( 'admin_notices', 'update_nag', 3 );
global $menu;
......
......@@ -196,6 +196,9 @@
tags.prepend('<span class="label">' + v + '</span>');
});
}
div.bind("tap",function(){
location.href = "{{site_url}}/?page=detail&hid="+value.id;
});
scroller.append(div);
});
searchData.index += 10;
......
......@@ -189,7 +189,7 @@
}
if (data_tags) {
$.each(data_tags, function (k, v) {
if(k < 3){
if (k < 3) {
tags.prepend('<span class="label">' + v + '</span>');
}
});
......
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