| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- <?php
- namespace app\admin\controller;
- use app\common\controller\Backend;
- use think\Db;
- /**
- * 外发采购子菜单安装(仅超级管理员访问一次)
- */
- class Procuremenmenu extends Backend
- {
- protected $noNeedRight = ['install'];
- public function install()
- {
- if (!$this->auth->isSuperAdmin()) {
- $this->error('仅超级管理员可执行');
- }
- $t = time();
- $listRule = Db::name('auth_rule')->where('name', 'procuremen/pick')->find();
- if (!$listRule) {
- $listRule = Db::name('auth_rule')->where('name', 'procuremen/index')->find();
- }
- if (!$listRule) {
- $this->error('未找到外发下发菜单,请先在权限规则中配置 procuremen/pick 或 procuremen/index');
- }
- $pid = (int)($listRule['pid'] ?? 0);
- if ($pid <= 0) {
- $existsRoot = Db::name('auth_rule')->where('name', 'procuremenroot')->find();
- if ($existsRoot) {
- $pid = (int)$existsRoot['id'];
- } else {
- $pid = Db::name('auth_rule')->insertGetId([
- 'type' => 'file',
- 'pid' => 0,
- 'name' => 'procuremenroot',
- 'title' => '外发采购',
- 'icon' => 'fa fa-share-alt',
- 'url' => '',
- 'ismenu' => 1,
- 'menutype' => 'addtabs',
- 'weigh' => 88,
- 'status' => 'normal',
- 'createtime' => $t,
- 'updatetime' => $t,
- ]);
- }
- Db::name('auth_rule')->where('id', (int)$listRule['id'])->update([
- 'pid' => $pid,
- 'title' => '外发下发',
- 'name' => 'procuremen/pick',
- 'updatetime' => $t,
- ]);
- }
- $added = 0;
- $workflowMenus = [
- ['name' => 'procuremen/pick', 'title' => '外发下发', 'icon' => 'fa fa-paper-plane', 'weigh' => 90],
- ['name' => 'procuremen/audit', 'title' => '确认供应商', 'icon' => 'fa fa-check-square-o', 'weigh' => 89],
- ['name' => 'procuremen/confirm', 'title' => '采购确认', 'icon' => 'fa fa-shopping-cart', 'weigh' => 88],
- ];
- foreach ($workflowMenus as $wm) {
- if (Db::name('auth_rule')->where('name', $wm['name'])->find()) {
- Db::name('auth_rule')->where('name', $wm['name'])->update([
- 'title' => $wm['title'],
- 'icon' => $wm['icon'],
- 'weigh' => $wm['weigh'],
- 'updatetime' => $t,
- ]);
- continue;
- }
- Db::name('auth_rule')->insertGetId([
- 'type' => 'file',
- 'pid' => $pid,
- 'name' => $wm['name'],
- 'title' => $wm['title'],
- 'icon' => $wm['icon'],
- 'url' => '',
- 'ismenu' => 1,
- 'menutype' => 'addtabs',
- 'weigh' => $wm['weigh'],
- 'status' => 'normal',
- 'createtime' => $t,
- 'updatetime' => $t,
- ]);
- $added++;
- }
- $menus = [
- ['name' => 'procuremensms/index', 'title' => '短信模版维护', 'icon' => 'fa fa-commenting-o', 'weigh' => 87],
- ['name' => 'procuremenarchive/index', 'title' => '历史存证档案查询', 'icon' => 'fa fa-archive', 'weigh' => 86],
- ['name' => 'procuremenexport/index', 'title' => '月度报表导出列表', 'icon' => 'fa fa-file-excel-o', 'weigh' => 85],
- ];
- foreach ($menus as $m) {
- if (Db::name('auth_rule')->where('name', $m['name'])->find()) {
- continue;
- }
- $menuId = Db::name('auth_rule')->insertGetId([
- 'type' => 'file',
- 'pid' => $pid,
- 'name' => $m['name'],
- 'title' => $m['title'],
- 'icon' => $m['icon'],
- 'url' => '',
- 'ismenu' => 1,
- 'menutype' => 'addtabs',
- 'weigh' => $m['weigh'],
- 'status' => 'normal',
- 'createtime' => $t,
- 'updatetime' => $t,
- ]);
- $added++;
- if ($m['name'] === 'procuremensms/index') {
- Db::name('auth_rule')->insert([
- 'type' => 'file',
- 'pid' => $menuId,
- 'name' => 'procuremensms/edit',
- 'title' => '编辑',
- 'icon' => 'fa fa-circle-o',
- 'ismenu' => 0,
- 'status' => 'normal',
- 'createtime' => $t,
- 'updatetime' => $t,
- ]);
- $added++;
- }
- }
- \think\Cache::rm('__menu__');
- $this->success('菜单安装完成,新增节点 ' . $added . ' 个。请刷新后台并到「权限管理」为角色勾选新菜单。');
- }
- }
|