Browse Source

新增迁移:为转盘活动菜单补齐按钮权限

转盘活动菜单由后台手动创建,下面没有按钮,角色无法授权 admin/promotion 等接口,
代理进入转盘页面提示无权限。按标题定位“转盘活动”菜单,补齐查看、保存/上下架、
抽奖记录三个按钮;uri 与其他独立活动共用,不移动已挂在其他菜单下的同名按钮。
不自动授权角色,需在角色管理中勾选。

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
doge 1 giờ trước cách đây
mục cha
commit
cab39d78aa

+ 81 - 0
database/migrations/2026_11_03_150000_add_wheel_promotion_admin_buttons.php

@@ -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();
+    }
+};