|
|
@@ -0,0 +1,81 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+use Illuminate\Database\Migrations\Migration;
|
|
|
+use Illuminate\Support\Facades\DB;
|
|
|
+use Illuminate\Support\Facades\Schema;
|
|
|
+
|
|
|
+return new class extends Migration {
|
|
|
+ private const MENU_TITLE = '转盘活动';
|
|
|
+
|
|
|
+ private const BUTTONS = [
|
|
|
+ 'admin/promotion' => '查看',
|
|
|
+ 'admin/promotion/submit' => '保存/上下架',
|
|
|
+ 'admin/promotion/records' => '抽奖记录',
|
|
|
+ ];
|
|
|
+
|
|
|
+ private const BUTTON_PERMISSION_NAMES = [
|
|
|
+ 'admin/promotion' => 'promotion.wheel.view',
|
|
|
+ 'admin/promotion/submit' => 'promotion.wheel.submit',
|
|
|
+ 'admin/promotion/records' => 'promotion.wheel.records',
|
|
|
+ ];
|
|
|
+
|
|
|
+ public function up(): void
|
|
|
+ {
|
|
|
+ if (!Schema::hasTable('menus')) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 转盘活动菜单由后台手动创建,按标题定位;按钮 uri 与净亏邀请、首充奖励共用,
|
|
|
+ // 因此只在转盘菜单下补齐缺失的按钮,不移动挂在其他活动下的同名按钮。
|
|
|
+ $menuIds = DB::table('menus')
|
|
|
+ ->where('title', self::MENU_TITLE)
|
|
|
+ ->where('type', 1)
|
|
|
+ ->pluck('id');
|
|
|
+
|
|
|
+ $now = date('Y-m-d H:i:s');
|
|
|
+ foreach ($menuIds as $menuId) {
|
|
|
+ $sort = 0;
|
|
|
+ foreach (self::BUTTONS as $uri => $title) {
|
|
|
+ $exists = DB::table('menus')
|
|
|
+ ->where('parent_id', $menuId)
|
|
|
+ ->where('uri', $uri)
|
|
|
+ ->exists();
|
|
|
+ if (!$exists) {
|
|
|
+ DB::table('menus')->insert([
|
|
|
+ 'parent_id' => $menuId,
|
|
|
+ 'title' => $title,
|
|
|
+ 'icon' => null,
|
|
|
+ 'uri' => $uri,
|
|
|
+ 'permission_name' => self::BUTTON_PERMISSION_NAMES[$uri],
|
|
|
+ 'sort' => $sort,
|
|
|
+ 'status' => 1,
|
|
|
+ 'type' => 2,
|
|
|
+ 'created_at' => $now,
|
|
|
+ 'updated_at' => $now,
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+ $sort++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public function down(): void
|
|
|
+ {
|
|
|
+ if (!Schema::hasTable('menus')) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ $menuIds = DB::table('menus')
|
|
|
+ ->where('title', self::MENU_TITLE)
|
|
|
+ ->where('type', 1)
|
|
|
+ ->pluck('id');
|
|
|
+ $buttonIds = DB::table('menus')
|
|
|
+ ->whereIn('parent_id', $menuIds)
|
|
|
+ ->whereIn('permission_name', array_values(self::BUTTON_PERMISSION_NAMES))
|
|
|
+ ->pluck('id');
|
|
|
+ if (Schema::hasTable('role_menu')) {
|
|
|
+ DB::table('role_menu')->whereIn('menu_id', $buttonIds)->delete();
|
|
|
+ }
|
|
|
+ DB::table('menus')->whereIn('id', $buttonIds)->delete();
|
|
|
+ }
|
|
|
+};
|