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"; }