service = new ResourceService(); } /** * 列表页数据格式化 * * @param array $data * @return array */ protected function allFormat($data) { if (isset($data['created_at'])) $data['created_at'] = date('Y-m-d H:i:s', $data['created_at']); if (isset($data['updated_at'])) $data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']); return $data; } /** * 资源树形结构 */ public function listTree(Request $request) { try { $raw = $this->service->serviceListAll($request); $data = $this->transformData($raw, method_exists($this, 'allFormat') ? [$this, 'allFormat'] : null); return $this->success($data); } catch (\Throwable $e) { return $this->error($e->getMessage()); } } /** * 菜单 */ public function menuList(Request $request) { try { $raw = $this->service->serviceMenuList($request); $data = $this->transformData($raw, method_exists($this, 'allFormat') ? [$this, 'allFormat'] : null); return $this->success($data); } catch (\Throwable $e) { return $this->error($e->getMessage()); } } /** * 菜单 */ public function menuTreeList(Request $request) { try { $raw = $this->service->serviceMenuTreeList($request); $data = $this->transformData($raw, method_exists($this, 'allFormat') ? [$this, 'allFormat'] : null); return $this->success($data); } catch (\Throwable $e) { return $this->error($e->getMessage()); } } }