ps_home_block_run.php 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. $root = dirname(dirname(__DIR__));
  3. define('APP_PATH', $root . '/application/');
  4. require $root . '/thinkphp/base.php';
  5. \think\App::initCommon();
  6. $prefix = \think\Db::getConfig('prefix');
  7. $table = $prefix . 'ps_home_block';
  8. $exists = \think\Db::query("SHOW TABLES LIKE '" . addslashes($table) . "'");
  9. if (!$exists) {
  10. \think\Db::execute("CREATE TABLE `{$table}` (
  11. `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  12. `type` varchar(20) NOT NULL DEFAULT 'custom' COMMENT 'hero/stats/steps/features/cta/custom',
  13. `name` varchar(64) NOT NULL DEFAULT '' COMMENT '后台备注名',
  14. `kicker` varchar(64) NOT NULL DEFAULT '' COMMENT '小标题',
  15. `title` varchar(120) NOT NULL DEFAULT '' COMMENT '主标题',
  16. `subtitle` varchar(255) NOT NULL DEFAULT '' COMMENT '说明',
  17. `content` text COMMENT '模块内容 JSON',
  18. `weigh` int(11) NOT NULL DEFAULT '0' COMMENT '越大越靠前',
  19. `status` enum('normal','hidden') NOT NULL DEFAULT 'normal',
  20. `createtime` bigint(16) DEFAULT NULL,
  21. `updatetime` bigint(16) DEFAULT NULL,
  22. PRIMARY KEY (`id`),
  23. KEY `weigh` (`weigh`),
  24. KEY `status` (`status`)
  25. ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='工厂端首页模块'");
  26. echo $table . " created\n";
  27. } else {
  28. echo $table . " exists\n";
  29. }
  30. $count = (int)\think\Db::name('ps_home_block')->count();
  31. if ($count === 0) {
  32. $now = time();
  33. foreach (\app\common\library\ps\HomePage::defaults() as $row) {
  34. unset($row['id']);
  35. $row['content'] = json_encode($row['content'], JSON_UNESCAPED_UNICODE);
  36. $row['createtime'] = $now;
  37. $row['updatetime'] = $now;
  38. \think\Db::name('ps_home_block')->insert($row);
  39. }
  40. echo "seeded defaults\n";
  41. } else {
  42. echo "blocks already " . $count . "\n";
  43. }
  44. $pid = (int)\think\Db::name('auth_rule')->where('name', 'ps/group_factory')->value('id');
  45. if ($pid <= 0) {
  46. echo "menu parent missing\n";
  47. return;
  48. }
  49. $menu = \think\Db::name('auth_rule')->where('name', 'ps/home_block')->find();
  50. if (!$menu) {
  51. $id = \think\Db::name('auth_rule')->insertGetId([
  52. 'type' => 'file',
  53. 'pid' => $pid,
  54. 'name' => 'ps/home_block',
  55. 'title' => '工厂端首页',
  56. 'icon' => 'fa fa-home',
  57. 'ismenu' => 1,
  58. 'status' => 'normal',
  59. 'weigh' => 40,
  60. 'createtime' => time(),
  61. 'updatetime' => time(),
  62. ]);
  63. echo "menu added {$id}\n";
  64. } else {
  65. $id = (int)$menu['id'];
  66. echo "menu exists {$id}\n";
  67. }
  68. foreach (['index' => '查看', 'add' => '添加', 'edit' => '编辑', 'del' => '删除', 'multi' => '批量更新'] as $act => $title) {
  69. $name = 'ps/home_block/' . $act;
  70. if (\think\Db::name('auth_rule')->where('name', $name)->find()) {
  71. continue;
  72. }
  73. \think\Db::name('auth_rule')->insert([
  74. 'type' => 'file',
  75. 'pid' => $id,
  76. 'name' => $name,
  77. 'title' => $title,
  78. 'icon' => 'fa fa-circle-o',
  79. 'ismenu' => 0,
  80. 'status' => 'normal',
  81. 'weigh' => 0,
  82. 'createtime' => time(),
  83. 'updatetime' => time(),
  84. ]);
  85. echo "rule {$name}\n";
  86. }