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
Delete row 620 from issue
id
620
repo_id
18
index
192
poster_id
1
original_author
original_author_id
0
name
🔍 代码审查报告:pc - Merge pull request '111' (#1
🔍 代码审查报告:pc - Merge pull request '111' (#190) from pc-260519 int
...
content
## 自动代码审查报告 **分支**: pc **提交**: `50b6c60f2cd85cb2b
## 自动代码审查报告 **分支**: pc **提交**: `50b6c60f2cd85cb2b1a060ef2c4e9bd6269d24a7` **提交人**: zhangjunnan (121158035@qq.com) **时间**: 2026-06-09 10:39:13 --- ## 1. 审查摘要 - **代码质量评分**:4 / 10 分 - **总体评价**:该 Model 承载了核心订单业务逻辑,功能覆盖面广,但存在严重的架构反模式、SQL 注入风险、N+1 查询性能瓶颈及大量重复代码。整体可维护性与扩展性较差,需进行系统性重构。 - **风险等级**:🔴 高 ## 2. 问题详情 | 严重程度 | 文件/行号 | 问题描述 | 建议修改方案 | 代码示例 (可选) | | :--- | :--- | :--- | :--- | :--- | | 🔴 严重 | `get_bill_goods_info` 方法内 | **SQL 注入漏洞**:使用字符串拼接构造 SQL 条件 `$sql = '_unique_key="' . $unique_key . '" AND ...'`,未进行参数绑定或转义,极易被恶意利用。 | 使用框架提供的查询构建器(Query Builder)或预处理语句,避免直接拼接。 | `$this->db->where('_unique_key', $unique_key)->where_in('_status', [1,4])->or_where(...)->get()->result_array();` | | 🔴 严重 | 文件顶部 (类外) | **全局实例化反模式**:`$CI = &get_instance(); $CI->load->model('Simple_model');` 在类外部执行。每次 `include/require` 该文件都会触发,严重拖慢框架启动速度,且违反 MVC 生命周期规范。 | 移除类外代码。模型依赖应在 `__construct()` 中加载,或通过框架自动加载机制处理。 | `public function __construct() { parent::__construct(); $this->load->model('Simple_model'); }` | | 🟠 警告 | `get_detail` / `get_list` / `get_list_export_v2` | **N+1 查询性能瓶颈**:在 `foreach` 循环中频繁调用 `$this->load->model()` 并执行单条查询(如 `get_custom_pay_platform`、`get_order_shopping_guide`、房间/用户查询)。数据量大时将导致数据库连接耗尽与响应超时。 | 采用**批量查询**或**JOIN 关联**。在循环外一次性获取所有关联数据,构建映射数组(如 `[$id => $data]`),循环内直接读取。 | `$ids = array_column($list, 'id'); $configs = $this->shop_config_model->get_batch($ids); foreach($list as &$item) { $item['config'] = $configs[$item['id']] ?? null; }` | | 🟠 警告 | `get_list_export` | **内存溢出风险**:注释掉了分页循环 `// for ($page = 1; ...)`,直接执行 `$this->select($where, $fields, '_timestamp desc');` 无 `LIMIT`。导出万级数据时将直接触发 PHP `memory_limit` 崩溃。 | 恢复分页逻辑,或使用游标/生成器逐批读取写入文件流(如 `fopen` + `fputcsv`),避免全量加载到内存。 | 保持 `for` 循环,或改用 `yield` 生成器配合流式导出。 | | 🟠 警告 | `get_detail` 方法内 | **错误的方法调用**:`$before_order_info_data = $this->ahead_yc_order_model->get_one(...)`。当前类即为 `Ahead_yc_order_model`,此处应直接调用 `$this->get_one()`,否则可能引发递归加载或属性未定义错误。 | 改为 `$this->get_one(['_id' => $order_info['before_order_id']]);` | `$before_order_info_data = $this->get_one(['_id' => $order_info['before_order_id']]);` | | 🟡 建议 | `get_bill_goods_info` | **调试代码残留**:存在 `if (1) {` 硬编码分支及大量注释掉的旧逻辑,干扰代码阅读,增加维护成本。 | 清理无用分支与注释,使用版本控制系统(Git)管理历史逻辑。 | 删除 `if (1) {` 及内部注释块,保留最终业务逻辑。 | | 🟡 建议 | `get_detail` / `get_bill_goods_info` | **拼写错误与命名不一致**:`$remard_extract` 应为 `$remark_extract`;数组定义混用 `array()` 与 `[]`;部分变量未声明类型。 | 遵循 PSR-12 规范,统一使用短数组语法 `[]`,修正拼写,建议添加 PHPDoc 类型提示。 | `$remark_extract = extractJsonAndText($remark);` | | 🟡 建议 | 全局 | **魔法数字/硬编码泛滥**:支付平台、订单类型、状态等映射数组直接写在 Model 中,且多处重复判断 `in_array(..., [17,18...])`。 | 将常量映射移至 `config/order.php` 或独立常量类;将重复的 `in_array` 判断封装为私有方法 `isCustomPayPlatform($id)`。 | `private function isCustomPayPlatform($platform) { return in_array($platform, [17,18,19,20,23,24,25,26,27,28]); }` | ## 3. 总结与行动建议 ### 🔑 优先修复的关键问题 1. **立即修复 SQL 注入**:替换 `get_bill_goods_info` 中的字符串拼接 SQL,全面改用框架查询构建器或参数化查询。 2. **移除类外 `$CI` 实例化**:将模型加载移至构造函数或依赖注入容器,避免每次文件加载时的性能损耗。 3. **解决 N+1 查询**:对 `get_list`、`get_detail`、`get_list_export_v2` 中的循环内查询进行批量重构。这是当前性能瓶颈的核心。 4. **修复导出内存泄漏**:恢复 `get_list_export` 的分页逻辑或改为流式导出,防止生产环境 OOM(Out of Memory)。 ### 🛠 后续重构与优化方向 1. **逻辑解耦与策略模式**:`get_bill_goods_info` 方法超过 300 行,包含大量 `if/elseif` 分支处理不同订单类型。建议提取为独立的 `OrderTypeHandler` 策略类,或使用工厂模式分发处理逻辑,大幅降低圈复杂度。 2. **统一数据格式化层**:当前在 Model 中大量使用 `number_format`、`date`、字符串拼接(如 `vip_card` 折扣显示)。建议将展示层格式化逻辑移至 **Service 层** 或 **View Helper**,保持 Model 仅负责数据获取与基础业务规则。 3. **框架适配确认**:代码结构高度类似 CodeIgniter 3/4。若 `phpci` 为内部定制框架,请核对官方文档中关于: - 模型自动加载机制(是否仍需 `$this->load->model()`) - 查询构建器链式调用语法 - 数据库驱动是否支持原生预处理语句 4. **引入静态分析工具**:建议接入 `PHPStan` 或 `Psalm` 进行类型检查,配合 `PHP_CodeSniffer` (PSR-12) 规范代码风格,从 CI/CD 流程拦截低级缺陷。 > 💡 **注**:由于提供的代码片段在末尾被截断,部分边界逻辑(如 `update_goods_info`、`goods_data_deal` 等辅助方法)未纳入本次审查。建议在完整代码合并前,补充单元测试覆盖核心计算逻辑(金额、折扣、退款抵扣)。 --- *此 Issue 由代码审查服务自动创建*
...
milestone_id
0
priority
0
is_closed
0
is_pull
0
num_comments
0
ref
deadline_unix
0
created_unix
1780972754
updated_unix
1780972754
closed_unix
0
is_locked
0
content_version
0
time_estimate
0
Delete
Cancel