Commit 9af48fab by felix

每日一更

parent 5a0a2ded
......@@ -66,90 +66,97 @@ class House {
$houseid = $wpdb->insert_id;
}
//主力房源的图片与房子信息关联插入数据库
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"]
);
//插入图片表
$imgRes = $wpdb->insert('tospur_image', $insert_image_array);
if (!$imgRes) {
return 501;
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');
}
//获取插入图片的id
$imgid = $wpdb->insert_id;
//房源类型、面积与图片关联表
if($data[$key]["type"] == "0"){
$houseTypeArea = array(
$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"]
);
//插入图片表
$imgRes = $wpdb->insert('tospur_image', $insert_image_array);
if (!$imgRes) {
return 501;
}
//获取插入图片的id
$imgid = $wpdb->insert_id;
//房源类型、面积与图片关联表
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,
"buildproperty_id" => $data["$key"]["buildProperty"],
"house_area" => $data["$key"]["housearea"],
"image_id" => $imgid
'image_id' => $imgid,
);
$houseTypeAreaRes = $wpdb->insert('a_district_area', $houseTypeArea);
if (!$houseTypeAreaRes) {
return 502;
$houseImgRes = $wpdb->insert('a_house_image', $house_img_array);
if (!$houseImgRes) {
return 503;
}
} else {
return $movefile['error'];
}
//将房源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 {
return $movefile['error'];
}
}
}
//插入推荐房源id与添加新房id到关联表a_house_recommend
foreach($data["recommend"] as $value){
$a_house_recommendArray = array(
"house_id" => $houseid,
"recommend_id" =>$value
);
$a_house_recommendRes = $wpdb->insert('a_house_recommend', $a_house_recommendArray);
if(!$a_house_recommendRes){
return 504;
if(isset($data["recommend"])){
//插入推荐房源id与添加新房id到关联表a_house_recommend
foreach($data["recommend"] as $value){
$a_house_recommendArray = array(
"house_id" => $houseid,
"recommend_id" =>$value
);
$a_house_recommendRes = $wpdb->insert('a_house_recommend', $a_house_recommendArray);
if(!$a_house_recommendRes){
return 504;
}
}
}
//插入推荐置业顾问user_id与新房id到关联表a_house_recommend
foreach($data["recConsultant"] as $val){
$a_house_userArray = array(
"user_id" => $val,
"house_id" => $houseid,
"user_type" =>1
);
$a_house_userRes = $wpdb->insert('a_house_user', $a_house_userArray);
if(!$a_house_userRes){
return 505;
if($data["recConsultant"]){
//插入推荐置业顾问user_id与新房id到关联表a_house_recommend
foreach($data["recConsultant"] as $val){
$a_house_userArray = array(
"user_id" => $val,
"house_id" => $houseid,
"user_type" =>1
);
$a_house_userRes = $wpdb->insert('a_house_user', $a_house_userArray);
if(!$a_house_userRes){
return 505;
}
}
}
}
......
......@@ -377,7 +377,7 @@
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.photoType}}'));
select.append($("<option>").attr("value",{{item.id}}).append('{{item.value}}'));
{% endfor%}
var p = $("<p>").append(select).append(file).append(picDelet);
$("#picList").append(p);
......@@ -413,7 +413,7 @@
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 %}
{% for item in buildProperty %}{{item.id}}
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");
......
......@@ -2,6 +2,7 @@
class Config {
//table name
const A_DISTRICT_AREA_TABLE = 'a_district_area';
const DIC_CITY_TABLE = 'dic_city';
const DIC_ROOM_TABLE = 'dic_room';
const DIC_BUILDPROPERTY_TABLE = 'dic_buildproperty';
......@@ -12,6 +13,7 @@ class Config {
const TOSPUR_ORGANIZATION_TABLE = 'tospur_organization';
const TOSPUR_CONSULTANT = 'tospur_consultant';
const TOSPUR_HOUSE_TABLE = 'tospur_house';
const TOSPUR_IMAGE_TABLE = 'tospur_image';
//sync url
......
<?php
class dao
{
//insert 预约看房
public static function insert_view_house($house_id, $user_id, $date, $index, $time, $consultant_id)
{
$insert_view_house_array = array(
'house_id' => $house_id,
'user_id' => $user_id,
'date' => $date,
'time_index' => $index,
'time' => $time,
'consultant_id' => $consultant_id,
'handle' => 0
);
global $wpdb;
$result = $wpdb->insert('view_house', $insert_view_house_array);
return $result;
}
public static function update_view_house($id)
{
global $wpdb;
$result = $wpdb->update('view_house', array(
'handle' => 1,
'handle_date' => current_time('Y-m-d H:i:s')
), array(
'id' => $id
));
return $result;
}
public static function update_view_house_consultant($house_id, $consultant_id)
{
global $wpdb;
$result = $wpdb->update('view_house', array(
'consultant_id' => $consultant_id
), array(
'id' => $house_id
));
return $result;
}
//search 预约看房 user_id
public static function search_view_house_by_user_id($user_id)
{
global $wpdb;
$sql = "select v.house_id,v.date,v.time,v.consultant_id,v.handle from view_house v where user_id = " . $user_id . " order by v.date desc";
return $wpdb->get_results($sql);
}
//search 预约看房 consultant_id
public static function search_view_house_by_consultant_id($consultant_id)
{
global $wpdb;
$sql = "select v.id,v.house_id,v.user_id,v.date,v.time,v.handle from view_house v where consultant_id = " . $consultant_id . " order by v.date desc";
return $wpdb->get_results($sql);
}
//insert 置业顾问评分
public static function insert_consultant_score($consultant_id, $user_id, $score, $valid = 1)
{
$insert_consultant_score_array = array(
'consultant_id' => $consultant_id,
'user_id' => $user_id,
'score' => $score,
'valid' => $valid
);
global $wpdb;
$result = $wpdb->insert('tospur_consultant_score', $insert_consultant_score_array);
return $result;
}
//search 置业顾问评分
public static function search_consultant_score($consultant_id)
{
global $wpdb;
$sql = "select sum(score)/count(score) as average_score from tospur_consultant_score where consultant_id = " . $consultant_id . " and valid = 1;";
return $wpdb->get_var($sql);
}
public static function update_consultant_score($score_id, $valid)
{
global $wpdb;
$result = $wpdb->update('tospur_consultant_score', array(
'valid' => $valid
), array(
'id' => $score_id
));
return $result;
}
public static function search_tospur_verify($phone, $code)
{
global $wpdb;
$sql = "select code from tospur_verify where phone = " . $phone . " and status = 0 " .
"and create_time > NOW() - INTERVAL 30 MINUTE " .
"order by create_time desc limit 1";
return $wpdb->get_var($sql);
}
public static function insert_tospur_verify($phone, $code)
{
$insert_tospur_verify_array = array(
'phone' => $phone,
'code' => $code,
'create_time' => current_time('Y-m-d H:i:s'),
'status' => 0
);
global $wpdb;
$result = $wpdb->insert('tospur_verify', $insert_tospur_verify_array);
return $result;
}
public static function update_tospur_verify($phone)
{
global $wpdb;
$wpdb->update('tospur_verify', array(
'status' => 1
), array(
'phone' => $phone
));
}
}
<?php
define('tospur_view_house_table', 'tospur_view_house');
class dao
{
//insert 预约看房
public static function insert_view_house($house_id, $user_id, $date, $index, $time, $consultant_id)
{
$insert_view_house_array = array(
'house_id' => $house_id,
'user_id' => $user_id,
'date' => $date,
'time_index' => $index,
'time' => $time,
'consultant_id' => $consultant_id,
'handle' => 0
);
global $wpdb;
$result = $wpdb->insert(tospur_view_house_table, $insert_view_house_array);
return $result;
}
public static function update_view_house($id)
{
global $wpdb;
$result = $wpdb->update(tospur_view_house_table, array(
'handle' => 1,
'handle_date' => current_time('Y-m-d H:i:s')
), array(
'id' => $id
));
return $result;
}
public static function update_view_house_consultant($house_id, $consultant_id)
{
global $wpdb;
$result = $wpdb->update(tospur_view_house_table, array(
'consultant_id' => $consultant_id
), array(
'id' => $house_id
));
return $result;
}
//search 预约看房 user_id
public static function search_view_house_by_user_id($user_id)
{
global $wpdb;
$sql = "select v.house_id,v.date,v.time,v.consultant_id,v.handle from " . tospur_view_house_table . " v where user_id = " . $user_id . " order by v.date desc";
return $wpdb->get_results($sql);
}
//search 预约看房 consultant_id
public static function search_view_house_by_consultant_id($consultant_id)
{
global $wpdb;
$sql = "select v.id,v.house_id,v.user_id,v.date,v.time,v.handle from " . tospur_view_house_table . " v where consultant_id = " . $consultant_id . " order by v.date desc";
return $wpdb->get_results($sql);
}
//insert 置业顾问评分
public static function insert_consultant_score($consultant_id, $user_id, $score, $valid = 1)
{
$insert_consultant_score_array = array(
'consultant_id' => $consultant_id,
'user_id' => $user_id,
'score' => $score,
'valid' => $valid
);
global $wpdb;
$result = $wpdb->insert('tospur_consultant_score', $insert_consultant_score_array);
return $result;
}
//search 置业顾问评分
public static function search_consultant_score($consultant_id)
{
global $wpdb;
$sql = "select sum(score)/count(score) as average_score from tospur_consultant_score where consultant_id = " . $consultant_id . " and valid = 1;";
return $wpdb->get_var($sql);
}
public static function update_consultant_score($score_id, $valid)
{
global $wpdb;
$result = $wpdb->update('tospur_consultant_score', array(
'valid' => $valid
), array(
'id' => $score_id
));
return $result;
}
public static function search_tospur_verify($phone, $code)
{
global $wpdb;
$sql = "select code from tospur_verify where phone = " . $phone . " and status = 0 " .
"and create_time > NOW() - INTERVAL 30 MINUTE " .
"order by create_time desc limit 1";
return $wpdb->get_var($sql);
}
public static function insert_tospur_verify($phone, $code)
{
$insert_tospur_verify_array = array(
'phone' => $phone,
'code' => $code,
'create_time' => current_time('Y-m-d H:i:s'),
'status' => 0
);
global $wpdb;
$result = $wpdb->insert('tospur_verify', $insert_tospur_verify_array);
return $result;
}
public static function update_tospur_verify($phone)
{
global $wpdb;
$wpdb->update('tospur_verify', array(
'status' => 1
), array(
'phone' => $phone
));
}
public static function search_consultant_by_city($city_id, $index)
{
global $wpdb;
$consultant_sql = 'select c.*,u.display_name,s.average_score from tospur_consultant c ' .
'left join wp_users u on c.id = u.ID ' .
'left join (select consultant_id,sum(score)/count(score) as average_score from tospur_consultant_score where valid=1 group by consultant_id) s on c.id = s.consultant_id ' .
'where cityid = ' . $city_id . ' LIMIT ' . $index . ',20;';
return $wpdb->get_results($consultant_sql);
}
public static function search_house_image($house_ids)
{
$sql = 'select ahi.house_id,ti.path from a_house_image ahi' .
' left join tospur_image ti on ahi.image_id = ti.id' .
' where ti.image_type in (1,5) and house_id in ' . $house_ids . ' group by house_id';
global $wpdb;
return $wpdb->get_results($sql);
}
public static function search_house_tag($house_ids)
{
$sql = 'select aht.house_id,tt.name from a_house_tag aht' .
' left join tospur_tag tt on aht.tag_id = tt.id' .
' where house_id in ' . $house_ids;
global $wpdb;
return $wpdb->get_results($sql);
}
}
?>
\ No newline at end of file
......@@ -2,12 +2,46 @@
require_once(WP_PLUGIN_DIR."/tospur/Config.php");
$context = array();
$context['theme'] = get_template_directory_uri();
$context['siteUrl'] = get_site_url();
if(isset($_GET['hid'])){
$hid = $_GET['hid'];
$context['hid'] = $hid;
$sql = "select * from ".Config::TOSPUR_HOUSE_TABLE." where id = %d";
$result = $wpdb->get_row($wpdb->prepare($sql,$hid));
$context['result'] = $result;
$context['cityName'] = SearchDao::getCityNameWithId($result->city_id);
$mainImagesSql = "SELECT db.literal as type,ada.house_area as area,ti.path FROM ".Config::A_DISTRICT_AREA_TABLE." ada
LEFT JOIN ".Config::DIC_BUILDPROPERTY_TABLE." db on db.value = ada.buildproperty_id
LEFT JOIN ".Config::TOSPUR_IMAGE_TABLE." ti on ti.id = ada.image_id
where ada.house_id = %d";
$mainImage = $wpdb->get_results($wpdb->prepare($mainImagesSql,$hid));
$context['mainImage'] = $mainImage;
$recommendSql = "select ahi.house_id as id,ti.path from a_house_image ahi
left join tospur_image ti on ahi.image_id = ti.id
where ti.image_type in (1,5) and house_id
in (select recommend_id from a_house_recommend where house_id = %d) group by house_id";
$recommends = $wpdb->get_results($wpdb->prepare($recommendSql,$hid));
$context['recommends'] = $recommends;
$consultantSql = 'select id,name,mobile,imageUrl,s.average_score from tospur_consultant c
LEFT JOIN (select consultant_id,sum(score)/count(score) as average_score
from tospur_consultant_score
where valid=1 group by consultant_id) s on c.id = s.consultant_id
where id in(select user_id from a_house_user where user_type = 1 and house_id = %d);';
$consultant = $wpdb->get_results($wpdb->prepare($consultantSql,$hid));
$context['consultant'] = $consultant;
$imagesSql = 'select * from tospur_image ti
LEFT JOIN a_house_image ahi on ti.id = ahi.image_id
WHERE ahi.house_id = %d order by image_type;';
$images = $wpdb->get_results($wpdb->prepare($imagesSql,$hid));
$context['images'] = $images;
Timber::render('detail.html', $context);
}else{
Timber::render('error.html', $context);
......
......@@ -35,6 +35,9 @@ function page_template($template)
case 'detail':
$page = $theme . '/detail.php';
break;
case 'map':
$page = $theme . '/map.php';
break;
default:
$page = $template;
break;
......@@ -97,6 +100,7 @@ function view_house()
}
$time = (9 + $index) . ':00-' . (10 + $index) . ':00';
$result = dao::insert_view_house($_POST['house_id'], $_POST['user_id'], $date, $index, $time, $_POST['consultant_id']);
print_r($result);
$array = array();
if ($result) {
$array['code'] = 2000;
......@@ -146,4 +150,23 @@ function get_consultant_score($consultant_id)
return dao::search_consultant_score($consultant_id);
}
add_action('wp_ajax_add_collect', 'add_collect');
function add_collect($house_id){
$insert_a_house_user_array = array(
'user_id' => get_current_user_id(),
'house_id' => $_POST["hid"],
'user_type' => 0
);
global $wpdb;
$result = $wpdb->insert('a_house_user', $insert_a_house_user_array);
$array = array();
if ($result) {
$array['code'] = 2000;
} else {
$array['code'] = 2001;
}
wp_send_json($array);
}
?>
\ No newline at end of file
wp-content/themes/tospur/img/star.png

5.61 KB | W: | H:

wp-content/themes/tospur/img/star.png

7.18 KB | W: | H:

wp-content/themes/tospur/img/star.png
wp-content/themes/tospur/img/star.png
wp-content/themes/tospur/img/star.png
wp-content/themes/tospur/img/star.png
  • 2-up
  • Swipe
  • Onion skin
<?php
require_once(WP_PLUGIN_DIR."/tospur/Config.php");
$context = array();
$context['theme'] = get_template_directory_uri();
$context['siteUrl'] = get_site_url();
$context['address'] = $_GET['a'];
$context['city'] = $_GET['c'];
$context['point'] = $_GET['p'];
$context['houseName'] = $_GET['hn'];
Timber::render('map.html', $context);
?>
\ No newline at end of file
......@@ -6,7 +6,8 @@ $context['url'] = home_url();
$current_user = wp_get_current_user();
$user_id = $current_user->ID;
if ($user_id == 0) {
wp_redirect(get_site_url()."?page=login");
exit;
}else{
$date = current_time('Y-m-d');
$datetime = new DateTime($cureent_time . '+1 day');
......@@ -19,8 +20,8 @@ if ($user_id == 0) {
$context['user_id'] = $user_id;
$context['house_id'] = $_GET['house_id'];
$context['consultant_id'] = $_GET['consultant_id'];
Timber::render('view.html', $context);
}
Timber::render('view.html', $context);
?>
\ No newline at end of file
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no"/>
<style type="text/css">
body, html, #allmap {
width: 100%;
height: 100%;
overflow: hidden;
margin: 0;
font-family: "微软雅黑";
}
.hn {
margin: 10px 0 5px 0
}
</style>
<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=DhzdodNVxoDSiBzRfZod4FG8"></script>
<title>地图</title>
</head>
<body>
<div id="allmap"></div>
</body>
</html>
<script type="text/javascript">
//map.html?a=南通市城山家园&hn=城山家园</br>同普路1220号&c=南通市&p=120.890824,31.971025
// 创建Map实例
var map = new BMap.Map("allmap");
var url_address = '{{address}}';
var url_city = '{{city}}';
var url_point = '{{point}}';
var url_houseName = "<a class='hn'>{{houseName}}</a>";
if (url_point) {
var pointLng = url_point.split(',')[0];
var pointLat = url_point.split(',')[1];
fromPoint(pointLng,pointLat);
} else if (!!url_address) {
fromAddress();
}
function fromAddress() {
// 创建地址解析器实例
var myGeo = new BMap.Geocoder();
// 将地址解析结果显示在地图上,并调整地图视野
myGeo.getPoint(url_address, function (point) {
if (point) {
map.centerAndZoom(point, 18);
map.addOverlay(new BMap.Marker(point));
showinfo(point);
} else {
alert("您选择地址没有解析到结果!");
}
},url_city);
}
function fromPoint(lng,lat) {
var point = new BMap.Point(lng, lat);
map.centerAndZoom(point, 18);
map.addOverlay(new BMap.Marker(point));
showinfo(point);
}
function showinfo(point) {
var opts = {
width: 0, // 信息窗口宽度
height: 0, // 信息窗口高度
//title: "楼盘名称", // 信息窗口标题
enableCloseOnClick: false, //
offset: new BMap.Size(10, -20) //信息窗位置偏移值
}
var infoWindow = new BMap.InfoWindow(url_houseName, opts); // 创建信息窗口对象
map.openInfoWindow(infoWindow, point); //开启信息窗口
}
function getUrlParam(name) {
var reg= new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
var r = window.location.search.substr(1).match(reg);
if (r != null) return decodeURI(r[2]);
return null;
}
</script>
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