diff --git a/beike/Admin/Http/Controllers/DesignController.php b/beike/Admin/Http/Controllers/DesignController.php index 7e959840..ae599843 100644 --- a/beike/Admin/Http/Controllers/DesignController.php +++ b/beike/Admin/Http/Controllers/DesignController.php @@ -51,12 +51,13 @@ class DesignController extends Controller */ public function update(Request $request): array { - $moduleData = DesignService::handleModules($request->getContent()); + $content = json_decode($request->getContent(), true); + $moduleData = DesignService::handleModules($content); $data = [ 'type' => 'system', 'space' => 'base', 'name' => 'design_setting', - 'value' => $moduleData, + 'value' => json_encode($moduleData), 'json' => 1 ]; SettingRepo::createOrUpdate($data); diff --git a/beike/Admin/Services/DesignService.php b/beike/Admin/Services/DesignService.php index 98604377..1cee3d84 100644 --- a/beike/Admin/Services/DesignService.php +++ b/beike/Admin/Services/DesignService.php @@ -11,10 +11,24 @@ namespace Beike\Admin\Services; +use Illuminate\Support\Str; + class DesignService { - public static function handleModules($moduleData) + public static function handleModules($modulesData): array { - return $moduleData; + $modulesData = $modulesData['modules']; + if (empty($modulesData)) { + return []; + } + + foreach ($modulesData as $index => $moduleData) { + $moduleId = $moduleData['module_id'] ?? ''; + if (empty($moduleId)) { + $moduleData['module_id'] = Str::random(16); + } + $modulesData[$index] = $moduleData; + } + return ['modules' => $modulesData]; } }