From d30b63abc2d23cc7fdd6df09affeebd3832eca13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9F=8F=E5=B0=98?= Date: Tue, 17 Dec 2019 13:18:34 +0800 Subject: [PATCH] core --- application/admin/controller/Index.php | 3 +- application/admin/view/login/index.html | 2 +- application/index/controller/Base.php | 21 +++- application/index/controller/Login.php | 68 +++++------ application/index/view/login/login.html | 149 +++++++++++++++++++----- extend/Logic/KefuLogic.php | 2 +- 6 files changed, 170 insertions(+), 75 deletions(-) diff --git a/application/admin/controller/Index.php b/application/admin/controller/Index.php index b632e01..22a157b 100644 --- a/application/admin/controller/Index.php +++ b/application/admin/controller/Index.php @@ -25,7 +25,6 @@ class Index extends Base $online_kefu_num=KefuLogic::kefuCount(['online_status'=>1]); //获取当前在线游客数量 $online_visitor_num=Visitor::visitorCount(['online_status'=>1]); - //获取当天的会话次数 $service_num=VisitorService::getServiceNum(); $days= date('t'); @@ -34,7 +33,7 @@ class Index extends Base $start_time = strtotime(date('Y-m-01')); //获取本月第一天时间戳 $date=date('Y-m-d', $start_time+$i*86400); $endDate=date('Y-m-d 23:59:59',strtotime($date)); - $where1[]=['create_time','between time',[$date, $endDate]]; + $where1[0]=['create_time','between time',[$date, $endDate]]; $service_num_list[]=[ 'date'=>$date, diff --git a/application/admin/view/login/index.html b/application/admin/view/login/index.html index 818c3fb..e0abcdf 100644 --- a/application/admin/view/login/index.html +++ b/application/admin/view/login/index.html @@ -98,7 +98,7 @@ layer.msg('验证码不能为空'); return false; } - console.log(data); + $.post('/admin/Login/loginIn', data, function (res) { if (res.code == 1000) { diff --git a/application/index/controller/Base.php b/application/index/controller/Base.php index 9835725..88e65f0 100644 --- a/application/index/controller/Base.php +++ b/application/index/controller/Base.php @@ -14,11 +14,28 @@ use think\Controller; class Base extends Controller { + const SUCCESS_CODE = 1000; // 系统成功代码 + const ERROR_CODE = 1001; // 失败代码 + /** + * @var \think\Request 请求体 + */ + var $request; + /** + * @var \library\Response 响应体 + */ + var $response; + + /** + * @var boolean 是否强制登录 + */ + protected $_require_login = TRUE; public function __construct(App $app = null) { parent::__construct($app); - if( !session('kefu_name')){ - return $this->redirect('login/login'); + $this->request = request(); + $this->response = new \library\Response(); + if( $this->_require_login== TRUE && !session('kefu_name')){ + return $this->redirect('login/Login'); } } } diff --git a/application/index/controller/Login.php b/application/index/controller/Login.php index 8ecc027..226cd6d 100644 --- a/application/index/controller/Login.php +++ b/application/index/controller/Login.php @@ -12,65 +12,51 @@ namespace app\index\controller; use think\Controller; use think\Db; use think\facade\Cache; -class Login extends Controller + +class Login extends Base { + protected $_require_login = false; + public function Login() { return $this->fetch(); } - public function Logining() + public function LoginIn() { - $name = input('post.name'); + $name = input('post.username'); $password = input('post.password'); + $captcha = input('post.captcha'); + if (!captcha_check($captcha)) { + return $this->response->api('', self::ERROR_CODE, '验证码错误'); + } if (empty($name)) { - return $this->error('请输入用户名'); + return $this->response->api('', self::ERROR_CODE, '请填写客服名'); } if (empty($password)) { - return $this->error('请输入密码'); + return $this->response->api('', self::ERROR_CODE, '请填写密码'); } $kefu_info = Db::name('kefu_info')->where('kefu_name', $name)->find(); - if ($kefu_info) { - if (md5(trim($password)) != $kefu_info['kefu_password']) { - return $this->error('密码错误'); - } - session('kefu_name', $kefu_info['kefu_name']); - session('kefu_code', $kefu_info['kefu_code']); - session('kefu_avatar', $kefu_info['kefu_avatar']); - } else { - //同一个ip 限制注册3个账号 - $num = Cache::get(request()->ip()); - if ($num > 3) { - return $this->error('同一ip限制注册三个账号'); - } - - //添加客服 - $kefu_data = [ - 'kefu_code' => uniqid('kefu'), - 'kefu_name' => trim($name), - 'kefu_avatar' => '/static/common/images/kefu.jpg', - 'kefu_password' => md5(trim($password)), - 'kefu_status' => 1, - 'online_status' => 0, - 'create_time' => date('Y-m-d H:i:s'), - 'update_time' => date('Y-m-d H:i:s'), - ]; - Db::name('kefu_info')->insertGetId($kefu_data); - Db::commit(); - Cache::inc(request()->ip()); - session('kefu_name', $kefu_data['kefu_name']); - session('kefu_code', $kefu_data['kefu_code']); - session('kefu_avatar', $kefu_data['kefu_avatar']); - + if (!$kefu_info) { + return $this->response->api('', self::ERROR_CODE, '客服不存在'); } + if (strtoupper(md5($password)) != $kefu_info['kefu_password']) { + return $this->response->api('', self::ERROR_CODE, '密码错误'); + } + session('kefu_name', $kefu_info['kefu_name']); + session('kefu_code', $kefu_info['kefu_code']); + session( 'kefu_avatar', $kefu_info['kefu_avatar']); - return $this->redirect('kefu/index'); + + return $this->response->api(url('kefu/index'), self::SUCCESS_CODE, '登录成功'); } - public function logout(){ - session('kefu_name',null); + + public function logout() + { + session('kefu_name', null); session('kefu_code', null); session('kefu_avatar', null); - return $this->redirect('login/login'); + return $this->redirect('login/login'); } } diff --git a/application/index/view/login/login.html b/application/index/view/login/login.html index b938db5..54dbfc7 100644 --- a/application/index/view/login/login.html +++ b/application/index/view/login/login.html @@ -1,33 +1,126 @@ - - + + - - - - Timely客服登陆 - + + Timely在线客服系统客服登录 + + + + + + + + - + +
+ +

Timely在线客服系统客服登录

+
+ + +
+
+ + +
+
+ + + +
+
+ +
+
+ + + +
+
+ + + + //登录按钮 + form.on("submit(login)",function(data){ + data = data.field; + if (data.username == '') { + layer.msg('用户名不能为空'); + return false; + } + if (data.password == '') { + layer.msg('密码不能为空'); + return false; + } + if (data.captcha == '') { + layer.msg('验证码不能为空'); + return false; + } + $.post('/index/Login/loginIn', data, function (res) { + if (res.code == 1000) { + + layer.msg('登录成功', {icon: 1, time: 1500}, function () { + // location.replace(res.data) + window.location.href = res.data; + }); + } else { + layer.msg(res.message, {icon: 2}); + $("#captchaPic").click(); + } + }, 'json'); + + return false; + }); + + //表单输入效果 + $(".loginBody .input-item").click(function(e){ + e.stopPropagation(); + $(this).addClass("layui-input-focus").find(".layui-input").focus(); + }) + $(".loginBody .layui-form-item .layui-input").focus(function(){ + $(this).parent().addClass("layui-input-focus"); + }) + $(".loginBody .layui-form-item .layui-input").blur(function(){ + $(this).parent().removeClass("layui-input-focus"); + if($(this).val() != ''){ + $(this).parent().addClass("layui-input-active"); + }else{ + $(this).parent().removeClass("layui-input-active"); + } + }) + }) + function changeCaptcha(obj) { + $(obj).attr('src', $(obj).attr('src') + '?t=' + Math.random(100000000,999999999)); + } + diff --git a/extend/Logic/KefuLogic.php b/extend/Logic/KefuLogic.php index e806399..8694d16 100644 --- a/extend/Logic/KefuLogic.php +++ b/extend/Logic/KefuLogic.php @@ -136,7 +136,7 @@ class KefuLogic } $kf['kefu_password'] = strtoupper(md5($password)); $kf['update_time'] = date('Y-m-d H:i:s'); - return Db::name('kefu_info')->where('kefu_id', $id)->update(['kefu_password' => strtoupper(md5(config('timely.acquiesce_password')))]); + return Db::name('kefu_info')->where('kefu_id', $id)->update($kf); } catch (BaseException $be) { throw new ResponsableException($be->getMessage(), $be->getCode()); } catch (Exception $e) {