sqlite-web 0.7.2
gitea.db
issue
Create
Query
access
access_token
action
action_artifact
action_run
action_run_index
action_run_job
action_runner
action_runner_token
action_schedule
action_schedule_spec
action_task
action_task_output
action_task_step
action_tasks_version
action_variable
app_state
attachment
auth_token
badge
branch
collaboration
comment
commit_status
commit_status_index
commit_status_summary
commit_sync_log
commit_sync_status
dbfs_data
dbfs_meta
deploy_key
email_address
email_hash
external_login_user
follow
gpg_key
gpg_key_import
hook_task
issue
issue_assignees
issue_content_history
issue_dependency
issue_index
issue_label
issue_pin
issue_user
issue_watch
label
language_stat
lfs_lock
lfs_meta_object
login_source
milestone
mirror
notice
notification
oauth2_application
oauth2_authorization_code
oauth2_grant
org_user
package
package_blob
package_blob_upload
package_cleanup_rule
package_file
package_property
package_version
project
project_board
project_issue
protected_branch
protected_tag
public_key
pull_auto_merge
pull_request
push_mirror
reaction
release
renamed_branch
repo_archiver
repo_hidden_file
repo_indexer_status
repo_license
repo_redirect
repo_topic
repo_transfer
repo_unit
repository
review
review_state
secret
session
sqlite_sequence
star
stopwatch
system_setting
task
team
team_invite
team_repo
team_unit
team_user
topic
tracked_time
two_factor
upload
user
user_badge
user_blocking
user_open_id
user_redirect
user_setting
version
watch
webauthn_credential
webhook
Toggle helper tables
Structure
Content
Query
Insert
Drop
Import
Export
Update row 337 in issue
id
Primary key.
INTEGER NOT NULL
repo_id
INTEGER
index
INTEGER
poster_id
INTEGER
original_author
TEXT
original_author_id
INTEGER
name
🔍 代码审查报告:pc-260616 - Merge branch 'pc-260616' of https://gitea.g-hi.com
TEXT
content
## 自动代码审查报告 **分支**: pc-260616 **提交**: `83c6a789c220fe167ea98fd573c3e882db25ebb5` **提交人**: LITTLEMAIDI (11833999+littlemaidi@user.noreply.gitee.com) **时间**: 2026-05-26 17:02:53 --- ## 1. 审查摘要 - **代码质量评分**:4 / 10 分 - **总体评价**:代码实现了大量财务与业务报表的查询及导出功能,但存在严重的架构与规范问题。大量重复的导出逻辑、直接操作超全局变量 `$_GET`、滥用 `exit()` 终止脚本、以及模型配置硬编码等问题显著降低了系统的可维护性、安全性与运行稳定性。 - **风险等级**:🔴 高 > 📌 **框架说明**:从 `defined('BASEPATH')`、`$this->load->model()`、`get_instance()` 等特征判断,当前代码实际基于 **CodeIgniter 3** 架构。若 `phpci` 为贵司内部封装或别名,请结合其官方生命周期文档对照调整。以下审查将基于 CI3 最佳实践与通用 PHP 规范进行。 ## 2. 问题详情 | 严重程度 | 文件/行号 | 问题描述 | 建议修改方案 | 代码示例 (可选) | | :--- | :--- | :--- | :--- | :--- | | 🔴 严重 | `FinanceReport2.php` (多处) | **直接读取/修改 `$_GET` 超全局变量**。绕过框架输入过滤,存在 XSS/SQL 注入风险;且直接赋值 `$_GET['admin_id'] = ...` 会污染全局状态,引发不可预知的副作用。 | 统一使用框架输入类获取参数,开启 XSS 过滤。禁止直接修改 `$_GET`,应将上下文参数(如 `admin_id`)作为独立参数传递给 Model 方法。 | `$params = $this->input->get(NULL, TRUE);`<br>`$this->model->export($merchant_id, $params, $this->admin_id);` | | 🔴 严重 | `FinanceReport2.php` (多处导出方法) | **滥用 `exit()` 终止请求**。破坏框架生命周期,可能导致数据库连接未释放、事务未回滚、日志未记录或后续中间件未执行。 | 使用框架标准输出机制或抛出异常交由全局异常处理器接管。导出文件应通过 CI 的 `Output` 类或标准 HTTP 响应头返回。 | `header('Content-Type: application/octet-stream');`<br>`header('Content-Disposition: attachment; filename="'.$filename.'"');`<br>`echo $fileContent;`<br>`return; // 替代 exit()` | | 🔴 严重 | `Ahead_community_shop_model.php` (文件顶部) | **类外部执行框架实例化与模型加载**。`$CI = &get_instance();` 放在类定义外违反 PHP OOP 原则,易引发加载顺序冲突、内存泄漏或致命错误。 | 移除顶部全局代码。将配置数据移至类属性、构造函数或独立的配置文件中,按需加载。 | `class Ahead_community_shop_model extends Simple_model {`<br>` protected $operational_scene_config = [...];`<br>`}` | | 🟠 警告 | `FinanceReport2.php` (导出方法) | **硬编码 `ini_set("memory_limit", "500M")`**。掩盖大数据量处理缺陷,高并发导出时极易耗尽服务器内存,导致 OOM 或服务雪崩。 | 采用分块查询(Chunking)、数据库游标或流式写入(如 `PhpSpreadsheet` 的 `Writer` 流式输出),避免一次性加载全量数据到内存。 | `while ($batch = $this->model->get_batch($offset, $limit)) {`<br>` $writer->addRows($batch);`<br>` $offset += $limit;`<br>`}` | | 🟠 警告 | `FinanceReport2.php` (多处) | **导出逻辑高度重复,违反 DRY 原则**。列定义、字段过滤、PDF/Excel 分支、设置保存等代码在 10+ 个方法中复制粘贴,维护成本极高。 | 抽取为基类方法或 Trait,通过配置数组驱动导出流程。控制器仅负责参数收集与调用。 | `protected function handleExport($title, $columns, $data, $params) {`<br>` // 统一处理字段过滤、表头、导出逻辑`<br>`}` | | 🟠 警告 | `FinanceReport2.php` (导出方法) | **`json_decode` 未做异常处理**。`$_GET['export_fields']` 传入非法 JSON 时返回 `null` 或触发 Warning,导致后续 `empty()` 或 `array_keys()` 报错。 | 增加类型校验与 JSON 解析异常捕获,提供明确的业务错误提示。 | `$fields = json_decode($param['export_fields'], true);`<br>`if (json_last_error() !== JSON_ERROR_NONE) {`<br>` show_error('导出字段参数格式错误');`<br>`}` | | 🟡 建议 | `FinanceReport2.php` & `Ahead_community_shop_model.php` | **命名规范不统一,缺乏类型声明**。模型加载名、方法名混用驼峰与蛇形;无 PHPDoc 类型提示,不符合 PSR-12 规范。 | 统一使用驼峰命名法,为方法添加参数与返回值类型声明,完善 PHPDoc 注释。 | `public function getManagerDiscountReport(): void`<br>`/** @param array $params */` | | 🟡 建议 | `Ahead_community_shop_model.php` | **巨型配置数组硬编码在 Model 中**。数组体积庞大,每次实例化模型都会占用内存,且业务变更需修改代码。 | 移至 `application/config/community_shop_config.php`,通过 `$this->config->load()` 按需读取,或持久化至数据库。 | `$this->config->load('community_shop_config');`<br>`$config = $this->config->item('operational_scene_config');` | > ⚠️ **局限性说明**:提供的代码片段在末尾被截断(如 `FinanceReport2.php` 的 `shoppingGuideOrderCountByUserExport` 方法未闭合,`Ahead_community_shop_model.php` 配置数组未结束)。以上审查基于已暴露的代码模式进行,完整逻辑可能存在更多未覆盖的边界条件或异常分支。 ## 3. 总结与行动建议 ### 🚀 优先修复的关键问题 1. **替换 `$_GET` 与 `exit()`**:立即全局搜索并替换直接操作 `$_GET` 的代码,改用 `$this->input->get()`;移除所有 `exit()`,改用框架标准响应或 `return`。 2. **修复模型顶部全局代码**:将 `Ahead_community_shop_model.php` 顶部的 `$CI = &get_instance();` 移除,改为类属性或构造函数初始化,避免框架加载冲突。 3. **增加 JSON 解析防御**:所有 `json_decode` 调用前必须校验 `json_last_error()`,防止恶意或畸形参数导致 500 错误。 ### 🛠 后续重构与优化方向 1. **抽象导出基类/Trait**:将重复的列定义、字段过滤、表头组装、Excel/PDF 分支逻辑抽取至 `BaseExportController` 或 `ExportTrait`。控制器仅保留业务参数收集与模型调用,代码量可减少 60% 以上。 2. **流式/分块导出改造**:针对大数据量报表,废弃 `ini_set("memory_limit")` 方案。采用 `LIMIT/OFFSET` 分批次查询,结合 `PhpSpreadsheet` 的 `Writer` 流式写入或 `fopen('php://output')` 直接输出,将内存占用控制在 MB 级别。 3. **配置外部化**:将 `Ahead_community_shop_model` 中的静态配置迁移至 `config/` 目录或数据库配置表。支持后台动态修改,避免发版。 4. **规范与类型安全**:全面对齐 PSR-12,为所有公开方法添加 `declare(strict_types=1);`、参数类型提示及返回值声明。使用 PHPStan 或 Psalm 进行静态分析,提前拦截类型错误。 5. **框架适配确认**:若项目确为 `phpci` 定制框架,请核对上述 CI3 特性(如 `$this->input`、`$this->load->model`)是否被重写。建议查阅 `phpci` 官方文档中关于 **输入过滤、输出响应、模型加载** 的标准用法,确保不偏离框架设计初衷。 --- *此 Issue 由代码审查服务自动创建*
TEXT
milestone_id
INTEGER
priority
INTEGER
is_closed
INTEGER
is_pull
INTEGER
num_comments
INTEGER
ref
TEXT
deadline_unix
INTEGER
created_unix
INTEGER
updated_unix
INTEGER
closed_unix
INTEGER
is_locked
INTEGER NOT NULL (default 0
content_version
INTEGER NOT NULL (default 0
time_estimate
INTEGER NOT NULL (default 0
Update
Cancel