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 576 in issue
id
Primary key.
INTEGER NOT NULL
repo_id
INTEGER
index
INTEGER
poster_id
INTEGER
original_author
TEXT
original_author_id
INTEGER
name
🔍 代码审查报告:pay-260616 - 1
TEXT
content
## 自动代码审查报告 **分支**: pay-260616 **提交**: `acf4d42d5ad729416889f928a924ceca988c6060` **提交人**: LITTLEMAIDI (11833999+littlemaidi@user.noreply.gitee.com) **时间**: 2026-06-05 18:05:57 --- ## 1. 审查摘要 - **代码质量评分**:5.5 / 10 分 - **总体评价**:该 Model 承载了订单查询、详情组装、账单计算、状态流转等大量核心业务逻辑,功能完整但代码结构臃肿。存在明显的 SQL 拼接隐患、循环内查库(N+1)性能瓶颈、MVC 分层越界(模型直接读 Session)以及多处逻辑断点。整体可维护性较低,需进行架构级重构。 - **风险等级**:🔴 高 > 📌 **框架说明**:根据目录结构(`system/`、`application/models/`、`get_instance()`、`$this->load->model()`)判断,该项目实际基于 **CodeIgniter 3** 架构。若 `phpci` 为内部定制框架,请结合其官方文档对生命周期与组件调用进行适配。 ## 2. 问题详情 | 严重程度 | 文件/行号 | 问题描述 | 建议修改方案 | 代码示例 (可选) | | :--- | :--- | :--- | :--- | :--- | | 🔴 严重 | 文件顶部 (1-4行) | 在类外部执行 `$CI = &get_instance();` 并加载模型。CI 框架在文件 `include` 时核心容器尚未初始化,极易引发 `Fatal Error`,且违反框架生命周期。 | 移除顶部过程式代码。模型继承关系应在类定义时声明,依赖模型建议在 `__construct()` 中按需加载。 | `class Ahead_yc_order_model extends CI_Model { public function __construct() { parent::__construct(); } }` | | 🔴 严重 | `get_detail` 方法 | `$order_data['before_payment'] = ...` 赋值后未合并至最终返回数组 `$data`,导致“转房前需支付金额”字段丢失,前端展示异常。 | 将计算结果直接赋值给 `$order_info` 或 `$data` 数组。 | `$order_info['before_payment'] = $before_order_info_data['_actual_pay'] ?? '';` | | 🔴 严重 | `get_bill_goods_info` | 直接使用字符串拼接构造 SQL 条件:`$sql = '_unique_key="' . $unique_key . '" ...'`。若 `$unique_key` 来源不可控,将导致 SQL 注入。 | 严格使用 CI 查询构造器(Query Builder)或参数化查询,杜绝手动拼接。 | `$this->db->where('_unique_key', $unique_key)->where_in('_status', [1,4])->get()->result_array();` | | 🟠 警告 | `get_list` 方法 | 在 `foreach` 循环内动态加载模型并执行 `get_one()` 查询。订单量稍大时将引发严重的 **N+1 查询问题**,拖垮数据库。 | 提前收集所有 `package_id`,使用 `where_in` 批量查询关联图片,再通过 PHP 数组映射回填。 | `$ids = array_column($order_info, 'package_id'); $imgs = $this->db->where_in('_id', $ids)->get('ahead_room_package')->result_array();` | | 🟠 警告 | `encode_group_buying_order` | 使用 `md5()` 进行签名校验。MD5 已存在碰撞漏洞,且未加盐,易被伪造或重放攻击。 | 改用 `hash_hmac('sha256', ...)` 或 CI 内置的 `Encryption` 库。 | `return hash_equals(hash_hmac('sha256', $order_id, $this->encrypt), $sign);` | | 🟠 警告 | `get_vip_order` | 模型层直接读取 Session:`$CI->session->{$CI->session_prefix . 'sp_month'}`。严重违反 MVC 分层原则,导致模型强耦合于 HTTP 上下文。 | 将时间过滤条件作为参数传入,或在 Controller 层组装 `$where` 后调用。 | `public function get_vip_order($merchant_id, $vipCardNo, $time_filter = null, ...)` | | 🟠 警告 | `confirm_receipt` | `$star` 参数默认值为 5,但无任何范围或类型校验。恶意传入负数或超大值将污染评分数据。 | 增加参数过滤与边界校验。 | `$star = in_array($star, range(1, 5), true) ? $star : 5;` | | 🟡 建议 | 全局/多处 | 存在大量魔术数字(如 `1, 2, 10, 14`)、拼写错误(`ORDRE_WARES_TPE`)、数组语法混用(`array()` 与 `[]`),且方法职责过重(`get_bill_goods_info` 超 300 行)。 | 统一定义为 `const`,修正拼写,遵循 PSR-12。将长方法拆分为 `calculateTotals()`、`mergeGoods()`、`formatBill()` 等私有方法。 | `const ORDER_WARES_TYPE = 2; // 修正拼写` | | 🟡 建议 | `get_detail` / `get_process` | 使用非标准函数 `throwError('订单不存在')`。CI3 中应使用 `show_error()` 或抛出 `\Exception`。 | 替换为框架标准异常处理或错误响应。 | `if (empty($order_data)) { show_error('订单不存在', 404); }` | ## 3. 总结与行动建议 ### 🔑 优先修复的关键问题 1. **修复数据丢失 Bug**:立即修正 `get_detail` 中 `$order_data['before_payment']` 未返回的问题。 2. **消除 SQL 注入风险**:将 `get_bill_goods_info` 中的字符串拼接 SQL 全面替换为 CI Query Builder 或预处理语句。 3. **移除类外过程代码**:删除文件顶部的 `$CI = &get_instance();`,确保模型在 CI 生命周期内正确实例化。 4. **解决 N+1 查询**:重构 `get_list` 的关联查询逻辑,采用批量查询(`where_in`)替代循环查库。 ### 🛠 后续重构与优化方向 1. **MVC 边界清晰化**: - 模型仅负责数据存取与基础业务计算,**禁止直接读取 `$_SESSION`、`$_GET`、`$_POST`**。 - 将 `get_bill_goods_info` 中的金额汇总、商品合并、格式化逻辑抽离至独立的 `OrderBillCalculator` 服务类中,遵循单一职责原则(SRP)。 2. **常量与配置集中管理**: - 将散落的订单状态、支付平台、场景类型等映射关系统一提取至 `config/order_config.php` 或定义为类常量,避免硬编码。 - 修正 `ORDRE_WARES_TPE` 等拼写错误,统一使用 `UPPER_SNAKE_CASE` 命名常量。 3. **安全与加密升级**: - 废弃 `md5` 签名,全面迁移至 `hash_hmac` 或 CI `Encryption` 库。 - 对金额计算引入 `bcmath` 扩展或严格使用 `number_format` 配合类型转换,避免浮点数精度丢失。 4. **代码规范与可测试性**: - 严格遵循 PSR-12,统一数组短语法 `[]`,补充方法参数类型声明与返回值类型提示。 - 拆分超长方法后,为核心计算逻辑编写 PHPUnit 单元测试,确保重构不破坏现有业务。 > ⚠️ **局限性提示**:提供的代码在 `get_timing_order` 方法末尾被截断(`return ['success' => false, 'msg' => '订单`)。若该方法涉及关键事务或复杂关联查询,请补充完整代码以便进行二次深度审查。 --- *此 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