连续复制
一键复制
一键打包

使用方法:php think code 表 模块儿 路径

code

sys.php

<?php

use app\code\command\Controller;
use think\Console;

$app = app();

if ($app->request->isCli()) {
    // 动态注册操作指令
    Console::starting(function (Console $console) {
        $console->addCommand(Controller::class);
    });
} else {

}

tpl

index_search.html
<fieldset>换行位置
    <legend>条件搜索</legend>换行位置
    <form action="{literal}{:request()->url()}{/literal}" autocomplete="off" class="layui-form layui-form-pane form-search" method="get" onsubmit="return false">
        {foreach $info['columns'] as $k=>$v}换行位置
        <div class="layui-form-item layui-inline">换行位置
            <label class="layui-form-label">{$v['COLUMN_COMMENT']}</label>换行位置
            {if in_array($v['COLUMN_NAME'],$info['search']['like'])}<label class="layui-input-inline">换行位置
                <input class="layui-input" name="{$v['COLUMN_NAME']}" placeholder="请输入{$v['COLUMN_COMMENT']}" value="{literal}{$get.{/literal}{$v['COLUMN_NAME']}{literal}|default=''}{/literal}">换行位置
            </label>换行位置
            {elseif in_array($v['COLUMN_NAME'],$info['search']['equal']) /}
            <label class="layui-input-inline">
            <select class="layui-select" name="{$v['COLUMN_NAME']}">换行位置
                <option value=''>-- 全部 --</option>换行位置
                {literal}{foreach ['0','1'] as $k=>$v}{/literal}换行位置
                {literal}{if $k.'' eq input('{/literal}{$v['COLUMN_NAME']}{literal}')}{/literal}换行位置
                <option selected value="{literal}{$k}{/literal}">{literal}{$v}{/literal}</option>换行位置
                {literal}{else}{/literal}换行位置
                <option value="{literal}{$k}{/literal}">{literal}{$v}{/literal}</option>换行位置
                {literal}{/if}{/literal}{literal}{/foreach}{/literal}换行位置
            </select>
            </label>
            {elseif  in_array($v['COLUMN_NAME'],$info['search']['between']) /}
                <label class="layui-input-inline">
                    <input class="layui-input" data-date-range name="{$v['COLUMN_NAME']}" placeholder="请选择{$v['COLUMN_COMMENT']}" value="{literal}{$get.{/literal}{$v['COLUMN_NAME']}{literal}|default=''}{/literal}">换行位置
                </label>换行位置
            {else /}
                <label class="layui-input-inline">换行位置
                    <input class="layui-input" name="{$v['COLUMN_NAME']}" placeholder="请输入{$v['COLUMN_COMMENT']}" value="{literal}{$get.{/literal}{$v['COLUMN_NAME']}{literal}|default=''}{/literal}">换行位置
                </label>换行位置
            {/if}
        </div>换行位置
       {/foreach}

        <div class="layui-form-item layui-inline">换行位置
            <button class="layui-btn layui-btn-primary"><i class="layui-icon">&#xe615;</i> 搜 索</button>换行位置
        </div>换行位置
    </form>换行位置
</fieldset>换行位置

form.html
<form action="{literal}{:request()->url()}{/literal}" autocomplete="off" class="layui-form layui-card" data-auto="true" method="post">换行位置
    <div class="layui-card-body padding-left-40">换行位置
    {foreach $info['columns'] as $k=>$v}
        {if $v['COLUMN_NAME']===$info['pk']}
        {literal}{notempty name='vo.id'}<input name='{/literal}{$v['COLUMN_NAME']}{literal}' type='hidden' value='{$vo.id}'>{/notempty}{/literal}换行位置
        {else/}
            {if in_array($v['COLUMN_NAME'],$info['add']['input'])}
            <label class="layui-form-item relative block">换行位置
                <span class="color-green font-w7">{$v['COLUMN_COMMENT']}</span>换行位置
                <span class="color-desc margin-left-5">{:ucwords($v['COLUMN_NAME'])}</span>换行位置
                <input class="layui-input" name="{$v['COLUMN_NAME']}" placeholder="请输入{$v['COLUMN_COMMENT']}" value="{literal}{$vo.{/literal}{$v['COLUMN_NAME']}{literal}|default=''}{/literal}"/>换行位置
                <span class="help-block"><b>提示,</b>请填写{$v['COLUMN_COMMENT']}</span>换行位置
            </label>换行位置
            {elseif in_array($v['COLUMN_NAME'],$info['add']['time']) /}换行位置
            <label class="layui-form-item relative block">换行位置
                <span class="color-green font-w7">{$v['COLUMN_COMMENT']}</span>换行位置
                <span class="color-desc margin-left-5">{:ucwords($v['COLUMN_NAME'])}</span>换行位置
                <input placeholder='请选择{$v['COLUMN_NAME']}' id="{$v['COLUMN_NAME']}" name='{$v['COLUMN_NAME']}' class="layui-input"
                       value='{literal}{$vo.{/literal}{$v['COLUMN_NAME']}{literal}|default=date("Y-m-d H:i:s")}{/literal}'>换行位置
                <script>{literal}layui.laydate.render({ elem: '#{/literal}{$v['COLUMN_NAME']}{literal}', type: "datetime" });{/literal}</script>换行位置
                <span class="help-block"><b>提示,</b>请填写{$v['COLUMN_COMMENT']}</span>换行位置
            </label>换行位置
            {elseif in_array($v['COLUMN_NAME'],$info['add']['select']) /}
                <label class="layui-form-item relative block">换行位置
                    <span class="color-green font-w7">{$v['COLUMN_COMMENT']}</span>换行位置
                    <span class="color-desc margin-left-5">{:ucwords($v['COLUMN_NAME'])}</span>换行位置
                    <select class="layui-select" name="{$v['COLUMN_NAME']}">换行位置
                        <option value=''>-- 全部 --</option>换行位置
                        {literal}{foreach ['0','1'] as $k=>$v}{/literal}换行位置
                        {literal}{if $k.'' eq input('{/literal}{$v['COLUMN_NAME']}{literal}')}{/literal}
                        <option selected value="{literal}{$k}{/literal}">{literal}{$v}{/literal}</option>换行位置
                        {literal}{else}{/literal}
                        <option value="{literal}{$k}{/literal}">{literal}{$v}{/literal}</option>换行位置
                        {literal}{/if}{/literal}{literal}{/foreach}{/literal}
                    </select>换行位置
                    <span class="help-block"><b>提示,</b>请填写{$v['COLUMN_COMMENT']}</span>换行位置
                </label>换行位置
            {elseif  in_array($v['COLUMN_NAME'],$info['add']['text']) /}
            <label class="layui-form-item relative block">换行位置
                <span class="color-green font-w7">{$v['COLUMN_COMMENT']}</span>换行位置
                <span class="color-desc margin-left-5">{:ucwords($v['COLUMN_NAME'])}</span>换行位置
                <textarea placeholder="请输入{$v['COLUMN_COMMENT']}" class="layui-textarea" name="{$v['COLUMN_NAME']}">{literal}{$vo.{/literal}{$v['COLUMN_NAME']}{literal}|default=""}{/literal}</textarea>换行位置
                <span class="help-block"><b>提示,</b>请填写{$v['COLUMN_COMMENT']}</span>换行位置
            </label>换行位置
            {elseif  in_array($v['COLUMN_NAME'],$info['add']['pic']) /}
                <label class="layui-form-item relative block">换行位置
                    <span class="color-green font-w7">{$v['COLUMN_COMMENT']}</span>换行位置
                    <span class="color-desc margin-left-5">{:ucwords($v['COLUMN_NAME'])}</span>换行位置
                    {literal}<input name="{/literal}{$v['COLUMN_NAME']}{literal}" type="hidden" value="{$vo.{/literal}{$v['COLUMN_NAME']}{literal}|default=''}">{/literal}换行位置
                    {literal}<script>$('[name="{/literal}{$v['COLUMN_NAME']}{literal}"]').uploadOneImage();</script>{/literal}换行位置
                </label>换行位置
            {else /}
                <label class="layui-form-item relative block">换行位置
                    <span class="color-green font-w7">{$v['COLUMN_COMMENT']}</span>换行位置
                    <span class="color-desc margin-left-5">{:ucwords($v['COLUMN_NAME'])}</span>换行位置
                    <input class="layui-input" name="{$v['COLUMN_NAME']}" placeholder="请输入{$v['COLUMN_COMMENT']}" value="{/literal}{literal}{$vo.{/literal}{$v['COLUMN_NAME']}{literal}|default=''}{/literal}{literal}"/>换行位置
                    <span class="help-block"><b>提示,</b>请填写{$v['COLUMN_COMMENT']}</span>换行位置
                </label>换行位置
            {/if}
        {/if}
    {/foreach}
    </div>换行位置
    <div class="hr-line-dashed"></div>换行位置
    <div class="layui-form-item text-center">换行位置
        <button class="layui-btn" type='submit'>保存数据</button>换行位置
        <button class="layui-btn layui-btn-danger" data-close data-confirm="确定要取消编辑吗?" type='button'>取消编辑</button>换行位置
    </div>换行位置
</form>换行位置

{block name='script'}
{literal} <script>
        window.form.render();
        // require 'angular','ckeditor'
        // ckeditor:window.createEditor('[name=content]', {height: 300});
        require(['angular'], function () {

        });
    </script>
{/literal}
{/block}
controller.php
<>?php
namespace {$info["namespaceController"]};
use  {$info["namespaceModel"]}\{$info['modelName']} as Model{$info['modelName']};换行位置
use think\admin\Controller;
/**
* {$info["text"]}管理
* Class {$info['controllerName']}换行位置
* @package {$info["namespaceController"]}\{$info['controllerName']}换行位置
*/
class {$info['controllerName']} extends Controller
{
    /**
    * {$info["text"]}管理
    * @auth true
    * @throws \think\db\exception\DataNotFoundException
    * @throws \think\db\exception\DbException
    * @throws \think\db\exception\ModelNotFoundException
    */
    public function index()
    {
    $this->title = '{$info["text"]}管理';
    $query = Model{$info['modelName']}::mQuery();
    $query->like('{:implode(",",$info["search"]["like"])}')->equal('{:implode(",",$info["search"]["equal"])}')->dateBetween('{:implode(",",$info["search"]["between"])}');
    $query->order('id desc')->page();
    }

    /**
    * 添加{$info["text"]}换行位置
    * @auth true
    */
    public function add()
    {
      Model{$info['modelName']}::mForm('form');
    }

    /**
    * 列表数据处理
    * @param array $data
    */
    protected function _index_page_filter(array &$data)
    {

    }

    /**
    * 表单数据处理
    * @param array $data
    */
    protected function _form_filter(array &$data)
    {
        if ($this->request->isGet()) {

        }else{

        }
    }

    /**
    * 编辑{$info["text"]}换行位置
    * @auth true
    */
    public function edit()
    {
      Model{$info['modelName']}::mForm('form');
    }

    /**
    * 修改{$info["text"]}状态
    * @auth true
    */
    public function state()
    {
      Model{$info['modelName']}::mSave($this->_vali([
        'status.in:0,1'  => '状态值范围异常!',
        'status.require' => '状态值不能为空!',
        ]));
    }

    /**
    * 删除{$info["text"]}换行位置
    * @auth true
    */
    public function remove(){
      Model{$info['modelName']}::mDelete();
    }
}
index.html
{literal}{extend name="../../admin/view/main"}

{block name="button"}
<!--{if auth("add")}-->换行位置
<button class='layui-btn layui-btn-sm layui-btn-primary' data-modal='{:url("add")}' data-title="添加{/literal}{$info['text']}{literal}">添加{/literal}{$info['text']}{literal}</button>换行位置
<!--{/if}-->换行位置

<!--{if auth("remove")}-->换行位置
<button class='layui-btn layui-btn-sm layui-btn-primary' data-action='{:url("remove")}'  data-confirm="确定批量删除{/literal}{$info['text']}{literal}吗?" data-rule="{/literal}{$info['pk']}{literal}#{{/literal}{key}{literal}}">删除{/literal}{$info['text']}{literal}</button>换行位置
<!--{/if}-->换行位置
{/block}

{block name='content'}
<div class="layui-tab layui-tab-card think-bg-white">
    <div class="layui-tab-content">
        {include file='{/literal}{:strtolower($info['controllerName'])}{literal}/index_search'}
        <table class="layui-table margin-top-10" lay-skin="line">
            {notempty name='list'}
                <thead>{/literal}{literal}
                <tr>
                    <th class='list-table-check-td think-checkbox'>
                        <label><input data-auto-none data-check-target='.list-check-box' type='checkbox'></label>
                    </th>
                    {/literal}换行位置
                    {foreach $info['columns'] as $k=>$v}
                    <th class="text-left nowrap">{$v['COLUMN_COMMENT']}</th>换行位置
                    {/foreach}
                    {literal}
                    <th class="text-left nowrap">操作</th>
                </tr>
                {/literal}
                </thead>
            {literal}{/notempty}
            <tbody>
            {foreach $list as $key=>$vo}{/literal}
                <tr data-dbclick>
                    <td class='list-table-check-td think-checkbox'>
                        <label><input class="list-check-box" type='checkbox' value='{literal}{$vo.{/literal}{$info['pk']}{literal}}{/literal}'></label>
                    </td>换行位置
                    {foreach $info['columns'] as $k=>$v}
                    {if  in_array($v['COLUMN_NAME'],$info['add']['pic']) /}
                    <td class="text-left nowrap"><div class="headimg" data-lazy-src="{literal}{$vo.{/literal}{$v['COLUMN_NAME']}{literal}}{/literal}" data-tips-image></div></td>换行位置
                    {else /}
                    <td class="text-left nowrap">{literal}{$vo.{/literal}{$v['COLUMN_NAME']}{literal}|default=''}{/literal}</td>换行位置
                    {/if}
                    {/foreach}
                    {literal}
                    <td class='text-left nowrap'>换行位置
                        <!--{if auth("edit")}-->换行位置
                        <a class="layui-btn layui-btn-sm" data-dbclick data-modal="{:url('edit')}?{/literal}{$info['pk']}{literal}={$vo.{/literal}{$info['pk']}}{literal}" data-title="编辑{/literal}{$info['text']}{literal}">编 辑</a>换行位置
                        <!--{/if}-->换行位置

                        <!--{if auth("remove")}-->换行位置
                        <a class="layui-btn layui-btn-sm layui-btn-danger" data-action="{:url('remove')}" data-confirm="确定要删除该{/literal}{$info['text']}{literal}吗?" data-value="{/literal}{$info['pk']}{literal}#{$vo.{/literal}{$info['pk']}{literal}}">删 除</a>换行位置
                        <!--{/if}-->换行位置
                    </td>
                </tr>
            {/foreach}
            </tbody>
        </table>换行位置
        {empty name='list'}<span class="notdata">没有记录哦</span>{else}{$pagehtml|raw|default=''}{/empty}
    </div>
</div>
{/block}

{block name='script'}换行位置
    <script>window.form.render()</script>换行位置
{/block}{/literal}
model.php
<>?php

namespace {$info["namespaceModel"]};

use think\admin\Model;

/**
 *
 * Class {$info['modelName']}换行位置
 * @package app\data\model
 */
class {$info['modelName']} extends Model
{

}

command

Controller.php
<?php

namespace app\code\command;

use think\admin\Command;
use think\console\Input;
use think\console\input\Argument;
use think\console\Output;
use think\View;

/**
 * 生成代码
 * Class Controller
 * @package app\data\command
 */
class Controller extends Command
{
  protected function configure()
  {
    $this->setName('code');
    $this->addArgument('table', Argument::OPTIONAL, '表名', '');
    $this->addArgument('moduleName', Argument::OPTIONAL, '模块', '');
    $this->addArgument('path', Argument::OPTIONAL, '路径', '');
    $this->setDescription('生成代码', 'table moduleName path');
  }

  //驼峰命名转下划线命名
  public function toUnderScore($str, $separatist = '/')
  {
    $dstr = preg_replace_callback('/([A-Z]+)/', function ($matchs) {
      return '/' . strtolower($matchs[0]);
    }, $str);
    return str_replace('/', $separatist, trim(preg_replace('/\/{2,}/', '/', $dstr), '/'));
  }
  /**
   * @param Input $input
   * @param Output $output
   * @return void
   * @throws \think\admin\Exception
   * @throws \think\db\exception\DataNotFoundException
   * @throws \think\db\exception\DbException
   * @throws \think\db\exception\ModelNotFoundException
   */
  protected function execute(Input $input, Output $output)
  {
    [$table, $moduleName, $path] = [$input->getArgument('table'), $input->getArgument('moduleName'), $input->getArgument('path')];

    if (empty($table)){ $this->setQueueError("示例:php think code 表 模块儿 路径");die;}
    $info = $this->getInfo($table, $moduleName, $path);
    $view = new View($this->app);
    $contentController = $view->fetch(__DIR__ . '/../tpl/controller.php', [
      'info' => $info
    ]);
    $contentController = str_replace('<>?php', '<?php', $contentController);
    $contentController = str_replace('换行位置', '', $contentController);
    $contentModel = $view->fetch(__DIR__ . '/../tpl/model.php', [
      'info' => $info
    ]);

    $contentModel = str_replace('<>?php', '<?php', $contentModel);
    $contentModel = str_replace('换行位置', '', $contentModel);
    $contentViewSearch = $view->fetch(__DIR__ . '/../tpl/index_search.html', [
      'info' => $info
    ]);
    $contentViewSearch = str_replace('换行位置', '', $contentViewSearch);
    $contentViewForm = $view->fetch(__DIR__ . '/../tpl/form.html', [
      'info' => $info
    ]);
    $contentViewForm = str_replace('换行位置', '', $contentViewForm);
    $contentViewIndex = $view->fetch(__DIR__ . '/../tpl/index.html', [
      'info' => $info
    ]);

    $contentViewIndex = str_replace('换行位置', '', $contentViewIndex);
    $pathController = __DIR__ . '/../../../' . str_replace('\\', '/', $info['namespaceController']);
    $pathModel = __DIR__ . '/../../../' . str_replace('\\', '/', $info['namespaceModel']);
    if ($path) {
      $pathView = $pathController . '/../../../' . $path . '/view/' . $moduleName . '/' .strtolower($info['controllerName']);
    } else {
      $pathView = $pathController . '/../view/' . strtolower($info['controllerName']);
    }

    $this->mkdirs($pathController);
    $this->mkdirs($pathModel);
    $this->mkdirs($pathView);
    var_dump($pathView . '/index.html');
    if (!file_exists($pathController . '/' . $info['controllerName'] . '.php'))
      file_put_contents($pathController . '/' . $info['controllerName'] . '.php', $contentController);
    else
      echo $pathController . '/' . $info['controllerName'] . '.php,文件已存在';
    if (!file_exists($pathModel . '/' . $info['modelName'] . '.php'))
      file_put_contents($pathModel . '/' . $info['modelName'] . '.php', $contentModel);
    else
      echo $pathModel . '/' . $info['modelName'] . '.php,文件已存在';
    if (!file_exists($pathView . '/index.html'))
      file_put_contents($pathView . '/index.html', $contentViewIndex);
    else
      echo $pathView . '/index.html,文件已存在';
    if (!file_exists($pathView . '/index_search.html'))
      file_put_contents($pathView . '/index_search.html', $contentViewSearch);
    else
      echo $pathView . '/index_search.html,文件已存在';
    if (!file_exists($pathView . '/form.html'))
      file_put_contents($pathView . '/form.html', $contentViewForm);
    else
      echo $pathView . '/form.html,文件已存在';
    $this->setQueueSuccess("生成代码成功");
  }

  protected function mkdirs($dir, $mode = 0777)
  {
    if (is_dir($dir) || @mkdir($dir, $mode)) return TRUE;
    if (!$this->mkdirs(dirname($dir), $mode)) return FALSE;

    return @mkdir($dir, $mode);
  }

  protected function getInfo($table, $moduleName, $path)
  {
    $database = $this->app->config->get('database.connections.mysql.database');
    $data = $this->app->db->query("select TABLE_NAME from INFORMATION_SCHEMA.TABLES where TABLE_SCHEMA='${database}' and TABLE_NAME='${table}'");
    $tableColumn = $this->app->db->query("select COLUMN_NAME,DATA_TYPE,COLUMN_COMMENT from information_schema.COLUMNS where TABLE_SCHEMA='$database' and table_name = '$table'");
    if (count($data) == 0) {
      $this->setQueueError("生成代码的数据表{$table}不存在");
    }

    $rtn = [];
    $pk = $this->app->db->name($table)->getPk();
    $rtn['pk'] = $pk ? $pk : 'id';
    $rtn['search'] = [
      'like'    => [],
      'equal'   => [],
      'between' => [],
    ];
    $rtn['add'] = [
      'pic'    => [],
      'select' => [],
      'input'  => [],
      'text'   => [],
      'time'   => [],
    ];
    $rtn['columns'] = $tableColumn;
    $columnTypeLike = [
      'varchar',
      'char',
    ];
    $columnTypeEqual = [
      'tinyint',
    ];
    $columnTypeText = [
      'text',
      'longtext',
    ];
    $columnTypeBetween = [
      'date',
      'datetime',
      'timestamp',
    ];

    foreach ($rtn['columns'] as $k => $v) {

      if (in_array($v['DATA_TYPE'], $columnTypeLike)) {
        $rtn['search']['like'][] = $v['COLUMN_NAME'];
        if (strpos($v['COLUMN_NAME'], 'pic') || strpos($v['COLUMN_NAME'], 'img') || strpos($v['COLUMN_NAME'], 'image') || strpos($v['COLUMN_NAME'], 'avatar')) {
          $rtn['add']['pic'][] = $v['COLUMN_NAME'];
        } else {
          $rtn['add']['input'][] = $v['COLUMN_NAME'];
        }
      } else if (in_array($v['DATA_TYPE'], $columnTypeEqual)) {
        $rtn['search']['equal'][] = $v['COLUMN_NAME'];
        $rtn['add']['select'][] = $v['COLUMN_NAME'];
      } else if (in_array($v['DATA_TYPE'], $columnTypeBetween)) {
        $rtn['search']['between'][] = $v['COLUMN_NAME'];
        $rtn['add']['time'][] = $v['COLUMN_NAME'];
      } else if (in_array($v['DATA_TYPE'], $columnTypeText)) {
        $rtn['add']['text'][] = $v['COLUMN_NAME'];
      } else {
        $rtn['add']['input'][] = $v['COLUMN_NAME'];
      }
    }

    // 处理控制器、模型
    $tableArr = explode('_', $table);
    $rtn['moduleName'] = $moduleName;
    if (count($tableArr) == 1) {
      $rtn['controllerName'] = ucwords($tableArr[0]);
      $rtn['modelName'] = ucwords($tableArr[0]);
    }
    if (count($tableArr) == 2) {
      $rtn['controllerName'] = ucwords($tableArr[1]);
      $rtn['modelName'] = ucwords($tableArr[0]) . ucwords($tableArr[1]);
    }
    if (count($tableArr) == 3) {
      $rtn['controllerName'] = ucwords($tableArr[1]) . $tableArr[2];
      $rtn['modelName'] = ucwords($tableArr[0]) . ucwords($tableArr[1]) . ucwords($tableArr[2]);
    }
    if (count($tableArr) == 4) {
      $rtn['controllerName'] = ucwords($tableArr[1]) . $tableArr[2] . $tableArr[3];
      $rtn['modelName'] = ucwords($tableArr[1]) . ucwords($tableArr[2]) . ucwords($tableArr[3]);
    }    

    if ($path) {
      $rtn['namespaceModel'] = "app\\" . $path . "\model";
      $rtn['namespaceController'] = "app\\" . $path . "\\controller\\" . $moduleName;
    } else {
      $rtn['namespaceModel'] = "app\\" .  $moduleName . "\model";
      $rtn['namespaceController'] = "app\\" . $moduleName . "\\controller";
    }
    $tableInfo = $this->app->db->query("show table status where name='$table'");
    $comment = explode('-', $tableInfo[0]['Comment']);
    $rtn['text'] = count($comment) > 1 ? $comment[1] : $comment[0];

    // 判断节点是否存在
    $node = $path ? $path . '/' . strtolower($moduleName).'.'.strtolower($rtn['controllerName']) . '/index' :  strtolower($moduleName).'/'.strtolower($rtn['controllerName']) . '/index';
    $nodeData = $this->app->db->table('system_menu')->where('node', $node)->where('url', $node)->find();

    if (!$nodeData) {
      $rootData = $this->app->db->table('system_menu')->where('url', 'like', "%$node%")->find();

      if ($rootData) {
        $this->app->db->table('system_menu')->insert([
          'pid'    => $rootData['pid'],
          'title'  => $rtn['text'] . '管理',
          'icon'   => '',
          'node'   => $node,
          'url'    => $node,
          'params' => '',
          'target' => '_self',
          'sort'   => 0,
          'status' => 1,
        ]);
      } else {
        $rootData = $this->app->db->table('system_menu')->where('pid', '=', 0)->where('title', $comment[0] . '管理')->where('node', '')->find();
        if (!$rootData) {
          $rootData = $this->app->db->table('system_menu')->insertGetId([
            'pid'    => 0,
            'title'  => $comment[0] . '管理',
            'icon'   => '',
            'node'   => '',
            'url'    => '',
            'params' => '',
            'target' => '_self',
            'sort'   => 0,
            'status' => 1,
          ]);
        }
        $this->app->db->table('system_menu')->insert([
          'pid'    => $rootData['id'],
          'title'  => $rtn['text'] . '管理',
          'icon'   => '',
          'node'   => $node,
          'url'    => $node,
          'params' => '',
          'target' => '_self',
          'sort'   => 0,
          'status' => 1,
        ]);
      }
    }
    //        $this->setQueueError('调试');
    return $rtn;
  }
}

目录

   └── code
       ├── sys.php
       └── tpl
               ├── index_search.html
               ├── form.html
               ├── controller.php
               ├── index.html
               ├── model.php
       └── command
               ├── Controller.php