has('theme_key') && !empty($request->theme_key)) { $query->where('theme_key', $request->theme_key); } $list = $query->orderBy('bid', 'desc')->paginate(20); // 获取所有主题用于筛选 $themes = WebThemeConfig::all(); return view('admin.banner.index', [ 'list' => $list, 'theme_key' => $request->theme_key ?? '', 'themes' => $themes ]); } public function add(Request $request) { if ($request->isMethod('post')) { $validator = Validator::make($request->all(), [ 'img' => 'required|string', 'alt' => 'nullable|string', 'link' => 'nullable|string|max:255', 'state' => 'nullable|integer', 'link_game' => 'nullable|integer', 'link_module' => 'nullable|integer', 'theme_key' => 'nullable|string|max:30', ]); if ($validator->fails()) { return apiReturnFail($validator->errors()->first()); } $data = $request->only(['img', 'img_pt', 'img_es', 'alt', 'link', 'state', 'link_game', 'link_module', 'theme_key']); // state: 127 启用, 0 禁用 $state = isset($data['state']) && $data['state'] !== '' ? intval($data['state']) : 127; $data['state'] = in_array($state, [0, 127]) ? $state : 127; Banner::create($data); return apiReturnSuc(); } $themes = WebThemeConfig::all(); return view('admin.banner.add', ['themes' => $themes]); } public function edit(Request $request, $id) { $info = Banner::findOrFail($id); if ($request->isMethod('post')) { $validator = Validator::make($request->all(), [ 'img' => 'required|string', 'alt' => 'nullable|string', 'link' => 'nullable|string|max:255', 'state' => 'nullable|integer', 'link_game' => 'nullable|integer', 'link_module' => 'nullable|integer', 'theme_key' => 'nullable|string|max:30', ]); if ($validator->fails()) { return apiReturnFail($validator->errors()->first()); } $data = $request->only(['img', 'img_pt', 'img_es', 'alt', 'link', 'state', 'link_game', 'link_module', 'theme_key']); // state: 127 启用, 0 禁用 $state = isset($data['state']) && $data['state'] !== '' ? intval($data['state']) : 127; $data['state'] = in_array($state, [0, 127]) ? $state : 127; $info->update($data); return apiReturnSuc(); } $themes = WebThemeConfig::all(); return view('admin.banner.edit', [ 'info' => $info, 'themes' => $themes ]); } public function delete($id) { $info = Banner::findOrFail($id); $info->delete(); return apiReturnSuc(); } }