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 622 from issue
id
622
repo_id
21
index
280
poster_id
1
original_author
original_author_id
0
name
🔍 代码审查报告:pay-260616 - 包厢配送可以合并配送的增加判断起购数。
content
## 自动代码审查报告 **分支**: pay-260616 **提交**: `a2bcc6060
## 自动代码审查报告 **分支**: pay-260616 **提交**: `a2bcc6060a2ffddb47d4bf3df51c3a6cdf98f54c` **提交人**: zhangjunnan (121158035@qq.com) **时间**: 2026-06-09 10:50:05 --- ## 1. 审查摘要 - **代码质量评分**:4 / 10 分 - **总体评价**:该 Model 承载了大量核心订单业务逻辑,但实现方式较为原始。存在 **SQL 注入风险、硬编码敏感密钥、循环内查询导致的严重性能瓶颈、关键写操作缺失事务** 等高危问题。代码规范与框架最佳实践偏离较大,魔法数字泛滥,方法职责过重(如 `get_bill_goods_info` 超 200 行),可维护性与扩展性较差。 - **风险等级**:🔴 高 > 📌 **框架说明**:从代码结构(`get_instance()`、`$this->load->model()`、`system/` 目录)判断,该代码基于 **CodeIgniter 3** 架构。若 `phpci` 为贵司内部定制框架,以下基于 CI 标准的审查建议同样适用。若存在差异,请以 `phpci` 官方文档为准。 ## 2. 问题详情 | 严重程度 | 文件/行号 | 问题描述 | 建议修改方案 | 代码示例 (可选) | | :--- | :--- | :--- | :--- | :--- | | 🔴 严重 | `get_bill_goods_info` (~L340) | **SQL 注入漏洞**:使用字符串直接拼接构建查询条件 `$sql = '_unique_key="' . $unique_key . '" ...`,未进行参数绑定或转义,攻击者可构造恶意输入破坏查询或拖库。 | 废弃字符串拼接,全面使用框架提供的查询构建器(Query Builder)或预处理语句。 | `$this->db->where('_unique_key', $unique_key);`<br>`$this->db->where_in('_status', [1, 4]);` | | 🔴 严重 | `confirm_receipt` (~L285) | **数据一致性风险**:连续执行两次 `insert` 写入订单状态流转记录,未包裹数据库事务。若第二次写入失败,将导致订单状态停留在“已送达”而非“已完成”,引发业务状态不一致。 | 使用框架事务机制包裹关键写操作,失败时自动回滚。 | `$this->db->trans_start();`<br>`$this->ahead_yc_order_process_model->insert($data1);`<br>`$this->ahead_yc_order_process_model->insert($data2);`<br>`$this->db->trans_complete();`<br>`if (!$this->db->trans_status()) { $this->db->trans_rollback(); return false; }` | | 🔴 严重 | 类属性定义 (~L10) | **硬编码敏感信息 & 弱加密**:`public $encrypt = "Vs!Fs7VT";` 将密钥明文暴露在源码中;且 `md5()` 校验签名易受彩虹表破解,且未使用防时序攻击比对。 | 密钥移至 `config/` 或环境变量;签名校验改用 `hash_equals()`;敏感数据加密建议改用 `openssl_encrypt()` 或框架内置 Encryption 库。 | `if (hash_equals($expected_sign, $sign)) { return true; }` | | 🟠 警告 | `get_list` (~L135) | **严重性能瓶颈 (N+1 查询)**:在 `foreach` 循环中动态 `load->model` 并执行 `get_one`。若列表返回 50 条数据,将触发 50+ 次独立 SQL 查询与模型加载,极易导致数据库连接耗尽与接口超时。 | 模型统一在 `__construct` 加载;使用 `WHERE IN` 批量查询关联数据,或在数据库层使用 `JOIN` 一次性拉取。 | `$ids = array_column($order_info, 'package_id');`<br>`$this->db->where_in('_id', $ids)->get('ahead_room_package')->result_array();` | | 🟠 警告 | `get_detail` (~L220) | **逻辑/变量错误**:`$order_data['before_payment'] = ...` 中 `$order_data` 未定义(应为 `$order_info`);且 `$this->ahead_yc_order_model->get_one()` 在自身类中调用冗余且易引发递归加载。 | 修正变量名,直接使用 `$this->get_one()` 查询当前表数据。 | `$before_order = $this->get_one(['_id' => $order_info['before_order_id']], '_actual_pay');`<br>`$order_info['before_payment'] = $before_order['_actual_pay'] ?? '';` | | 🟠 警告 | 全局/多处 | **模型重复加载**:每个方法内部频繁调用 `$this->load->model()`,违反框架最佳实践,增加文件 I/O 与内存开销。 | 统一在 `__construct()` 中加载依赖模型,或配置 `autoload.php` 自动加载。 | `public function __construct() { parent::__construct(); $this->load->model(['ahead_room_package_model', 'ahead_yc_order_extension_model']); }` | | 🟡 建议 | 全文件 | **命名规范不一致**:方法名混用驼峰 (`bindingOrder`) 与下划线 (`binding_order_check`);数组与常量定义重复 (`$pay_id_arr` vs `const ORDER_PAY_PLATFORM_ARR`)。 | 遵循 PSR-12 统一使用下划线命名法;将映射关系收敛至 `config/` 目录或单一常量类,避免散落。 | `const PAY_PLATFORM_MAP = [1 => '微信', 2 => '支付宝', ...];` | | 🟡 建议 | `get_bill_goods_info` (~L350) | **魔法数字泛滥**:大量硬编码状态值(如 `1, 2, 10, 14, -1`)散落在业务逻辑中,可读性差且修改易遗漏。 | 提取为类常量或枚举(PHP 8.1+),并在逻辑判断中引用常量。 | `if ($order['_pay_platform'] === self::ORDER_VIP_PAY_PLATFORM) { ... }` | ## 3. 总结与行动建议 ### 🚨 优先修复(P0/P1) 1. **修复 SQL 注入**:立即替换 `get_bill_goods_info` 中的字符串拼接查询,全面改用 `$this->db->where()` / `$this->db->where_in()`。 2. **补充数据库事务**:为 `confirm_receipt`、`bindingOrder` 等涉及多表写入或状态流转的方法添加 `$this->db->trans_start()` / `$this->db->trans_complete()` 机制。 3. **消除循环内查询**:重构 `get_list` 与 `get_detail`,将模型加载移至构造函数,使用批量查询或 `JOIN` 替代 `foreach` 中的单条查询。 4. **移除硬编码密钥**:将 `$encrypt` 迁移至配置文件,签名校验替换为 `hash_equals()`,避免安全审计不通过。 ### 🛠 后续重构方向 1. **拆分巨型方法**:`get_bill_goods_info` 逻辑过于臃肿(超 300 行),建议按职责拆分为:`calculateBillTotals()`、`formatGoodsList()`、`handleSpecialPlatforms()` 等私有方法,提升可测试性。 2. **统一状态管理**:将散落的 `$pay_id_arr`、`$type_arr` 等映射数组迁移至 `application/config/order_status.php`,或使用 PHP 8.1 `enum` 管理,彻底消除魔法数字。 3. **补充类型声明**:建议为所有公开方法添加参数类型与返回值类型声明(如 `public function get_list(array $where, int $page, int $page_size): array`),提升 IDE 提示与静态分析能力。 4. **清理历史债务**:移除 `//add by nan 24.3.7` 等过时注释、被注释的废弃代码及未使用的局部变量,保持代码库整洁。 > ⚠️ **局限性说明**:您提供的代码在 `get_timing_order` 方法处被截断,未能完整审查该方法及后续可能存在的逻辑。建议补充完整代码后再次进行针对性审查。若 `phpci` 框架对事务、查询构建器或模型加载有特殊封装,请以官方文档为准进行适配调整。 --- *此 Issue 由代码审查服务自动创建*
...
milestone_id
0
priority
0
is_closed
0
is_pull
0
num_comments
0
ref
deadline_unix
0
created_unix
1780973405
updated_unix
1780973405
closed_unix
0
is_locked
0
content_version
0
time_estimate
0
Delete
Cancel