order('sort DESC,smid DESC')->select(); View::assign([ 'lists' => $lists ]); return View::fetch(); } # 菜单添加 public function menuadd() { $req = request(); if ($req->isPost()) { $data['label'] = trim(input('post.label')); if (empty($data['label'])) { Log::record('添加菜单', 0, '请输入菜单名称', '菜单管理'); $this->returnCode(1, '请输入菜单名称'); } $data['icon_class'] = trim(input('post.icon_class')); $data['sort'] = (int) trim(input('post.sort')); $data['status'] = (int) trim(input('post.status')); $data['type'] = (int) trim(input('post.type', 0)); if ($data['type'] == 1) { $data['src'] = trim(input('post.src1')); if (empty($data['src'])) { Log::record('添加菜单', 0, '请输入内部跳转地址', '菜单管理'); $this->returnCode(1, '请输入内部跳转地址'); } } else if ($data['type'] == 2) { $data['src'] = trim(input('post.src2')); if (empty($data['src'])) { Log::record('添加菜单', 0, '请输入超链接地址', '菜单管理'); $this->returnCode(1, '请输入超链接地址'); } } else { $data['src'] = ''; } // 保存菜单 $res = AdminSysMenu::insert($data); if (!$res) { Log::record('添加菜单', 0, '添加菜单失败', '菜单管理'); $this->returnCode(1, '添加菜单失败'); } // 获取新插入的菜单ID $newMenuId = AdminSysMenu::getLastInsID(); // 获取所有管理员用户组 $adminGroups = AdminUserGroup::select(); foreach ($adminGroups as $group) { // 获取现有权限 $rights = []; if (!empty($group['rights'])) { $rights = json_decode($group['rights'], true); } // 添加新菜单ID到权限列表 if (!in_array($newMenuId, $rights)) { $rights[] = $newMenuId; // 更新用户组权限 AdminUserGroup::where('group_id', $group['group_id']) ->update(['rights' => json_encode($rights)]); } } Log::record('添加菜单', 1, '', '菜单管理'); $this->returnCode(0); } else { $iconfont = ZIconfont::where('status', 1)->select(); View::assign([ 'iconfont' => $iconfont ]); return View::fetch(); } } # 菜单修改 public function menuedit() { $req = request(); if ($req->isPost()) { $smid = (int) input('post.smid'); $data['label'] = trim(input('post.label')); if (!$data['label']) { Log::record('编辑菜单', 0, '请输入菜单名称', '菜单管理'); $this->returnCode(1, '请输入菜单名称'); } $data['icon_class'] = trim(input('post.icon_class')); $data['sort'] = (int) trim(input('post.sort')); $data['status'] = (int) trim(input('post.status')); $data['type'] = (int) trim(input('post.type', 0)); if ($data['type'] == 1) { $data['src'] = trim(input('post.src1')); if (empty($data['src'])) { Log::record('编辑菜单', 0, '请输入内部跳转地址', '菜单管理'); $this->returnCode(1, '请输入内部跳转地址'); } } else if ($data['type'] == 2) { $data['src'] = trim(input('post.src2')); if (empty($data['src'])) { Log::record('编辑菜单', 0, '请输入超链接地址', '菜单管理'); $this->returnCode(1, '请输入超链接地址'); } } else { $data['src'] = ''; } // 保存用户 $res = AdminSysMenu::where('smid', $smid)->update($data); if (!$res) { Log::record('编辑菜单', 0, '修改菜单失败', '菜单管理'); $this->returnCode(1, '修改菜单失败'); } Log::record('编辑菜单', 1, '', '菜单管理'); $this->returnCode(0); } else { $smid = (int) input('get.smid'); $lists = AdminSysMenu::where('smid', $smid)->find(); $iconfont = ZIconfont::where('status', 1)->select(); View::assign([ 'lists' => $lists, 'iconfont' => $iconfont ]); return View::fetch(); } } # 菜单删除 public function menudel() { $smid = (int) input('post.smid'); $count = AdminSysMenu::where('parent_id', $smid)->count(); if ($count > 0) { Log::record('删除菜单', 0, '该菜单下还有子菜单,不能删除', '菜单管理'); $this->returnCode(1, '该菜单下还有子菜单,不能删除'); } $res = AdminSysMenu::where('smid', $smid)->delete(); if (empty($res)) { Log::record('删除菜单', 0, '删除菜单失败', '菜单管理'); $this->returnCode(1, '删除菜单失败'); } Log::record('删除菜单', 1, '', '菜单管理'); $this->returnCode(0); } # 按钮管理 public function buttoninfo() { $smid = (int) input('get.smid'); $lists = AdminSysMenu::where('parent_id', $smid)->order('sort DESC')->select()->toArray(); if (!empty($lists)) { foreach ($lists as &$v) { switch ($v['type']) { case 0: $v['type_name'] = '顶级菜单'; break; case 1: $v['type_name'] = '内部跳转'; break; case 2: $v['type_name'] = '超链接'; break; default: $v['type_name'] = '未规划类型'; break; } } } View::assign([ 'lists' => $lists, 'smid' => $smid ]); return View::fetch(); } # 按钮添加 public function buttonadd() { $req = request(); if ($req->isPost()) { $smid = (int) input('post.smid'); $data['label'] = trim(input('post.label')); if (!$data['label']) { Log::record('添加按钮', 0, '请输入按钮名称', '按钮管理'); $this->returnCode(1, '请输入按钮名称'); } $data['icon_class'] = trim(input('post.icon_class')); $data['sort'] = (int) trim(input('post.sort')); $data['status'] = (int) trim(input('post.status')); $data['type'] = (int) trim(input('post.type')); if (empty($data['type'])) { Log::record('添加按钮', 0, '请选择按钮类型', '按钮管理'); $this->returnCode(1, '请选择按钮类型'); } if ($data['type'] == 1) { $data['src'] = trim(input('post.src1')); if (empty($data['src'])) { Log::record('添加按钮', 0, '请输入内部跳转地址', '按钮管理'); $this->returnCode(1, '请输入内部跳转地址'); } } else if ($data['type'] == 2) { $data['src'] = trim(input('post.src2')); if (empty($data['src'])) { Log::record('添加按钮', 0, '请输入超链接地址', '按钮管理'); $this->returnCode(1, '请输入超链接地址'); } } $data['parent_id'] = $smid; $res = AdminSysMenu::insert($data); if (!$res) { Log::record('添加按钮', 0, '添加按钮失败', '按钮管理'); $this->returnCode(1, '添加按钮失败'); } Log::record('添加按钮', 1, '', '按钮管理'); $this->returnCode(0); } else { $smid = (int) input('get.smid'); $iconfont = ZIconfont::where('status', 1)->select(); View::assign([ 'smid' => $smid, 'iconfont' => $iconfont ]); return View::fetch(); } } # 按钮修改 public function buttonedit() { $req = request(); if ($req->isPost()) { $smid = (int) input('post.smid'); $data['label'] = trim(input('post.label')); if (!$data['label']) { Log::record('编辑按钮', 0, '请输入按钮名称', '按钮管理'); $this->returnCode(1, '请输入按钮名称'); } $data['icon_class'] = trim(input('post.icon_class')); $data['sort'] = (int) trim(input('post.sort')); $data['status'] = (int) trim(input('post.status')); $data['type'] = (int) trim(input('post.type')); if (empty($data['type'])) { Log::record('编辑按钮', 0, '请选择按钮类型', '按钮管理'); $this->returnCode(1, '请选择按钮类型'); } if ($data['type'] == 1) { $data['src'] = trim(input('post.src1')); if (empty($data['src'])) { Log::record('编辑按钮', 0, '请输入内部跳转地址', '按钮管理'); $this->returnCode(1, '请输入内部跳转地址'); } } else if ($data['type'] == 2) { $data['src'] = trim(input('post.src2')); if (empty($data['src'])) { Log::record('编辑按钮', 0, '请输入超链接地址', '按钮管理'); $this->returnCode(1, '请输入超链接地址'); } } $res = AdminSysMenu::where('smid', $smid)->update($data); if (!$res) { Log::record('编辑按钮', 0, '修改按钮失败', '按钮管理'); $this->returnCode(1, '修改按钮失败'); } Log::record('编辑按钮', 1, '', '按钮管理'); $this->returnCode(0); } else { $smid = (int) input('get.smid'); $lists = AdminSysMenu::where('smid', $smid)->find(); $iconfont = ZIconfont::where('status', 1)->select(); View::assign([ 'lists' => $lists, 'iconfont' => $iconfont ]); return View::fetch(); } } # 按钮删除 public function buttondel() { $smid = (int) input('post.smid'); $res = AdminSysMenu::where('smid', $smid)->delete(); if (empty($res)) { Log::record('删除按钮', 0, '删除按钮失败', '按钮管理'); $this->returnCode(1, '删除按钮失败'); } Log::record('删除按钮', 1, '', '按钮管理'); $this->returnCode(0); } # 配置列表 public function configlist() { $req = request(); if ($req->isPost()) { $page = (int) input('post.page', 1); $limit = (int) input('post.limit', $this->config['admin_page']); $count = AdminConfig::count(); $lists = AdminConfig::page($page, $limit)->order('config_sort DESC,config_id DESC')->select(); $this->returnCode(0, $lists, $count); } else { return View::fetch(); } } # 配置添加 public function configadd() { $req = request(); if ($req->isPost()) { $data['config_name'] = trim(input('post.config_name')); if (empty($data['config_name'])) { Log::record('添加配置', 0, '请输入关键词', '系统配置'); $this->returnCode(1, '请输入关键词'); } $data['config_info'] = trim(input('post.config_info')); if (empty($data['config_info'])) { Log::record('添加配置', 0, '请输入作用', '系统配置'); $this->returnCode(1, '请输入作用'); } $data['config_type'] = trim(input('post.config_type')); $data['config_desc'] = trim(input('post.config_desc')); $data['config_status'] = trim(input('post.config_status')); $data['config_sort'] = trim(input('post.config_sort')); $res = AdminConfig::insert($data); if (empty($res)) { Log::record('添加配置', 0, '添加配置失败', '系统配置'); $this->returnCode(1, '添加配置失败'); } Log::record('添加配置', 1, '', '系统配置'); $this->returnCode(0); } else { return View::fetch(); } } # 配置修改 public function configedit() { $req = request(); if ($req->isPost()) { $config_id = (int) input('post.config_id'); if (empty($config_id)) { Log::record('编辑配置', 0, '请选择一条数据', '系统配置'); $this->returnCode(1, '请选择一条数据'); } $data['config_name'] = trim(input('post.config_name')); if (empty($data['config_name'])) { Log::record('编辑配置', 0, '请输入关键词', '系统配置'); $this->returnCode(1, '请输入关键词'); } $data['config_info'] = trim(input('post.config_info')); if (empty($data['config_info'])) { Log::record('编辑配置', 0, '请输入作用', '系统配置'); $this->returnCode(1, '请输入作用'); } $data['config_type'] = trim(input('post.config_type')); $data['config_desc'] = trim(input('post.config_desc')); $data['config_status'] = trim(input('post.config_status')); $data['config_sort'] = trim(input('post.config_sort')); $res = AdminConfig::where('config_id', $config_id)->update($data); if (empty($res)) { Log::record('编辑配置', 0, '修改配置失败', '系统配置'); $this->returnCode(1, '修改配置失败'); } Log::record('编辑配置', 1, '', '系统配置'); $this->returnCode(0); } else { $config_id = (int) input('get.config_id'); $find = AdminConfig::where('config_id', $config_id)->find(); View::assign([ 'find' => $find ]); return View::fetch(); } } # 配置删除 public function configdel() { $config_id = (int) input('post.config_id'); if (empty($config_id)) { Log::record('删除配置', 0, '请选择一条数据', '系统配置'); $this->returnCode(1, '请选择一条数据'); } $res = AdminConfig::where('config_id', $config_id)->delete(); if (empty($res)) { Log::record('删除配置', 0, '删除配置失败', '系统配置'); $this->returnCode(1, '删除配置失败'); } Log::record('删除配置', 1, '', '系统配置'); $this->returnCode(0); } # 配置值 public function configvalue() { $req = request(); if ($req->isPost()) { $post = input('post.'); if (empty($post)) { Log::record('更新配置值', 0, '数据不能为空', '系统配置'); $this->returnCode(1, '数据不能为空'); } // 获取所有配置项,检查 config_type 为 4 的项 $allConfigs = AdminConfig::order('config_sort DESC,config_id')->select(); foreach ($allConfigs as $config) { if ($config['config_type'] == 4) { $checkboxName = $config['config_name'] . '_checkbox'; $configName = $config['config_name']; if (!isset($post[$checkboxName])) { // 复选框未选中,手动添加对应的值为 0 $post[$configName] = 0; } else { // 复选框选中,确保值为 1 $post[$configName] = 1; } // 移除 checkbox 字段 unset($post[$checkboxName]); } } $oConfig = new YzAdminConfig(); $updateAll = $oConfig->updateAll($post); if (empty($updateAll)) { Log::record('更新配置值', 0, '更新配置值失败', '系统配置'); $this->returnCode(1, '更新配置值失败'); } Log::record('更新配置值', 1, '', '系统配置'); $this->returnCode(0); } else { $lists = AdminConfig::order('config_sort DESC,config_id')->select(); View::assign([ 'lists' => $lists ]); return View::fetch(); } } // 邮件配置 public function mailconfig() { if (Request::isPost()) { $data = [ 'smtp_host' => input('post.smtp_host'), 'smtp_port' => input('post.smtp_port'), 'smtp_email' => input('post.smtp_email'), 'smtp_password' => input('post.smtp_password'), 'smtp_name' => input('post.smtp_name') ]; // 验证必填字段 if (empty($data['smtp_host']) || empty($data['smtp_port']) || empty($data['smtp_email']) || empty($data['smtp_password'])) { // Log::record('修改邮件配置', 0, '必填字段不能为空', '邮件配置'); return json(['code' => 1, 'msg' => '必填字段不能为空']); } $res = MailConfig::where('id', 1)->update($data); if ($res === false) { // Log::record('修改邮件配置', 0, '更新邮件配置失败', '邮件配置'); return json(['code' => 1, 'msg' => '更新邮件配置失败']); } // Log::record('修改邮件配置', 1, '', '邮件配置'); return json(['code' => 0, 'msg' => '更新成功']); } $config = MailConfig::where('id', 1)->find(); View::assign([ 'config' => $config ]); return View::fetch(); } // 获取邮件配置 public function getMailConfig() { $config = MailConfig::where('id', 1)->find(); if ($config) { return json(['code' => 0, 'msg' => '获取成功', 'data' => $config]); } return json(['code' => 1, 'msg' => '获取配置失败']); } // 测试邮件配置 public function testMailConfig() { if (!Request::isPost()) { return json(['code' => 1, 'msg' => '请求方法无效']); } $email = input('post.email'); $config = input('post.config'); if (empty($email) || empty($config)) { return json(['code' => 1, 'msg' => '参数错误']); } try { // 配置邮件服务器 $mail = new PHPMailer(true); $mail->isSMTP(); $mail->Host = $config['smtp_host']; $mail->Port = $config['smtp_port']; $mail->SMTPAuth = true; $mail->Username = $config['smtp_email']; $mail->Password = $config['smtp_password']; $mail->SMTPSecure = 'ssl'; $mail->CharSet = 'UTF-8'; // 设置发件人 $mail->setFrom($config['smtp_email'], $config['smtp_name']); $mail->addAddress($email); // 设置邮件内容 $mail->isHTML(true); $mail->Subject = '邮件配置测试'; $mail->Body = '这是一封测试邮件,如果您收到这封邮件,说明邮件配置正确。'; $mail->send(); return json(['code' => 0, 'msg' => '发送成功']); } catch (\Exception $e) { //Log::record('测试邮件配置', 0, $e->getMessage(), '邮件配置'); return json(['code' => 1, 'msg' => '发送失败:' . $e->getMessage()]); } } }