where('name', 'like', '%' . $params['name'] . '%'); } if (isset($params['status'])) { $query->where('status', $params['status']); } return $query->paginate($params['per_page'] ?? 15); } /** * 创建开发工具 * * @param array $data 开发工具数据 * @return Dev */ public static function createDevTool(array $data): Dev { // 检查事务是否已开启 \UCore\Db\Helper::check_tr(); try { return Dev::create($data); } catch (\Exception $e) { Log::error('创建开发工具失败', [ 'error' => $e->getMessage(), 'data' => $data ]); throw $e; } } /** * 更新开发工具 * * @param int $id 开发工具ID * @param array $data 开发工具数据 * @return bool */ public static function updateDevTool(int $id, array $data): bool { // 检查事务是否已开启 \UCore\Db\Helper::check_tr(); try { $devTool = Dev::find($id); if (!$devTool) { return false; } return $devTool->update($data); } catch (\Exception $e) { Log::error('更新开发工具失败', [ 'error' => $e->getMessage(), 'id' => $id, 'data' => $data ]); return false; } } /** * 删除开发工具 * * @param int $id 开发工具ID * @return bool */ public static function deleteDevTool(int $id): bool { // 检查事务是否已开启 \UCore\Db\Helper::check_tr(); try { $devTool = Dev::find($id); if (!$devTool) { return false; } return $devTool->delete(); } catch (\Exception $e) { Log::error('删除开发工具失败', [ 'error' => $e->getMessage(), 'id' => $id ]); return false; } } /** * 记录开发日志 * * @param string $type 日志类型 * @param string $content 日志内容 * @param array $extraData 额外数据 * @return DevLog */ public static function log(string $type, string $content, array $extraData = []): DevLog { try { $data = [ 'type' => $type, 'content' => $content, 'ip' => Request::ip(), 'user_id' => auth()->id() ?? 0, 'user_agent' => Request::userAgent(), 'extra_data' => $extraData, ]; $log = DevLog::create($data); // 触发日志创建事件 event(new DevLogCreatedEvent($log)); return $log; } catch (\Exception $e) { \UCore\Helper\Logger::exception('记录开发日志失败', $e, [ 'type' => $type, 'content' => $content, 'extra_data' => $extraData ]); // 创建失败时,返回一个空的日志对象 return new DevLog(); } } }