Jonlin 6 роки тому
батько
коміт
9b36c923f7

+ 80 - 0
application/admin/controller/Accounts.php

@@ -0,0 +1,80 @@
+<?php
+/**
+ * User: nickbai
+ * Date: 2017/10/23 13:33
+ * Email: 1902822973@qq.com
+ */
+namespace app\admin\controller;
+
+class Accounts extends Base
+{
+    // 用户列表
+    public function index()
+    {
+        if(request()->isAjax()){
+            $param  = input('param.');
+            $limit  = $param['pageSize'];
+            $offset = (($param['pageNumber'] - 1) * $limit);
+            $where = [];
+            if (empty($param['searchText']) === false) {
+                $where['account_name'] = $param['searchText'];
+            }
+            $result = db('accounts')->where($where)->limit($offset, $limit)->order('add_time', 'desc')->select();
+            foreach($result as $key=>$vo){
+                $result[$key]['add_time'] = date('Y-m-d H:i:s',$result[$key]['add_time']);
+                // 生成操作按钮
+                $result[$key]['operate'] = $this->makeBtn($vo['id']);
+            }
+            $return['total'] = db('accounts')->count();  //总数据
+            $return['rows'] = $result;
+            return json($return);
+        }
+        return $this->fetch();
+    }
+
+    // 重置用户密码为 123456
+    public function resetPwd()
+    {
+        if(request()->isAjax()){
+            $id = input('param.id/d');
+            $password = md5('123456' . config('salt'));
+            try{
+                db('accounts')->where('id', $id)->update(['password' => $password]);
+            }catch(\Exception $e){
+                return json(['code' => -1, 'data' => '', 'msg' => $e->getMessage()]);
+            }
+            return json(['code' => 1, 'data' => 'accounts/index', 'msg' => '重置密码成功']);
+        }
+    }
+
+    // 删除用户
+    public function delAccount()
+    {
+        if(request()->isAjax()){
+            $id = input('param.id/d');
+            try{
+                db('accounts')->where('id', $id)->delete();
+            }catch(\Exception $e){
+                return json(['code' => -1, 'data' => '', 'msg' => $e->getMessage()]);
+            }
+            return json(['code' => 1, 'data' => 'accounts/index', 'msg' => '删除客服成功']);
+        }
+    }
+
+    // 生成按钮
+    private function makeBtn($id)
+    {
+//        $operate = '<a href="' . url('Accounts/resetpwd', ['id' => $id]) . '">';
+//        $operate .= '<button type="button" class="btn btn-primary btn-sm"><i class="fa fa-paste"></i> 重置密码</button></a> ';
+
+        $operate = '<a href="javascript:resetPwd(' . $id . ')"><button type="button" class="btn btn-primary btn-sm"><i class="fa fa-paste"></i> 重置密码</button></a>';
+
+        $operate .= '<a style="margin-left:5px;" href="javascript:accountDel(' . $id . ')"><button type="button" class="btn btn-danger btn-sm">';
+        $operate .= '<i class="fa fa-trash-o"></i> 删除</button></a> ';
+
+        //$operate .= '<a href="javascript:;">';
+        //$operate .= '<button type="button" class="btn btn-info btn-sm"><i class="fa fa-institution"></i> 详情</button></a>';
+
+        return $operate;
+    }
+}

+ 2 - 2
application/admin/controller/Messages.php

@@ -16,10 +16,10 @@ class Messages extends Base
 
             $param  = input('param.');
             $limit  = $param['pageSize'];
-            $offset = (($param['pageNumber'] - 1) * $limit);
+            $offset = ($param['pageNumber'] - 1) * $limit;
             $where  = [];
             if (empty($param['searchText']) === false) {
-                $where['user_name'] = $param['searchText'];
+                $where['account_name'] = $param['searchText'];
             }
             $join   = [
                 'accounts b'      => 'a.account_id = b.id',

+ 2 - 2
application/admin/model/Accountsmessage.php

@@ -38,9 +38,9 @@ class Accountsmessage extends Model
             $result = $result->where($where);
         }
 
-        if (empty($offset) === false && empty($limit) === false) {
+        //if (empty($offset) === false && empty($limit) === false) {
             $result = $result->limit($offset, $limit);
-        }
+        //}
 
         if (empty($order) === false) {
             foreach ($order as $k => $v) {

+ 150 - 0
application/admin/view/accounts/index.html

@@ -0,0 +1,150 @@
+<!DOCTYPE html>
+<html>
+<head>
+    <meta charset="utf-8">
+    <meta name="viewport" content="width=device-width, initial-scale=1.0">
+    <title>用户列表</title>
+    <link rel="shortcut icon" href="favicon.ico">
+    <link href="__CSS__/bootstrap.min.css?v=3.3.6" rel="stylesheet">
+    <link href="__CSS__/font-awesome.min.css?v=4.4.0" rel="stylesheet">
+    <link href="__CSS__/plugins/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">
+    <link href="__CSS__/animate.min.css" rel="stylesheet">
+    <link href="__CSS__/style.min.css?v=4.1.0" rel="stylesheet">
+</head>
+<body class="gray-bg">
+<div class="wrapper wrapper-content animated fadeInRight">
+    <!-- Panel Other -->
+    <div class="ibox float-e-margins">
+        <div class="ibox-title">
+            <h5>用户列表</h5>
+        </div>
+        <div class="ibox-content">
+            <!--搜索框开始-->
+            <form id='commentForm' role="form" method="post" class="form-inline pull-right">
+                <div class="content clearfix m-b">
+                    <div class="form-group">
+                        <label>用户名称:</label>
+                        <input type="text" class="form-control" id="username" name="user_name">
+                    </div>
+                    <div class="form-group">
+                        <button class="btn btn-primary" type="button" style="margin-top:5px" id="search"><strong>搜 索</strong>
+                        </button>
+                    </div>
+                </div>
+            </form>
+            <!--搜索框结束-->
+            <div class="example-wrap">
+                <div class="example">
+                    <table id="cusTable">
+                        <thead>
+                        <th data-field="id">用户ID</th>
+                        <th data-field="account_name">用户名称</th>
+                        <th data-field="account_email">用户邮箱</th>
+                        <th data-field="account_phone">用户电话</th>
+                        <th data-field="add_time">注册时间</th>
+                        <th data-field="operate">操作</th>
+                        </thead>
+                    </table>
+                </div>
+            </div>
+            <!-- End Example Pagination -->
+        </div>
+    </div>
+</div>
+<!-- End Panel Other -->
+<script src="__JS__/jquery.min.js?v=2.1.4"></script>
+<script src="__JS__/bootstrap.min.js?v=3.3.6"></script>
+<script src="__JS__/content.min.js?v=1.0.0"></script>
+<script src="__JS__/plugins/bootstrap-table/bootstrap-table.min.js"></script>
+<script src="__JS__/plugins/bootstrap-table/bootstrap-table-mobile.min.js"></script>
+<script src="__JS__/plugins/bootstrap-table/locale/bootstrap-table-zh-CN.min.js"></script>
+<script src="__JS__/plugins/layer/layer.min.js"></script>
+<script type="text/javascript">
+    function initTable() {
+        //先销毁表格
+        $('#cusTable').bootstrapTable('destroy');
+        //初始化表格,动态从服务器加载数据
+        $("#cusTable").bootstrapTable({
+            method: "get",  //使用get请求到服务器获取数据
+            url: "{:url('accounts/index')}", //获取数据的地址
+            striped: true,  //表格显示条纹
+            pagination: true, //启动分页
+            pageSize: 10,  //每页显示的记录数
+            pageNumber:1, //当前第几页
+            pageList: [5, 10, 15, 20, 25],  //记录数可选列表
+            sidePagination: "server", //表示服务端请求
+            paginationFirstText: "首页",
+            paginationPreText: "上一页",
+            paginationNextText: "下一页",
+            paginationLastText: "尾页",
+            queryParamsType : "undefined",
+            queryParams: function queryParams(params) {   //设置查询参数
+                var param = {
+                    pageNumber: params.pageNumber,
+                    pageSize: params.pageSize,
+                    searchText:$('#username').val()
+                };
+                return param;
+            },
+            onLoadSuccess: function(res){  //加载成功时执行
+                if(111 == res.code){
+                    window.location.reload();
+                }
+                layer.msg("加载成功", {time : 1000});
+            },
+            onLoadError: function(){  //加载失败时执行
+                layer.msg("加载数据失败");
+            }
+        });
+    }
+
+    $(document).ready(function () {
+        //调用函数,初始化表格
+        initTable();
+
+        //当点击查询按钮的时候执行
+        $("#search").bind("click", initTable);
+    });
+
+    function accountDel(id){
+        layer.confirm('确认删除此用户?', {icon: 3, title:'提示'}, function(index){
+            //do something
+            $.getJSON("{:url('accounts/delAccount')}", {'id' : id}, function(res){
+                if(1 == res.code){
+                    layer.alert(res.msg, {title: '友情提示', icon: 1, closeBtn: 0}, function(){
+                        initTable();
+                    });
+                }else if(111 == res.code){
+                    window.location.reload();
+                }else{
+                    layer.alert(res.msg, {title: '友情提示', icon: 2});
+                }
+            });
+
+            layer.close(index);
+        })
+
+    }
+
+    function resetPwd(id){
+        layer.confirm('确认重置密码?', {icon: 3, title:'提示'}, function(index){
+            //do something
+            $.getJSON("{:url('accounts/resetPwd')}", {'id' : id}, function(res){
+                if(1 == res.code){
+                    layer.alert(res.msg, {title: '友情提示', icon: 1, closeBtn: 0}, function(){
+                        initTable();
+                    });
+                }else if(111 == res.code){
+                    window.location.reload();
+                }else{
+                    layer.alert(res.msg, {title: '友情提示', icon: 2});
+                }
+            });
+
+            layer.close(index);
+        })
+
+    }
+</script>
+</body>
+</html>

+ 13 - 0
application/admin/view/menu.html

@@ -114,6 +114,19 @@
     </ul>
 </li>
 
+<li class="menu">
+    <a href="#">
+        <i class="fa fa-user"></i>
+        <span class="nav-label">用户管理</span>
+        <span class="fa arrow"></span>
+    </a>
+    <ul class="nav nav-second-level">
+        <li>
+            <a class="J_menuItem" href="{:url('accounts/index')}">用户列表</a>
+        </li>
+    </ul>
+</li>
+
 <li class="menu">
     <a href="#">
         <i class="fa fa-comments-o"></i>

+ 2 - 2
application/index/controller/Email.php

@@ -13,7 +13,7 @@ class Email extends Controller
 {
     // 发送邮件
     public function email(){
-        $email=input("post.email");//获取收件人邮箱
+        $email=input("param.email/s");//获取收件人邮箱
         $mail = new PHPMailer();
         $mail->IsSMTP();
         $mail->isHTML(true);
@@ -30,7 +30,7 @@ class Email extends Controller
         session('code', $code, 1800);
         $mail->Subject = '邮箱验证';
         $mail->AddAddress($email);
-        $mail->MsgHTML('邮件内容是 <b>您的验证码是:'.$code.',30分钟内有效</b>,如果非本人操作无需理会!');
+        $mail->MsgHTML('邮箱验证码 <b>您的验证码是:'.$code.'</b>,30分钟内有效,如果非本人操作无需理会!');
 
         $res = $mail->send();
         if($res == true){

+ 10 - 4
application/index/controller/Register.php

@@ -28,6 +28,7 @@ class Register extends Controller
             $userName = input("param.user_name/s");
             $userEmail = input("param.user_email/s");
             $password = input("param.password/s");
+            $phone = input("param.phone/s");
             $emailCode = input("param.code/s");
 
             if(empty($userName)){
@@ -42,22 +43,26 @@ class Register extends Controller
                 return json(['code' => -3, 'data' => '', 'msg' => '密码不能为空']);
             }
 
+            if(empty($phone)){
+                return json(['code' => -4, 'data' => '', 'msg' => '密码不能为空']);
+            }
+
             if(empty($emailCode)){
-                return json(['code' => -4, 'data' => '', 'msg' => '验证码不能为空']);
+                return json(['code' => -5, 'data' => '', 'msg' => '验证码不能为空']);
             }
 
             if($emailCode != session('code')){
-                return json(['code' => -5, 'data' => '', 'msg' => '验证码不正确']);
+                return json(['code' => -6, 'data' => '', 'msg' => '验证码不正确']);
             }
 
             $name = db('accounts')->where('account_name', $userName)->find();
             if(!empty($name)){
-                return json(['code' => -6, 'data' => '', 'msg' => '用户名已存在']);
+                return json(['code' => -7, 'data' => '', 'msg' => '用户名已存在']);
             }
 
             $email = db('accounts')->where('account_email', $userEmail)->find();
             if(!empty($email)){
-                return json(['code' => -7, 'data' => '', 'msg' => '邮箱已存在']);
+                return json(['code' => -8, 'data' => '', 'msg' => '邮箱已存在']);
             }
 
             // 添加用户信息
@@ -65,6 +70,7 @@ class Register extends Controller
                 'account_name' => $userName,
                 'account_email' => $userEmail,
                 'password' => md5($password . config('salt')),
+                'account_phone' => $phone,
                 'status' => 1,
                 'add_time' => time(),
                 'last_login_time' => time()

+ 1 - 1
application/index/controller/User.php

@@ -57,7 +57,7 @@ class User extends Controller
 
         $userInfo = db('accounts')->where('id', $user_id)->find();
 
-        if(md5($password . session('salt')) != $userInfo['password']){
+        if(md5($password . config('salt')) != $userInfo['password']){
             return json(['code' => -3, 'data' => '', 'msg' => '原密码不正确']);
         }
 

+ 105 - 0
application/service/controller/Services.php

@@ -0,0 +1,105 @@
+<?php
+namespace app\service\controller;
+
+class Services extends Base
+{
+    public function index()
+    {
+        $token = input("param.token/s");
+        $res = model('Services')->checktoken($token);
+        if($res == -1){
+            return $res;
+        }
+        $user_id = $res;
+        //客服信息
+        $service = db('users')->where('id',$user_id )->select();
+        //print_r($service);exit;
+        $this->assign([
+            'service' => $service,
+        ]);
+
+        return $this->fetch();
+    }
+
+    // 客服信息修改
+    public function updateinfo()
+    {
+        if(request()->isPost()){
+
+            $token = input("param.token/s");
+            $res = model('Services')->checktoken($token);
+            if($res == -1){
+                return $res;
+            }
+            $user_id = $res;
+
+            //$user_id = input("param.user_id/s");
+            $user_name = input("param.user_name/s");
+            $user_job_number = input("param.user_job_number/s");
+            $user_email = input("param.user_email/s");
+            $phone = input("param.phone/s");
+
+            $username = db('users')->where('user_name', $user_name)->where('id', '<>', $user_id)->find();
+            if(!empty($username)){
+                return json(['code' => -1, 'data' => '', 'msg' => '该客服已经存在']);
+            }
+
+            $userjobnumber = db('users')->where('user_job_number', $user_job_number)->where('id', '<>', $user_id)->find();
+            if(!empty($userjobnumber)){
+                return json(['code' => -2, 'data' => '', 'msg' => '该工号已经存在']);
+            }
+
+            $useremail = db('users')->where('user_email', $user_email)->where('id', '<>', $user_id)->find();
+            if(!empty($useremail)){
+                return json(['code' => -3, 'data' => '', 'msg' => '该邮箱已经存在']);
+            }
+
+            // 更新客服信息
+            $param = [
+                'user_name' => $user_name,
+                'user_job_number' => $user_job_number,
+                'user_email' => $user_email,
+                'phone' => $phone
+            ];
+            db('users')->where('id', $user_id)->update($param);
+
+            return json(['code' => 1, 'data' => url('service/index'), 'msg' => '修改成功']);
+        }
+    }
+
+    // 客服密码修改
+    public function updatepwd()
+    {
+        if(request()->isPost()){
+
+            $token = input("param.token/s");
+            $res = model('Services')->checktoken($token);
+            if($res == -1){
+                return $res;
+            }
+            $user_id = $res;
+
+            //$user_id = input("param.user_id/s");
+            $password = input("param.password/s");
+            $new_password = input("param.new_password/s");
+
+            $user = db('users')->where('id', $user_id)->find();
+            if(empty($user)){
+                return json(['code' => -1, 'data' => '', 'msg' => '客服不存在']);
+            }else{
+                if($user['user_pwd'] != md5($password . config('salt'))){
+                    return json(['code' => -2, 'data' => '', 'msg' => '原密码不正确']);
+                }
+            }
+
+            // 更新密码
+            $param = [
+                'user_pwd' => md5($new_password . config('salt'))
+            ];
+            db('users')->where('id', $user_id)->update($param);
+
+            return json(['code' => 1, 'data' => url('service/index'), 'msg' => '密码修改成功']);
+        }
+    }
+
+}

+ 24 - 0
application/service/model/Services.php

@@ -0,0 +1,24 @@
+<?php
+namespace app\service\model;
+
+use think\Model;
+
+class Services extends Model
+{
+    //检测token
+    function checktoken($token){
+        $user = db('users')->where('token', $token)->find();
+        if(!empty($user)){
+            $time = time()-$user['expire_time'];
+            if($time<3600){
+                db('users')->where('id', $user['id'])->update(['expire_time' => time()]);
+                $user_id = explode('/',base64_decode($token))['2'];
+                return $user_id;
+            }else{
+                return -1;
+            }
+        }
+        return -1;
+    }
+
+}