Commit 768a71cc by shz

后台:

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