id); if ($result['success']) { return $this->response() ->success('初始化成功!' . $result['message'] . ',共初始化了 ' . $result['initialized_count'] . ' 个商品的库存记录。') ->refresh(); // 刷新当前页面 } else { return $this->response()->error('初始化失败: ' . $result['message']); } } catch (\Exception $e) { return $this->response()->error('初始化失败: ' . $e->getMessage()); } } /** * 构建表单 */ public function form() { $this->html('
初始化说明
'); $this->html('
注意事项
'); // 添加一个隐藏字段,确保表单可以提交 $this->hidden('action')->value('initialize'); } /** * 返回表单默认数据 */ public function default() { return [ 'action' => 'initialize', ]; } }