代码文件application/admin/command/Api/library/Builder.php
/** * 渲染 * @param string $template * @param array $vars * @return string */ public function render($template, $vars = []) { $docsList = $this->parse(); //小和 加入api规则到数据库 START foreach ($docsList as $main_title => $action_s) { $ci = 0; unset($main_data); $main_data['title'] = $main_title; foreach ($action_s as $method_name => $method) { if ($ci == 0) { //删除前缀/api/ 然后在删除后缀/erere/ $main_data['name'] = substr($method['route'], 5); // 删除后缀/erere $main_data['name'] = $action_name = substr($main_data['name'], 0, - (strlen($method_name) + 1)); $main_data['pid'] = 2; //api接口 $main_data['ismenu'] = 1; $main_data['status'] = 'normal'; $res_main = Db::name('user_rule')->where($main_data)->find(); if (!$res_main) { $main_data['createtime'] = time(); $main_data['updatetime'] = time(); $main_data['id'] = Db::name('user_rule')->insertGetId($main_data); } else { $main_data = $res_main; } } else { unset($data); $data['title'] = $method['title']; $data['name'] = $method['route']; $data['pid'] = $main_data['id']; $data['ismenu'] = 0; $res_sub = Db::name('user_rule')->where($data)->find(); if (!$res_sub) { $data['status'] = 'normal'; $data['createtime'] = time(); $data['updatetime'] = time(); $data['id'] = Db::name('user_rule')->insertGetId($data); } } $ci++; } } //小和 加入api规则到数据库END QQ496631085 return $this->view->display(file_get_contents($template), array_merge($vars, ['docsList' => $docsList])); }