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 398 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 **提交**: `8a6a915ea2cb13136936a4525cd43d2b44ba36ce` **提交人**: zhangjunnan (121158035@qq.com) **时间**: 2026-05-28 13:30:28 --- ## 1. 审查摘要 - **代码质量评分**:4/10 分 - **总体评价**:该 Model 承载了极其复杂的订单查询、账单聚合与导出逻辑,业务覆盖全面,但代码呈现出典型的“遗留系统”特征。存在严重的 SQL 注入隐患、高频的 N+1 数据库查询、超长方法体(违反单一职责原则)以及大量硬编码魔法数字。整体可维护性、安全性与性能表现均不达标,急需系统性重构。 - **风险等级**:🔴 高 ## 2. 问题详情 | 严重程度 | 文件/行号 | 问题描述 | 建议修改方案 | 代码示例 (可选) | | :--- | :--- | :--- | :--- | :--- | | 🔴 严重 | `get_bill_goods_info` ~L385 | **SQL 注入漏洞**:`$unique_key` 未经过滤直接拼接至 SQL 字符串 `$sql = '_unique_key="' . $unique_key . '" AND ...'`,攻击者可构造恶意输入破坏查询或拖库。 | 彻底移除字符串拼接,改用框架查询构建器(Query Builder)或参数绑定。 | `$this->db->where('_unique_key', $unique_key)->where_in('_status', [1,4])->or_where(['_pay_platform' => 10, '_status' => -1])->order_by('_timestamp', 'ASC')->get($this->table_name)->result_array();` | | 🔴 严重 | 文件顶部 ~L3-4 | **反模式:类外部加载实例**:`$CI = &get_instance(); $CI->load->model('Simple_model');` 在类定义外执行。CI 框架中 Model 应通过 `extends CI_Model` 或基类自动继承,全局调用会破坏生命周期且可能引发内存泄漏。 | 删除全局代码,确保类正确继承框架基类,依赖自动加载或构造函数初始化。 | `class Ahead_yc_order_model extends Simple_model { // 移除顶部 $CI 代码 }` | | 🟠 警告 | `get_detail` ~L68-69 | **冗余查询**:连续执行两次 `get_one($where)`,仅字段不同。造成不必要的数据库往返与内存开销。 | 仅查询一次全量数据,后续通过 `array_intersect_key` 或手动映射提取所需字段。 | `$order = $this->get_one($where); $fields_map = ['_id'=>'id', '_no'=>'no']; $order_info = array_map(fn($k)=>$order[$k]??null, $fields_map);` | | 🟠 警告 | `get_list` / `get_list_export` 循环内 | **N+1 查询性能瓶颈**:在 `foreach` 循环中逐行调用 `get_custom_pay_platform()` 与 `get_order_shopping_guide()`。数据量过百时将引发数百次 DB 请求,极易导致接口超时。 | 改为批量查询:收集所有 `shop_id` 和 `pay_platform`,使用 `WHERE IN` 一次性拉取配置,再通过 PHP 数组映射填充。 | `$ids = array_column($res, 'id'); $configs = $this->shop_config_model->get_batch($ids); foreach($res as &$val){ $val['pay_platform_show'] = $configs[$val['id']] ?? ''; }` | | 🟠 警告 | `get_bill_goods_info` ~L430 | **除零风险与类型安全**:`$v['actual_amount'] / $v['discount_rate'] * 100` 未判断 `$v['discount_rate']` 是否为 `0` 或空值,可能触发 `Division by zero` 警告或返回 `INF`。 | 增加安全校验,使用默认折扣率(如 100)。 | `$rate = ($v['discount_rate'] > 0) ? $v['discount_rate'] : 100; $price = number_format($v['actual_amount'] / $rate * 100, 2, '.', '');` | | 🟠 警告 | `get_list_export_v2` | **PHP 内存累积计算总额**:在循环中使用 `$total_amount += $val['amount']` 累加。浮点数累加易产生精度丢失,且大数据量导出时 PHP 内存占用过高。 | 将总额统计下沉至数据库层,使用 `SUM()` 聚合函数一次性返回。 | `SELECT SUM(_prime_actual_pay) as total_amount, SUM(_actual_pay) as total_actual_pay FROM ...` | | 🟡 建议 | 全文多处 | **魔法数字与硬编码**:大量使用 `17,18,19...`、`'1'=>'酒水订单'` 等硬编码,散落在业务逻辑中,后期维护成本极高。 | 将映射关系提取为类常量或独立配置类,使用 `const` 或 `readonly` 属性管理。 | `const PAY_PLATFORM_CUSTOM = [17,18,19,20,23,24,25,26,27,28]; if (in_array($platform, self::PAY_PLATFORM_CUSTOM)) { ... }` | | 🟡 建议 | `get_detail` / `get_bill_goods_info` | **超长方法违反单一职责**:单个方法超过 300 行,嵌套 `if/else` 与 `foreach` 达 5 层以上,包含数据查询、格式化、业务规则计算、视图组装等混合逻辑。 | 按业务边界拆分为私有方法:如 `formatOrderDetail()`, `calculateBillTotals()`, `processGoodsMerge()`。主方法仅负责流程编排。 | `public function get_detail(...){ $order = $this->fetchOrder(...); $order = $this->enrichOrderData($order); return $this->assembleResponse($order); }` | | 🟡 建议 | 全文 | **不符合 PSR-12 规范**:使用旧式 `array()` 语法、缺少类型声明、缩进不一致、注释与代码混杂。 | 全面升级至 PHP 7.4+/8.x 语法:短数组 `[]`、属性/参数类型声明、返回值类型声明。 | `public function get_detail(int $id, int $merchant_id, array $parms = []): array` | ## 3. 总结与行动建议 ### 🔑 优先修复的关键问题 1. **立即修复 SQL 注入**:`get_bill_goods_info` 中的 `$unique_key` 拼接是最高危漏洞,必须在下一个发版前替换为参数绑定或 Query Builder。 2. **消除 N+1 查询**:`get_list` 与导出方法中的循环内 DB 调用是性能杀手。请改为 `WHERE IN` 批量查询 + 内存映射,预计可将接口响应时间降低 70% 以上。 3. **移除冗余查询**:`get_detail` 中的双 `get_one` 调用应合并,减少无效 IO。 ### 🛠 后续重构与优化方向 1. **架构解耦(策略模式/责任链)**:当前 `get_bill_goods_info` 使用巨型 `if/elseif` 处理不同订单类型(酒水、套餐、计时开房等)。建议引入**策略模式**,将各类型账单计算逻辑抽离为独立的 `BillCalculator` 类,主方法仅负责路由分发。 2. **数据聚合下沉**:导出与列表的总额统计(`total_amount`, `total_refund_amount`)强烈建议交由数据库 `GROUP BY` 或窗口函数完成,避免 PHP 层处理大数据集时的内存溢出与精度问题。 3. **框架规范对齐**: - 注:根据目录结构(`system/`, `application/`)及 `$this->load->model()` 等特征,该框架应为 **CodeIgniter (CI2/CI3)**。若 `phpci` 为内部定制版,请以官方文档为准。 - 移除文件顶部的 `$CI = &get_instance()`,依赖 CI 的自动加载机制。 - 将 `force index(_merchant_id)` 等硬编码索引提示移至数据库配置或查询构建器中,避免优化器失效。 4. **代码规范升级**:启用 `PHP_CodeSniffer` 配合 `PSR-12` 规则集进行静态扫描。逐步添加 `declare(strict_types=1);` 与类型声明,提升代码健壮性。 > ⚠️ **局限性说明**:提供的代码在 `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