瀏覽代碼

[dev]完善系统模块

邹景立 8 年之前
父節點
當前提交
b28798ff31

+ 8 - 10
application/admin/controller/Node.php

@@ -62,9 +62,9 @@ class Node extends BasicAdmin {
             $tmp = explode('/', $thr);
             $one = $tmp[0];
             $two = "{$tmp[0]}/{$tmp[1]}";
-            $nodes[$one] = array_merge(isset($alias[$one]) ? $alias[$one] : ['node' => $one, 'title' => $thr, 'is_menu' => 0, 'is_auth' => 0], ['pnode' => '']);
-            $nodes[$two] = array_merge(isset($alias[$two]) ? $alias[$two] : ['node' => $two, 'title' => $thr, 'is_menu' => 0, 'is_auth' => 0], ['pnode' => $one]);
-            $nodes[$thr] = array_merge(isset($alias[$thr]) ? $alias[$thr] : ['node' => $thr, 'title' => $thr, 'is_menu' => 1, 'is_auth' => 0], ['pnode' => $two]);
+            $nodes[$one] = array_merge(isset($alias[$one]) ? $alias[$one] : ['node' => $one, 'title' => '', 'is_menu' => 0, 'is_auth' => 0], ['pnode' => '']);
+            $nodes[$two] = array_merge(isset($alias[$two]) ? $alias[$two] : ['node' => $two, 'title' => '', 'is_menu' => 0, 'is_auth' => 0], ['pnode' => $one]);
+            $nodes[$thr] = array_merge(isset($alias[$thr]) ? $alias[$thr] : ['node' => $thr, 'title' => '', 'is_menu' => 0, 'is_auth' => 0], ['pnode' => $two]);
         }
         $this->assign('nodes', Tools::arr2table($nodes, 'node', 'pnode'));
     }
@@ -75,15 +75,13 @@ class Node extends BasicAdmin {
     public function save() {
         if ($this->request->isPost()) {
             $post = $this->request->post();
-            foreach ($post as $key => $vo) {
-                if (stripos($key, 'title_') !== 0) {
-                    continue;
-                }
-                $node = substr($key, strlen('title_'));
-                $data = ['node' => $node, 'title' => $vo, 'is_menu' => intval(!empty($post["menu_{$node}"])), 'is_auth' => intval(!empty($post["auth_{$node}"]))];
+            if (isset($post['name']) && isset($post['value'])) {
+                $nameattr = explode('.', $post['name']);
+                $field = array_shift($nameattr);
+                $data = ['node' => join(',', $nameattr), $field => $post['value']];
                 Data::save($this->table, $data, 'node');
+                $this->success('参数保存成功!', '');
             }
-            $this->success('参数保存成功!', '');
         } else {
             $this->error('访问异常,请重新进入...');
         }

+ 97 - 1
application/admin/controller/User.php

@@ -15,6 +15,8 @@
 namespace app\admin\controller;
 
 use controller\BasicAdmin;
+use library\Data;
+use think\Db;
 
 /**
  * 系统用户管理控制器
@@ -25,10 +27,104 @@ use controller\BasicAdmin;
  */
 class User extends BasicAdmin {
 
+    /**
+     * 指定当前数据表
+     * @var string
+     */
     protected $table = 'SystemUser';
 
     public function index() {
-        parent::_list($this->table);
+        $this->title = '用户管理';
+        $db = Db::name($this->table)->where('is_deleted', '0');
+        parent::_list($db);
+    }
+
+    /**
+     * 用户添加
+     */
+    public function add() {
+        return $this->_form($this->table, 'form');
+    }
+
+    /**
+     * 用户编辑
+     */
+    public function edit() {
+        return $this->add();
+    }
+
+    /**
+     * 用户密码修改
+     */
+    public function pass() {
+        if (in_array('10000', explode(',', $this->request->post('id')))) {
+            $this->error('系统超级账号禁止操作!');
+        }
+        if ($this->request->isGet()) {
+            return $this->_form($this->table, 'pass');
+        }
+        $data = $this->request->post();
+        if ($data['password'] !== $data['repassword']) {
+            $this->error('两次输入的密码不一致!');
+        }
+        if (Data::save($this->table, ['id' => $data['id'], 'password' => md5($data['password'])], 'id')) {
+            $this->success('密码修改成功,下次请使用新密码登录!', '');
+        } else {
+            $this->error('密码修改失败,请稍候再试!');
+        }
+    }
+
+    /**
+     * 表单数据默认处理
+     * @param type $data
+     */
+    public function _form_filter(&$data) {
+        if ($this->request->isPost()) {
+            if (isset($data['id'])) {
+                unset($data['username']);
+            } elseif (Db::name($this->table)->where('username', $data['username'])->find()) {
+                $this->error('用户账号已经存在,请使用其它账号!');
+            }
+        }
+    }
+
+    /**
+     * 删除用户
+     */
+    public function del() {
+        if (in_array('10000', explode(',', $this->request->post('id')))) {
+            $this->error('系统超级账号禁止删除!');
+        }
+        if (Data::update($this->table)) {
+            $this->success("用户删除成功!", '');
+        } else {
+            $this->error("用户删除失败,请稍候再试!");
+        }
+    }
+
+    /**
+     * 用户禁用
+     */
+    public function forbid() {
+        if (in_array('10000', explode(',', $this->request->post('id')))) {
+            $this->error('系统超级账号禁止操作!');
+        }
+        if (Data::update($this->table)) {
+            $this->success("用户禁用成功!", '');
+        } else {
+            $this->error("用户禁用失败,请稍候再试!");
+        }
+    }
+
+    /**
+     * 用户禁用
+     */
+    public function resume() {
+        if (Data::update($this->table)) {
+            $this->success("用户启用成功!", '');
+        } else {
+            $this->error("用户启用失败,请稍候再试!");
+        }
     }
 
 }

+ 1 - 1
application/admin/view/auth.form.html

@@ -18,7 +18,7 @@
 
     <div class="layui-form-item text-center">
         {if isset($vo['id'])}<input type='hidden' value='{$vo.id}' name='id'/>{/if}
-        <button class="layui-btn"type='submit'>保存数据</button>
+        <button class="layui-btn" type='submit'>保存数据</button>
         <button class="layui-btn layui-btn-danger" type='button' data-confirm="确定要取消编辑吗?" data-close>取消编辑</button>
     </div>
 

+ 4 - 3
application/admin/view/auth.index.html

@@ -1,12 +1,13 @@
 {extend name='extra@admin/content' /}
 
-{block name="content"}
-
-<div class="text-right" style='margin-bottom:10px'>
+{block name="button"}
+<div class="nowrap pull-right" style="margin-top:10px">
     <button data-modal='{:url("$classuri/add")}' data-title="添加权限" class='layui-btn layui-btn-small'><i class='fa fa-plus'></i> 添加权限</button>
     <button data-update data-field='delete' data-action='{:url("$classuri/del")}' class='layui-btn layui-btn-small layui-btn-danger'><i class='fa fa-remove'></i> 删除权限</button>
 </div>
+{/block}
 
+{block name="content"}
 <form onsubmit="return false;" data-auto="" method="POST">
     <input type="hidden" value="resort" name="action"/>
     <table class="table table-hover">

+ 1 - 1
application/admin/view/menu.form.html

@@ -38,7 +38,7 @@
     <div class="hr-line-dashed"></div>
     <div class="layui-form-item text-center">
         {if isset($vo['id'])}<input type='hidden' value='{$vo.id}' name='id'/>{/if}
-        <button class="layui-btn"type='submit'>保存数据</button>
+        <button class="layui-btn" type='submit'>保存数据</button>
         <button class="layui-btn layui-btn-danger" type='button' data-confirm="确定要取消编辑吗?" data-close>取消编辑</button>
     </div>
     <script>

+ 6 - 4
application/admin/view/menu.index.html

@@ -1,11 +1,13 @@
 {extend name='extra@admin/content' /}
 
-{block name="content"}
-
-<div class="text-right" style='margin-bottom:10px'>
+{block name="button"}
+<div class="nowrap pull-right" style="margin-top:10px">
     <button data-modal='{:url("$classuri/add")}' data-title="添加菜单" class='layui-btn layui-btn-small'><i class='fa fa-plus'></i> 添加菜单</button>
     <button data-update data-field='delete' data-action='{:url("$classuri/del")}' class='layui-btn layui-btn-small layui-btn-danger'><i class='fa fa-remove'></i> 删除菜单</button>
 </div>
+{/block}
+
+{block name="content"}
 
 <form onsubmit="return false;" data-auto="" method="POST">
     <input type="hidden" value="resort" name="action"/>
@@ -35,7 +37,7 @@
                     <input name="_{$vo.id}" value="{$vo.sort}" class="list-sort-input"/>
                 </td>
                 <td class='text-center'>
-                    <i style="font-size:18px;float:right" class="{$vo.icon}"></i>
+                    <i style="font-size:18px;" class="{$vo.icon}"></i>
                 </td>
                 <td>{$vo.spl}{$vo.title}</td>
                 <td class='visible-lg'>{$vo.url}</td>

+ 61 - 53
application/admin/view/node.index.html

@@ -1,65 +1,73 @@
 {extend name='extra@admin/content' /}
 
 {block name="content"}
-
-<form onsubmit="return false;" action='{:url("$classuri/save")}' data-auto="true" method="POST">
-
-    <div class="text-right" style='margin-bottom:10px'>
-        <button type="submit" class='layui-btn layui-btn-small'><i class='fa fa-save'></i> 保存更改</button>
-    </div>
-
-    <table class="table table-hover">
-        <thead>
-            <tr>
-                <th class='text-left'>节点名称</th>
-                <th class='text-left'>节点代码</th>
-                <th class='text-left'><input data-none-auto="" data-check-target='.auth-check-box' type='checkbox'/> 权限控制</th>
-                <th class='text-left'><input data-none-auto="" data-check-target='.menu-check-box' type='checkbox'/> 可设为菜单</th>
-            </tr>
-        </thead>
-        <tbody>
-            {foreach $nodes as $key=>$vo}
-            <tr>
-                <td class="text-left nowrap" style="width:250px">
-                    {$vo.spl} &nbsp;
-                    <input class='layui-input layui-input-inline' style='height:28px;line-height:28px;width:auto' name='title.{$vo.node}' value="{$vo.title}"/>
-                </td>
-                <td class='text-left' style="width:250px">{$vo.spl}{$vo.node}</td>
-                <td class='text-left' style="width:100px">
-                    <label>
-                        {if substr_count($vo['node'],'/')==2}
-                        {notempty name='vo.is_auth'}
-                        <input name='auth.{$vo.node}' checked='checked' class="auth-check-box" type='checkbox' value='1'/>
-                        {else /}
-                        <input name='auth.{$vo.node}' class="auth-check-box" type='checkbox' value='1'/>
-                        {/notempty}
-                        权限控制
-                    </label>
-                    {/if}
-                </td>
-                <td class='text-left'>
+<table class="table table-hover">
+    <thead>
+        <tr>
+            <th style="width:20px"></th>
+            <th class='text-left'>节点</th>
+            <th class='text-left'></th>
+            <th class='text-left'></th>
+            <th>&nbsp;</th>
+        </tr>
+    </thead>
+    <tbody>
+        {foreach $nodes as $key=>$vo}
+        <tr>
+            <td style="width:20px"></td>
+            <td class='text-left nowrap'>
+                {$vo.spl}{$vo.node}
+                {if auth("$classuri/save")}
+                &nbsp;<input class='layui-input layui-input-inline title-input' style='height:28px;line-height:28px;width:auto' name='title.{$vo.node}' value="{$vo.title}"/>
+                {/if}
+            </td>
+            <td class='text-left' style="width:100px">
+                {if auth("$classuri/save")}
+                <label>
+                    {if substr_count($vo['node'],'/')==2}
+                    {notempty name='vo.is_auth'}
+                    <input name='is_auth.{$vo.node}' checked='checked' class="check-box" type='checkbox' value='1'/>
+                    {else /}
+                    <input name='is_auth.{$vo.node}' class="check-box" type='checkbox' value='1'/>
+                    {/notempty}
+                    权限控制
+                </label>
+                {/if}
+                {/if}
+            </td>
+            <td class='text-left'>
+                {if auth("$classuri/save")}
+                <label>
                     {if substr_count($vo['node'],'/')==2}
                     {notempty name='vo.is_menu'}
-                    <input name='menu.{$vo.node}' checked='checked' class='menu-check-box' type='checkbox' value='1'/>
+                    <input name='is_menu.{$vo.node}' checked='checked' class='check-box' type='checkbox' value='1'/>
                     {else/}
-                    <input name='menu.{$vo.node}' class='menu-check-box' type='checkbox' value='1'/>
+                    <input name='is_menu.{$vo.node}' class='check-box' type='checkbox' value='1'/>
                     {/notempty}
                     可设为菜单
                     {/if}
-                </td>
-            </tr>
-            {/foreach}
-        </tbody>
-    </table>
-    <script>
-        $(function () {
-            $('input[type=checkbox]').on('click', function () {
-                var checked = !!this.checked;
-                $('[name^="' + this.name + '"]').map(function () {
-                    this.checked = checked;
-                });
+                </label>
+                {/if}
+            </td>
+            <td></td>
+        </tr>
+        {/foreach}
+    </tbody>
+</table>
+{if auth("$classuri/save")}
+<script>
+    $(function () {
+        $('input.title-input').on('blur', function () {
+            $.form.load('{:url("save")}', {name: this.name, value: this.value}, 'POST', function (ret) {
+                return false;
+            });
+        });
+        $('input.check-box').on('click', function () {
+            $.form.load('{:url("save")}', {name: this.name, value: this.checked ? 1 : 0}, 'POST', function (ret) {
+                return false;
             });
         });
-    </script>
-</form>
+    });
+</script>
+{/if}
 {/block}

+ 43 - 0
application/admin/view/user.form.html

@@ -0,0 +1,43 @@
+<form class="layui-form layui-box" style='padding:25px 30px 20px 0' action="{:url()}" data-auto="true" method="post">
+
+    <div class="layui-form-item">
+        <label class="layui-form-label">用户账号</label>
+        <div class="layui-input-block">
+            {if $vo and $vo.username}
+            <input type="text" readonly="" disabled="" name="username" value='{$vo.username|default=""}' required="required" title="请输入用户名称" placeholder="请输入用户名称" class="layui-input disabled">
+            {else/}
+            <input type="text" name="username" value='{$vo.username|default=""}' required="required" title="请输入用户名称" placeholder="请输入用户名称" class="layui-input">
+            {/if}
+        </div>
+    </div>
+
+    <div class="layui-form-item">
+        <label class="layui-form-label">联系手机</label>
+        <div class="layui-input-block">
+            <input type="tel" name="phone" value='{$vo.phone|default=""}' pattern="^1[3-9][0-9]{9}$" title="请输入联系手机" placeholder="请输入联系手机" class="layui-input">
+        </div>
+    </div>
+
+    <div class="layui-form-item">
+        <label class="layui-form-label">联系邮箱</label>
+        <div class="layui-input-block">
+            <input type="text" name="mail" value='{$vo.mail|default=""}' title="请输入联系邮箱" placeholder="请输入联系邮箱" class="layui-input">
+        </div>
+    </div>
+
+    <div class="layui-form-item">
+        <label class="layui-form-label">用户描述</label>
+        <div class="layui-input-block">
+            <textarea placeholder="请输入用户描述" title="请输入用户描述" class="layui-textarea" name="desc">{$vo.desc|default=""}</textarea>
+        </div>
+    </div>
+
+    <div class="hr-line-dashed"></div>
+
+    <div class="layui-form-item text-center">
+        {if isset($vo['id'])}<input type='hidden' value='{$vo.id}' name='id'/>{/if}
+        <button class="layui-btn" type='submit'>保存数据</button>
+        <button class="layui-btn layui-btn-danger" type='button' data-confirm="确定要取消编辑吗?" data-close>取消编辑</button>
+    </div>
+
+</form>

+ 73 - 0
application/admin/view/user.index.html

@@ -0,0 +1,73 @@
+{extend name='extra@admin/content' /}
+
+{block name="button"}
+<div class="nowrap pull-right" style="margin-top:10px">
+    <button data-modal='{:url("$classuri/add")}' data-title="添加用户" class='layui-btn layui-btn-small'><i class='fa fa-plus'></i> 添加用户</button>
+    <button data-update data-field='delete' data-action='{:url("$classuri/del")}' class='layui-btn layui-btn-small layui-btn-danger'><i class='fa fa-remove'></i> 删除用户</button>
+</div>
+{/block}
+
+{block name="content"}
+<form onsubmit="return false;" data-auto="" method="POST">
+    <input type="hidden" value="resort" name="action"/>
+    <table class="table table-hover">
+        <thead>
+            <tr>
+                <th class='list-table-check-td'>
+                    <input data-none-auto="" data-check-target='.list-check-box' type='checkbox'/>
+                </th>
+                <th class='text-center'>用户账号</th>
+                <th class='text-center'>手机号</th>
+                <th class='text-center'>电子邮箱</th>
+                <th class='text-center'>登录次数</th>
+                <th class='text-center'>最后登录</th>
+                <th class='text-center'>状态</th>
+                <th class='text-center'>操作</th>
+            </tr>
+        </thead>
+        <tbody>
+            {foreach $list as $key=>$vo}
+            <tr>
+                <td class='list-table-check-td'>
+                    <input class="list-check-box" value='{$vo.id}' type='checkbox'/>
+                </td>
+                <td class='text-center'>{$vo.username}</td>
+                <td class='text-center'>{$vo.phone|default="<span style='color:#ccc'>还没有设置手机号</span>"}</td>
+                <td class='text-center'>{$vo.mail|default="<span style='color:#ccc'>还没有设置邮箱</span>"}</td>
+                <td class='text-center'>{$vo.login_num|default="<span style='color:#ccc'>从未登录</span>"}</td>
+                <td class='text-center'>{$vo.login_at|default="<span style='color:#ccc'>从未登录</span>"}</td>
+                <td class='text-center'>
+                    {if $vo.status eq 0}
+                    <span>已禁用</span>
+                    {elseif $vo.status eq 1}
+                    <span style="color:#090">使用中</span>
+                    {/if}
+                </td>
+                <td class='text-center nowrap'>
+                    {if auth("$classuri/edit")}
+                    <span class="text-explode">|</span>
+                    <a data-modal='{:url("$classuri/edit")}?id={$vo.id}' href="javascript:void(0)">编辑</a>
+                    {/if}
+                    {if auth("$classuri/edit")}
+                    <span class="text-explode">|</span>
+                    <a data-modal='{:url("$classuri/pass")}?id={$vo.id}' href="javascript:void(0)">密码</a>
+                    {/if}
+                    {if $vo.status eq 1 and auth("$classuri/forbid")}
+                    <span class="text-explode">|</span>
+                    <a data-update="{$vo.id}" data-field='status' data-value='0'data-action='{:url("$classuri/forbid")}' href="javascript:void(0)">禁用</a>
+                    {elseif auth("$classuri/resume")}
+                    <span class="text-explode">|</span>
+                    <a data-update="{$vo.id}" data-field='status' data-value='1' data-action='{:url("$classuri/resume")}' href="javascript:void(0)">启用</a>
+                    {/if}
+                    {if auth("$classuri/del")}
+                    <span class="text-explode">|</span>
+                    <a data-update="{$vo.id}" data-field='delete' data-action='{:url("$classuri/del")}' href="javascript:void(0)">删除</a>
+                    {/if}
+                </td>
+            </tr>
+            {/foreach}
+        </tbody>
+    </table>
+    {if isset($page)}<p>{$page}</p>{/if}
+</form>
+{/block}

+ 36 - 0
application/admin/view/user.pass.html

@@ -0,0 +1,36 @@
+<form class="layui-form layui-box" style='padding:25px 30px 20px 0' action="{:url()}" data-auto="true" method="post">
+
+    <div class="layui-form-item">
+        <label class="layui-form-label">用户账号</label>
+        <div class="layui-input-block">
+            {if $vo and $vo.username}
+            <input type="text" readonly="" disabled="" name="username" value='{$vo.username|default=""}' required="required" title="请输入用户名称" placeholder="请输入用户名称" class="layui-input disabled">
+            {else/}
+            <input type="text" name="username" value='{$vo.username|default=""}' required="required" title="请输入用户名称" placeholder="请输入用户名称" class="layui-input">
+            {/if}
+        </div>
+    </div>
+
+    <div class="layui-form-item">
+        <label class="layui-form-label">登录密码</label>
+        <div class="layui-input-block">
+            <input type="password" name="password" value='' pattern="^\S{1,}$" required=""  title="请输入登录密码" placeholder="请输入登录密码" class="layui-input">
+        </div>
+    </div>
+
+    <div class="layui-form-item">
+        <label class="layui-form-label">重复密码</label>
+        <div class="layui-input-block">
+            <input type="text" name="repassword" value='' pattern="^\S{1,}$" required="" title="请输入重复密码" placeholder="请输入重复密码" class="layui-input">
+        </div>
+    </div>
+
+    <div class="hr-line-dashed"></div>
+
+    <div class="layui-form-item text-center">
+        {if isset($vo['id'])}<input type='hidden' value='{$vo.id}' name='id'/>{/if}
+        <button class="layui-btn" type='submit'>保存数据</button>
+        <button class="layui-btn layui-btn-danger" type='button' data-confirm="确定要取消编辑吗?" data-close>取消编辑</button>
+    </div>
+
+</form>

+ 1 - 7
application/extra/view/admin.content.html

@@ -2,16 +2,10 @@
     {if isset($title)}
     <div class="ibox-title">
         <h5>{$title}</h5>
+        {block name="button"}{/block}
     </div>
     {/if}
     <div class="ibox-content fadeInUp animated">
-        <div class="alert alert-success alert-dismissible" role="alert" style="border-radius:0">
-            <button type="button" class="close" data-dismiss="alert" aria-label="Close">
-                <span aria-hidden="true">&times;</span>
-            </button>
-            <p style="font-size:18px;padding-bottom:10px">正在闭关Coding,请随意看看!</p>
-            <p style="font-size:14px">Thank you so much.</p>        
-        </div>
         {if isset($alert)}
         <div class="alert alert-{$alert.type} alert-dismissible" role="alert" style="border-radius:0">
             <button type="button" class="close" data-dismiss="alert" aria-label="Close">

+ 40 - 7
application/index/controller/Index.php

@@ -11,18 +11,51 @@
 // +----------------------------------------------------------------------
 // | github开源项目:https://github.com/zoujingli/Think.Admin
 // +----------------------------------------------------------------------
+
 namespace app\index\controller;
 
+use library\Http;
 use think\Controller;
 use think\Db;
 
 class Index extends Controller {
 
-public function index() {
-$this->redirect('@admin');
-$version = Db::query('select version() as ver');
-$version = array_pop($version);
-$this->assign('mysql_ver', $version['ver']);
-return view();
-}
+    public function index() {
+        $this->redirect('@admin');
+        $version = Db::query('select version() as ver');
+        $version = array_pop($version);
+        $this->assign('mysql_ver', $version['ver']);
+        return view();
+    }
+
+    public function test() {
+        $DEVICE_NO = 'kdt1080126';
+        $key = '20585';
+        $content = "";
+        $content .= "^Q +http://weixin.qq.com/r/2Eg2LkzEKRFWrQhN9123";
+        $result = $this->sendSelfFormatOrderInfo($DEVICE_NO, $key, 1, $content);
+        var_dump($result);
+    }
+
+    function sendSelfFormatOrderInfo($device_no, $key, $times, $orderInfo) { // $times打印次数
+        $selfMessage = array(
+            'deviceNo'     => $device_no,
+            'printContent' => $orderInfo,
+            'key'          => $key,
+            'times'        => $times
+        );
+        $url = "http://open.printcenter.cn:8080/addOrder";
+        $options = [
+            'http' => [
+                'header'  => "Content-type: application/x-www-form-urlencoded ",
+                'method'  => 'POST',
+                'content' => http_build_query($selfMessage),
+            ],
+        ];
+        $context = stream_context_create($options);
+        $result = file_get_contents($url, false, $context);
+
+        return $result;
+    }
+
 }