Commit 768a71cc by shz

后台:

1.房源分配置业顾问功能
2.评分列表 评分验证设为有效或无效 可以批量操作
前台:置业顾问登录验证
parent f950c045
<?php
//登录
$const_login_page = home_url() . '/?page=login';
//注册
$const_register_page = home_url() . '/?page=register';
//忘记密码
$const_forget_page = home_url() . '/?page=forget';
//我的
$const_my_page = home_url() . '/?page=my';
//预约看房
$const_view_page = home_url() . '/?page=view';
//约看清单
$const_list_page = home_url() . '/?page=list';
//置业顾问 信息
$const_consultant_info_page = home_url() . '/?page=consultant_info';
//置业顾问 评分
$const_score_page = home_url() . '/?page=score';
?>
\ No newline at end of file
......@@ -2,26 +2,25 @@
$context = array();
$context['theme'] = get_template_directory_uri();
$context['url'] = home_url();
if ($_POST) {
$phone = $_POST['phone'];
$code = $_POST['code'];
$password = $_POST['password'];
$repeatPassword = $_POST['repeatPassword'];
if (!$phone) {
$context['phoneError'] = '请输入11位手机号';
} else if (!$code) {
$context['codeError'] = '请输入验证码';
} else if (!$password) {
$context['passwordError'] = '请输入新密码';
} else if (!$repeatPassword) {
$context['repeatPasswordError'] = '请输入确认密码';
} else {
$user = get_user_by('login', $phone);
if ($user) {
$search_code = dao::search_tospur_verify($phone, $code);
if ($code == $search_code) {
wp_set_password($password, $user->data->ID);
dao::update_tospur_verify($phone);
echo '成功修改密码';
} else {
$context['phoneError'] = '请输入有效的手机号';
$context['codeError'] = '请输入正确的验证码';
}
}
}
......
<?php
require_once(dirname(__FILE__) . '/dao.php');
add_filter('template_include', 'page_template');
function page_template($template)
{
......@@ -24,6 +26,12 @@ function page_template($template)
case 'list':
$page = $theme . '/list.php';
break;
case 'consultant_info':
$page = $theme . '/consultant_info.php';
break;
case 'score':
$page = $theme . '/score.php';
break;
default:
$page = $template;
break;
......@@ -31,4 +39,108 @@ function page_template($template)
return $page;
}
function generate_code()
{
$characters = '0123456789';
$charactersLength = strlen($characters);
$random = '';
for ($i = 0; $i < 4; $i++) {
$random .= $characters[rand(0, $charactersLength - 1)];
}
return $random;
}
//发送验证码
add_action('wp_ajax_send_code', 'send_code');
add_action('wp_ajax_nopriv_send_code', 'send_code');
function send_code()
{
$phone = $_POST['phone'];
$validate = (bool)$_POST['validate'];
$array = array();
if (isset($phone)) {
$user = get_user_by('login', $phone);
if (($user && $validate == 0) || (!$user && $validate == 1)) {
$array['code'] = 2002;
} else {
$code = generate_code();
$insert_result = dao::insert_tospur_verify($phone, strtolower($code));
$response = wp_remote_post('http://218.1.67.130:8988/api/NanTongWechat/MobileSendMessage' .
'?mobilePhone=' . $phone . '&VerificationCode=' . $code
);
if ($response['response']['code'] == 200) {
$array['code'] = 2000;
} else {
$array['code'] = 2001;
}
}
wp_send_json($array);
}
}
//预约看房
add_action('wp_ajax_view_house', 'view_house');
function view_house()
{
$index = $_POST['index'];
if (isset($index)) {
$date = null;
if ($_POST['day']) {
$cureent_time = current_time('Y-m-d');
$datetime = new DateTime($cureent_time . '+' . $_POST['day'] . ' day');
$date = $datetime->format('Y-m-d');
} else {
$date = $_POST['date'];
}
$time = (9 + $index) . ':00-' . (10 + $index) . ':00';
$result = dao::insert_view_house($_POST['house_id'], $_POST['user_id'], $date, $index, $time, $_POST['consultant_id']);
$array = array();
if ($result) {
$array['code'] = 2000;
} else {
$array['code'] = 2001;
}
wp_send_json($array);
}
}
//置业顾问接受 预约看房
add_action('wp_ajax_handle_view_house', 'handle_view_house');
function handle_view_house()
{
$id = $_POST['id'];
if (isset($id)) {
$result = dao::update_view_house($id);
$array = array();
if ($result) {
$array['code'] = 2000;
} else {
$array['code'] = 2001;
}
wp_send_json($array);
}
}
//添加 置业顾问 评分
add_action('wp_ajax_add_score', 'add_consultant_score');
function add_consultant_score()
{
if (isset($_POST['score'])) {
$result = dao::insert_consultant_score($_POST['consultant_id'], $_POST['user_id'], $_POST['score']);
$array = array();
if ($result) {
$array['code'] = 2000;
} else {
$array['code'] = 2001;
}
wp_send_json($array);
}
}
//置业顾问信息 评分
function get_consultant_score($consultant_id)
{
return dao::search_consultant_score($consultant_id);
}
?>
\ No newline at end of file
function sendCodeBindClick() {
$('#send').bind('click', clickSendCode);
function sendCodeBindClick(ajaxUrl, validate) {
$('#send').bind('click', {ajaxUrl: ajaxUrl, validate: validate}, clickSendCode);
}
function clickSendCode() {
if ($('#phone').val().trim()) {
var second = 60;
function clickSendCode(event) {
var ajaxUrl = event.data.ajaxUrl;
var validate = event.data.validate;
var phone = $('#phone').val().trim();
if (phone.length == 11) {
var self = $(this);
self.unbind('click');
ajaxSendCode(ajaxUrl, self, phone, validate);
} else {
$('#phone-error').text('请输入11位手机号');
}
}
function countDown(ajaxUrl, self, validate) {
var second = 60;
self.text(second + '秒后重发');
var interval = setInterval(function () {
second--;
self.text(second + '秒后重发');
if (second == 0) {
window.clearInterval(interval);
second = 60;
self.text('发送验证码');
self.bind('click', clickSendCode);
self.bind('click', {ajaxUrl: ajaxUrl, validate: validate}, clickSendCode);
}
}, 1000);
} else {
$('#phone-error').text('请输入11位手机号');
}
function ajaxSendCode(ajaxUrl, self, phone, validate) {
$.ajax({
type: 'POST',
url: ajaxUrl + '/wp-admin/admin-ajax.php/',
data: 'action=send_code&phone=' + phone + '&validate=' + validate,
success: function (data) {
switch (data.code) {
case 2000:
countDown(ajaxUrl, self, validate);
break;
case 2001:
self.bind('click', {ajaxUrl: ajaxUrl, validate: validate}, clickSendCode);
alert('发送验证码失败');
break;
case 2002:
var phoneError = $('#phone-error');
phoneError.text('请输入有效的手机号');
phoneError.removeAttr('style');
self.bind('click', {ajaxUrl: ajaxUrl, validate: validate}, clickSendCode);
break;
default:
break;
}
}
});
}
Date.prototype.Format = function (fmt) {
......
......@@ -3,6 +3,7 @@
require_once(dirname(__FILE__) . '/dao.php');
$context = array();
$context['theme'] = get_template_directory_uri();
$context['url'] = home_url();
$current_user = wp_get_current_user();
$current_user_id = $current_user->ID;
if ($current_user_id == 0) {
......@@ -13,17 +14,13 @@ if ($current_user_id == 0) {
$result = null;
switch ($role) {
case 'contributor':
$result = TospurDao::search_view_house_by_user_id($current_user_id);
$result = dao::search_view_house_by_user_id($current_user_id);
break;
case 'editor':
$result = TospurDao::search_view_house_by_consultant_id($current_user_id);
$result = dao::search_view_house_by_consultant_id($current_user_id);
break;
}
if ($result) {
foreach ($result as $item) {
$item->time = ($item->time == 0) ? '上午' : (($item->time == 1) ? '中午' : '下午');
$item->handle = ($item->handle == 0) ? '未接受' : '接受';
}
$context['result'] = $result;
} else {
$context['message'] = 'not found';
......
......@@ -16,6 +16,16 @@ if (is_user_logged_in()) {
} else if (!$password) {
$context['passwordError'] = '请输入密码';
} else {
if (strlen($phone) != 11) {
$response = wp_remote_post('http://218.1.67.130:8988/api/NanTongWechat/LoginWechat' .
'?userName=' . $phone . '&password=' . $password
);
$body = json_decode($response['body']);
$data = $body->data;
if ($data) {
$password = $data->WorkNoAndId;
}
}
$creds['user_login'] = $phone;
$creds['user_password'] = $password;
$creds['remember'] = true;
......
......@@ -21,8 +21,8 @@ if ($current_user_id == 0) {
break;
case 'editor':
$user_role = '置业顾问';
header('Location: ' . $const_list_page);
exit;
/*header('Location: ' . $const_list_page);
exit;*/
break;
case 'administrator':
$user_role = '管理员';
......
......@@ -2,31 +2,37 @@
$context = array();
$context['theme'] = get_template_directory_uri();
$context['url'] = home_url();
if ($_POST) {
$phone = $_POST['phone'];
$code = $_POST['code'];
$password = $_POST['password'];
if(!$phone){
if (!$phone) {
$context['phoneError'] = '请输入11位手机号';
}else if(!$code){
} else if (!$code) {
$context['codeError'] = '请输入验证码';
}else if(!$password){
} else if (!$password) {
$context['passwordError'] = '请输入密码';
}else{
} else {
$search_code = dao::search_tospur_verify($phone, $code);
if ($code == $search_code) {
$result = wp_create_user($phone, $password);
if (is_integer($result)) {
dao::update_tospur_verify($phone);
$creds['user_login'] = $phone;
$creds['user_password'] = $password;
$creds['remember'] = true;
echo '注册成功';
$user = wp_signon($creds, false);
if(!is_wp_error($user)){
if (!is_wp_error($user)) {
echo '自动登录,跳转页面';
}
}else{
} else {
$context['phoneError'] = '抱歉,用户名已存在';
}
} else {
$context['codeError'] = '请输入正确的验证码';
}
}
}
Timber::render('register.html', $context);
......
<?php
require_once(dirname(__FILE__) . '/dao.php');
$context = array();
$context['theme'] = get_template_directory_uri();
$context['url'] = home_url();
$current_user = wp_get_current_user();
$user_id = $current_user->ID;
if ($user_id == 0) {
$context['message'] = '请先登录';
} else if (isset($_POST['time'])) {
$house_id = $_GET['house_id'];
$consultant_id = $_GET['consultant_id'];
$date = null;
switch ($_POST['time']) {
case 0:
case 1:
case 2:
}else{
$date = current_time('Y-m-d');
break;
case 3:
case 4:
case 5:
$cureent_time = current_time('Y-m-d');
$datetime = new DateTime($cureent_time . '+1 day');
$date = $datetime->format('Y-m-d');
break;
case 6:
case 7:
case 8:
$cureent_time = current_time('Y-m-d');
$datetime = new DateTime($cureent_time . '+2 day');
$date = $datetime->format('Y-m-d');
break;
case 9:
case 10:
case 11:
$date = $_POST['date'];
break;
}
$time = $_POST['time'] % 3;
$result = TospurDao::insert_view_house($house_id, $user_id, $date, $time, $consultant_id);
if ($result) {
$context['message'] = '预约成功';
}
$context['data'] = array(
'jt' => $date,
'mt' => new DateTime($date . '+1 day'),
'ht' => $date
);
$context['user_id'] = $user_id;
$context['house_id'] = $_GET['house_id'];
$context['consultant_id'] = $_GET['consultant_id'];
}
Timber::render('view.html', $context);
......
......@@ -16,26 +16,19 @@
phone: {
required: true,
minlength: 11,
maxlength: 11
maxlength: 11,
digits: true
},
code: 'required',
password: 'required',
repeatPassword: {
required: true,
equalTo: '#password'
}
password: 'required'
},
messages: {
phone: '请输入11位手机号',
code: '请输入验证码',
password: '请输入新密码',
repeatPassword: {
required: '请输入确认密码',
equalTo: '确认密码和新密码不匹配'
}
password: '请输入新密码'
}
});
sendCodeBindClick();
sendCodeBindClick("{{ url }}", 1);
});
</script>
</head>
......@@ -63,15 +56,8 @@
</label>
</p>
<p>
<label for="repeatPassword">确认密码<br>
<input type="password" name="repeatPassword" id="repeatPassword">
<label id="repeatPassword-error" class="error" for="repeatPassword">{{ repeatPasswordError }}</label>
</label>
</p>
<p class="submit">
<input type="submit" id="register_submit" value="修改密码">
<input type="submit" id="forget_submit" value="修改密码">
</p>
</form>
</body>
......
......@@ -11,6 +11,23 @@
<script src="{{ theme }}/js/public.js"></script>
<script>
$(document).ready(function () {
$('[data-name=handle]').click(function () {
var self = $(this);
var id = self.data('id');
$.ajax({
type: 'POST',
url: '{{ url }}/wp-admin/admin-ajax.php/',
data: 'action=handle_view_house&id=' + id,
success: function (data) {
if (data.code == 2000) {
self.parent().html('已接受');
alert('接受成功');
} else {
alert('接受失败');
}
}
});
});
{% if message %}
alert('{{ message }}');
{% endif %}
......@@ -23,13 +40,26 @@
<ul>
<li>楼盘 {{ item.house_id }}</li>
<li>预约时间 {{ item.date }} {{ item.time }}</li>
<!--用户 约看清单-->
{% if item.consultant_id %}
<li>置业顾问 {{ item.consultant_id }}</li>
{% if item.handle==0 %}
<li>未接受</li>
{% else %}
<li>接受</li>
{% endif %}
{% endif %}
<!--置业顾问 约看清单-->
{% if item.user_id %}
<li>用户 {{ item.user_id }}</li>
{% if item.handle==0 %}
<li>
<button data-name="handle" data-id="{{ item.id }}">接受</button>
</li>
{% else %}
<li>已接受</li>
{% endif %}
{% endif %}
<li>{{ item.handle }}</li>
</ul>
</div>
{% endfor %}
......
......@@ -16,7 +16,8 @@
phone: {
required: true,
minlength: 11,
maxlength: 11
maxlength: 11,
digits: true
},
code: 'required',
password: 'required'
......@@ -27,7 +28,7 @@
password: '请输入密码'
}
});
sendCodeBindClick();
sendCodeBindClick("{{ url }}", 0);
});
</script>
</head>
......
......@@ -9,56 +9,89 @@
<style></style>
<script src="{{ theme }}/js/jquery.min.js"></script>
<script src="{{ theme }}/js/jquery.validate.js"></script>
<script src="{{ theme }}/js/date-selector.js"></script>
<script src="{{ theme }}/js/public.js"></script>
<script>
$(document).ready(function () {
var date = new Date().Format('yyyy-MM-dd');
$('#date').val(date);
$('#viewForm').validate({
var ds = new DateSelector('year', 'month', 'day', {
MaxYear: new Date().getFullYear() + 1,
onChange: function () {
$('#date').val(this.Year + '-' + this.Month + '-' + this.Day);
}
});
ds.onChange();
var viewForm = $('#viewForm');
viewForm.validate({
rules: {
time: 'required'
},
messages: {
time: '请选择时间'
},
errorPlacement: function(error, element) {
error.appendTo('body');
errorPlacement: function (error, element) {
console.log(error);
console.log(element);
alert('请选择时间');
}
});
viewForm.submit(function () {
$.ajax({
type: 'POST',
url: '{{ url }}/wp-admin/admin-ajax.php/',
data: 'action=view_house&' + viewForm.serialize(),
success: function (data) {
if (data.code == 2000) {
alert('预约成功');
} else {
alert('预约失败');
}
}
});
{% if message %}
alert('{{ message }}');
{% endif %}
return false;
});
});
</script>
</head>
<body>
<form id="viewForm" method="post">
<div>
<p>今天</p>
<input type="radio" name="time" id="js" value="0"/><label for="js">上午</label>
<input type="radio" name="time" id="jz" value="1"/><label for="jz">中午</label>
<input type="radio" name="time" id="jx" value="2"/><label for="jx">下午</label>
</div>
<div>
<p>明天</p>
<input type="radio" name="time" id="ms" value="3"/><label for="ms">上午</label>
<input type="radio" name="time" id="mz" value="4"/><label for="mz">中午</label>
<input type="radio" name="time" id="mx" value="5"/><label for="mx">下午</label>
<label for="jt">今天</label>
<input type="radio" name="day" id="jt" value="0"/>
<label for="mt">明天</label>
<input type="radio" name="day" id="mt" value="1"/>
<label for="ht">后天</label>
<input type="radio" name="day" id="ht" value="2"/>
</div>
<div>
<p>后天</p>
<input type="radio" name="time" id="hs" value="6"/><label for="hs">上午</label>
<input type="radio" name="time" id="hz" value="7"/><label for="hz">中午</label>
<input type="radio" name="time" id="hx" value="8"/><label for="hx">下午</label>
<p>指定日期</p>
<p>
<label for="year"></label>
<select id="year"></select>
<label for="month"></label>
<select id="month"></select>
<label for="day"></label>
<select id="day"></select>
</p>
</div>
<div>
<p><label for="date">指定时间</label></p>
<p><input type="date" name="date" id="date"></p>
<input type="radio" name="time" id="zs" value="9"/><label for="zs">上午</label>
<input type="radio" name="time" id="zz" value="10"/><label for="zz">中午</label>
<input type="radio" name="time" id="zx" value="11"/><label for="zx">下午</label>
<label for="index">选择时间</label>
<select id="index" name="index">
<option value="0">9:00-10:00</option>
<option value="1">10:00-11:00</option>
<option value="2">11:00-12:00</option>
<option value="3">12:00-13:00</option>
<option value="4">13:00-14:00</option>
<option value="5">14:00-15:00</option>
<option value="6">15:00-16:00</option>
<option value="7">16:00-17:00</option>
</select>
</div>
<input type="hidden" name="date" id="date" value="">
<input type="hidden" name="user_id" value="{{ user_id }}">
<input type="hidden" name="house_id" value="{{ house_id }}">
<input type="hidden" name="consultant_id" value="{{ consultant_id }}">
<p class="submit">
<input type="submit" id="view_submit" value="提交">
......
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