| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- <?php
- $root = dirname(dirname(__DIR__));
- define('APP_PATH', $root . '/application/');
- require $root . '/thinkphp/base.php';
- \think\App::initCommon();
- $prefix = \think\Db::getConfig('prefix');
- $table = $prefix . 'ps_home_block';
- $exists = \think\Db::query("SHOW TABLES LIKE '" . addslashes($table) . "'");
- if (!$exists) {
- \think\Db::execute("CREATE TABLE `{$table}` (
- `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
- `type` varchar(20) NOT NULL DEFAULT 'custom' COMMENT 'hero/stats/steps/features/cta/custom',
- `name` varchar(64) NOT NULL DEFAULT '' COMMENT '后台备注名',
- `kicker` varchar(64) NOT NULL DEFAULT '' COMMENT '小标题',
- `title` varchar(120) NOT NULL DEFAULT '' COMMENT '主标题',
- `subtitle` varchar(255) NOT NULL DEFAULT '' COMMENT '说明',
- `content` text COMMENT '模块内容 JSON',
- `weigh` int(11) NOT NULL DEFAULT '0' COMMENT '越大越靠前',
- `status` enum('normal','hidden') NOT NULL DEFAULT 'normal',
- `createtime` bigint(16) DEFAULT NULL,
- `updatetime` bigint(16) DEFAULT NULL,
- PRIMARY KEY (`id`),
- KEY `weigh` (`weigh`),
- KEY `status` (`status`)
- ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='工厂端首页模块'");
- echo $table . " created\n";
- } else {
- echo $table . " exists\n";
- }
- $count = (int)\think\Db::name('ps_home_block')->count();
- if ($count === 0) {
- $now = time();
- foreach (\app\common\library\ps\HomePage::defaults() as $row) {
- unset($row['id']);
- $row['content'] = json_encode($row['content'], JSON_UNESCAPED_UNICODE);
- $row['createtime'] = $now;
- $row['updatetime'] = $now;
- \think\Db::name('ps_home_block')->insert($row);
- }
- echo "seeded defaults\n";
- } else {
- echo "blocks already " . $count . "\n";
- }
- $pid = (int)\think\Db::name('auth_rule')->where('name', 'ps/group_factory')->value('id');
- if ($pid <= 0) {
- echo "menu parent missing\n";
- return;
- }
- $menu = \think\Db::name('auth_rule')->where('name', 'ps/home_block')->find();
- if (!$menu) {
- $id = \think\Db::name('auth_rule')->insertGetId([
- 'type' => 'file',
- 'pid' => $pid,
- 'name' => 'ps/home_block',
- 'title' => '工厂端首页',
- 'icon' => 'fa fa-home',
- 'ismenu' => 1,
- 'status' => 'normal',
- 'weigh' => 40,
- 'createtime' => time(),
- 'updatetime' => time(),
- ]);
- echo "menu added {$id}\n";
- } else {
- $id = (int)$menu['id'];
- echo "menu exists {$id}\n";
- }
- foreach (['index' => '查看', 'add' => '添加', 'edit' => '编辑', 'del' => '删除', 'multi' => '批量更新'] as $act => $title) {
- $name = 'ps/home_block/' . $act;
- if (\think\Db::name('auth_rule')->where('name', $name)->find()) {
- continue;
- }
- \think\Db::name('auth_rule')->insert([
- 'type' => 'file',
- 'pid' => $id,
- 'name' => $name,
- 'title' => $title,
- 'icon' => 'fa fa-circle-o',
- 'ismenu' => 0,
- 'status' => 'normal',
- 'weigh' => 0,
- 'createtime' => time(),
- 'updatetime' => time(),
- ]);
- echo "rule {$name}\n";
- }
|