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 @@ - - + +
- - - -