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 361 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-260519 - 导购
TEXT
content
## 自动代码审查报告 **分支**: pc-260519 **提交**: `5ed0a300f72e86c5209446f397ff534f033e0abd` **提交人**: zhangjunnan (121158035@qq.com) **时间**: 2026-05-27 15:05:50 --- ## 1. 审查摘要 - **代码质量评分**:5.5 / 10 分 - **总体评价**:该 Model 承载了订单详情、列表查询、导出及账单商品聚合等核心业务,功能覆盖较全。但代码存在明显的 **SQL 注入隐患**、**N+1 查询性能瓶颈**、**大量重复逻辑** 以及 **不符合现代 PHP/CI 规范的写法**。整体可维护性较低,在高并发或大数据量导出场景下极易引发数据库超时或内存溢出。 - **风险等级**:🔴 高(存在直接拼接 SQL 的注入风险,且导出逻辑存在严重性能隐患) > 📌 **框架说明**:根据目录结构(`system/`、`application/`)及 `$CI = &get_instance()` 等特征,判断项目基于 **CodeIgniter 3.x** 架构。若为自研 `phpci` 框架,请参照同类 MVC 规范调整。 ## 2. 问题详情 | 严重程度 | 文件/行号 | 问题描述 | 建议修改方案 | 代码示例 (可选) | | :--- | :--- | :--- | :--- | :--- | | 🔴 严重 | `get_bill_goods_info()` 方法内 | **SQL 注入风险**:`$sql = '_unique_key="' . $unique_key . '" AND ...'` 直接拼接外部参数,未做转义或参数绑定。若 `$unique_key` 可控,将导致严重数据泄露或篡改。 | 废弃字符串拼接,全面使用 CI 查询构造器(Query Builder)或参数绑定。 | ```php<br>// 推荐写法<br>$this->db->where('_unique_key', $unique_key)<br> ->where_in('_status', [1, 4])<br> ->or_group_start()<br> ->where('_pay_platform', 10)<br> ->where('_status', -1)<br> ->group_end()<br> ->order_by('_timestamp', 'asc')<br> ->get($this->table_name)->result_array();<br>``` | | 🔴 严重 | 文件顶部 (L4-5) | **全局实例加载反模式**:在类外部执行 `$CI = &get_instance(); $CI->load->model('Simple_model');`。该代码会在文件被 `include/require` 时立即执行,导致每次请求(即使未调用此 Model)都加载依赖,浪费内存且易引发循环依赖。 | 移除顶部代码。若需加载父类/依赖,应在 `__construct()` 中处理,或通过 CI 自动加载配置(`autoload.php`)管理。 | ```php<br>// 删除顶部代码<br>class Ahead_yc_order_model extends Simple_model {<br> public function __construct() {<br> parent::__construct();<br> // 按需加载或依赖自动加载<br> }<br>}<br>``` | | 🟠 警告 | `get_list_export_v2()` 循环内 | **N+1 查询性能瓶颈**:在分页 `foreach` 循环中逐条调用 `$this->ahead_yc_order_extension_model->get_order_shopping_guide($val['id'])`。导出 1000 条数据将触发 1000 次额外查询,极易导致 DB 连接池耗尽或脚本超时。 | 收集所有订单 ID,**批量查询**导购数据,再通过数组映射(`array_column` + `array_combine`)进行关联。 | ```php<br>$order_ids = array_column($res, 'id');<br>$guide_map = $this->ahead_yc_order_extension_model->get_shopping_guide_data($order_ids);<br>foreach ($res as $val) {<br> $shopping_guide = $guide_map[$val['id']] ?? '';<br> // ...<br>}<br>``` | | 🟠 警告 | `get_detail()` 方法内 | **递归/自调用异常**:`$before_order_info_data = $this->ahead_yc_order_model->get_one(...)`。在 Model 内部调用自身实例,CI 中通常直接使用 `$this->get_one()` 即可。当前写法可能导致重复实例化或 CI 加载器异常。 | 改为直接调用当前实例方法。 | `$before_order_info_data = $this->get_one(['_id' => $order_info['before_order_id']]);` | | 🟠 警告 | `get_detail()` ~L150 | **金额计算未做边界防御**:`$order_info['actual_pay'] - $order_info['refund_amount']` 未校验类型与大小。若退款金额大于实付金额,将产生负数金额,影响财务对账。 | 增加类型转换与最小值限制,确保金额非负。 | `$actual = max(0, (float)$order_info['actual_pay'] - (float)$order_info['refund_amount']);`<br>`$order_info['actual_pay'] = number_format($actual, 2, '.', '');` | | 🟠 警告 | 全文多处 | **DRY 原则违反**:支付平台、订单类型、状态等字典转换逻辑(`in_array` + 数组映射)在 `get_detail`、`get_list`、`get_list_export` 中重复编写,维护成本极高。 | 提取为私有格式化方法,统一处理展示字段。 | ```php<br>private function _format_display_fields(&$order) {<br> $order['timestamp'] = date('Y-m-d H:i:s', $order['timestamp']);<br> $order['type_show'] = $this->type_arr[$order['type']] ?? '';<br> // ... 统一处理 pay_platform, status 等<br>}<br>``` | | 🟡 建议 | 全文 | **编码规范与类型声明缺失**:大量使用 `array()` 而非 `[]`;方法无参数类型提示与返回值声明;硬编码魔法数字(如 `[17, 18, 19...]`)散落各处。 | 遵循 PSR-12,使用短数组语法、PHP 7+ 类型声明,将硬编码提取为类常量。 | ```php<br>const CUSTOM_PAY_IDS = [17, 18, 19, 20, 23, 24, 25, 26, 27, 28];<br>public function get_detail(int $id, int $merchant_id, array $parms = []): array { ... }<br>``` | ## 3. 总结与行动建议 ### 🚨 优先修复的关键问题 1. **立即修复 SQL 注入**:将 `get_bill_goods_info` 中的字符串拼接查询替换为 CI Query Builder 或预处理语句。这是最高优先级的安全红线。 2. **消除导出 N+1 查询**:重构 `get_list_export` 与 `get_list_export_v2`,将循环内的单条查询改为批量 `WHERE IN` 查询,并使用内存数组映射关联数据。 3. **清理全局加载代码**:删除文件顶部的 `$CI = &get_instance();` 及外部 `load->model()`,改为在 `__construct()` 或 CI 自动加载器中管理依赖。 ### 🛠 后续重构与优化方向 - **逻辑抽离与 DRY 化**:当前 Model 承担了过多“视图层”职责(如字段格式化、字典转换、金额计算)。建议: - 将展示层格式化逻辑移至 `Service` 层或 `Helper` 中。 - 提取 `_format_order_for_display(array $order): array` 方法,统一处理 `timestamp`、`type_show`、`pay_platform_show` 等字段。 - **配置与常量管理**:将 `pay_platform_arr`、`type_arr`、`custom_order_pay_platform` 等硬编码数组迁移至 `config/order.php` 或使用 PHP 8 枚举(若环境支持),提升可维护性。 - **分页导出优化**:`get_list_export_v2` 使用 `for` 循环手动分页,建议改用 CI 的 `limit()` 与 `offset()` 结合生成器(`yield`)或流式处理,避免一次性加载大量数据到内存导致 `memory_limit` 溢出。 - **单元测试覆盖**:针对金额计算(实付-退款)、状态映射、特殊支付平台逻辑补充 PHPUnit 测试用例,防止后续迭代引入财务计算偏差。 > ⚠️ **局限性说明**:您提供的代码在 `get_bill_goods_info` 方法末尾(`/** 更新同一商品的数据...`)被截断,未能审查到 `update_goods_info` 等后续方法。若存在事务处理、锁机制或复杂递归逻辑,建议补充完整代码后再次进行深度审查。 --- *此 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