136 lines
4.5 KiB
PHP
136 lines
4.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use Phinx\Migration\AbstractMigration;
|
|
use support\think\Db;
|
|
|
|
/**
|
|
* Markdown 文档:分红说明文档(归入 docs/mdManual 目录)
|
|
*/
|
|
final class DocsCommissionShareMenu extends AbstractMigration
|
|
{
|
|
public function up(): void
|
|
{
|
|
$ruleTable = $this->hasTable('admin_rule') ? 'admin_rule' : ($this->hasTable('menu_rule') ? 'menu_rule' : null);
|
|
if ($ruleTable === null) {
|
|
return;
|
|
}
|
|
$ct = $this->table($ruleTable)->hasColumn('create_time') ? 'create_time' : 'createtime';
|
|
$ut = $this->table($ruleTable)->hasColumn('update_time') ? 'update_time' : 'updatetime';
|
|
$now = time();
|
|
|
|
$dirId = $this->resolveDocsDirId($ruleTable, $ct, $ut, $now);
|
|
$menuName = 'docs/docCommissionShare';
|
|
$menuId = $this->ensureMenu($ruleTable, $dirId, $menuName, $ct, $ut, $now);
|
|
$this->ensureButtons($ruleTable, $menuId, $menuName, $ct, $ut, $now);
|
|
}
|
|
|
|
private function resolveDocsDirId(string $table, string $ct, string $ut, int $now): int
|
|
{
|
|
$row = Db::name($table)->where('name', 'docs/mdManual')->where('type', 'menu_dir')->find();
|
|
if ($row) {
|
|
return (int) $row['id'];
|
|
}
|
|
return (int) Db::name($table)->insertGetId([
|
|
'pid' => 0,
|
|
'type' => 'menu_dir',
|
|
'title' => 'Markdown文档',
|
|
'name' => 'docs/mdManual',
|
|
'path' => 'docs/mdManual',
|
|
'icon' => 'fa fa-book',
|
|
'menu_type' => 'tab',
|
|
'component' => '',
|
|
'url' => '',
|
|
'extend' => 'none',
|
|
'remark' => '',
|
|
'weigh' => 53,
|
|
'status' => 1,
|
|
'keepalive' => 0,
|
|
$ct => $now,
|
|
$ut => $now,
|
|
]);
|
|
}
|
|
|
|
private function ensureMenu(string $table, int $pid, string $name, string $ct, string $ut, int $now): int
|
|
{
|
|
$row = Db::name($table)->where('name', $name)->where('type', 'menu')->find();
|
|
if ($row) {
|
|
Db::name($table)->where('id', $row['id'])->update([
|
|
'pid' => $pid,
|
|
'title' => '分红说明文档',
|
|
'path' => $name,
|
|
'component' => '/src/views/backend/docs/docCommissionShare/index.vue',
|
|
'icon' => 'fa fa-percent',
|
|
'menu_type' => 'tab',
|
|
'weigh' => 51,
|
|
'status' => 1,
|
|
'keepalive' => 1,
|
|
$ut => $now,
|
|
]);
|
|
return (int) $row['id'];
|
|
}
|
|
return (int) Db::name($table)->insertGetId([
|
|
'pid' => $pid,
|
|
'type' => 'menu',
|
|
'title' => '分红说明文档',
|
|
'name' => $name,
|
|
'path' => $name,
|
|
'icon' => 'fa fa-percent',
|
|
'menu_type' => 'tab',
|
|
'component' => '/src/views/backend/docs/docCommissionShare/index.vue',
|
|
'url' => '',
|
|
'extend' => 'none',
|
|
'remark' => 'commission share guide markdown',
|
|
'weigh' => 51,
|
|
'status' => 1,
|
|
'keepalive' => 1,
|
|
$ct => $now,
|
|
$ut => $now,
|
|
]);
|
|
}
|
|
|
|
private function ensureButtons(string $table, int $pid, string $menuName, string $ct, string $ut, int $now): void
|
|
{
|
|
$titleMap = [
|
|
'content' => '拉取正文',
|
|
'download' => '下载 Markdown',
|
|
];
|
|
foreach ($titleMap as $action => $title) {
|
|
$btnName = $menuName . '/' . $action;
|
|
$exists = Db::name($table)->where('name', $btnName)->where('type', 'button')->find();
|
|
if ($exists) {
|
|
Db::name($table)->where('id', $exists['id'])->update([
|
|
'pid' => $pid,
|
|
'title' => $title,
|
|
'status' => 1,
|
|
$ut => $now,
|
|
]);
|
|
continue;
|
|
}
|
|
Db::name($table)->insert([
|
|
'pid' => $pid,
|
|
'type' => 'button',
|
|
'title' => $title,
|
|
'name' => $btnName,
|
|
'path' => '',
|
|
'icon' => '',
|
|
'menu_type' => 'tab',
|
|
'component' => '',
|
|
'url' => '',
|
|
'extend' => 'none',
|
|
'remark' => '',
|
|
'weigh' => 0,
|
|
'status' => 1,
|
|
'keepalive' => 0,
|
|
$ct => $now,
|
|
$ut => $now,
|
|
]);
|
|
}
|
|
}
|
|
|
|
public function down(): void
|
|
{
|
|
}
|
|
}
|