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 621 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-260616 - Merge pull request '111' (#191) from pc into pc-26
TEXT
content
## 自动代码审查报告 **分支**: pc-260616 **提交**: `4164e2450b0c34aefa95cf473682e005c6e9833f` **提交人**: zhangjunnan (121158035@qq.com) **时间**: 2026-06-09 10:39:44 --- ## 1. 审查摘要 - **代码质量评分**:5.5 / 10 分 - **总体评价**:该 Model 承载了核心订单业务,功能覆盖较全,但存在明显的架构设计缺陷。代码中混用全局实例、循环内频繁查库(N+1 问题)、硬编码逻辑重复严重,且存在高危 SQL 注入风险。整体可维护性与扩展性较差,亟需进行安全加固与结构重构。 - **风险等级**:🔴 高(存在 SQL 注入隐患、财务金额计算越界风险、大数据量导出易导致 OOM/超时) --- ## 2. 问题详情 | 严重程度 | 文件/行号 | 问题描述 | 建议修改方案 | 代码示例 (可选) | | :--- | :--- | :--- | :--- | :--- | | 🔴 严重 | `get_bill_goods_info` (~L450) | **SQL 注入漏洞**:使用字符串拼接构造 `$sql` 并直接传入 `$this->select()`,未使用参数绑定或查询构造器,极易被恶意构造的 `$unique_key` 攻击。 | 废弃原生拼接,全面改用 CI 查询构造器或参数绑定。 | `$this->db->where('_unique_key', $unique_key)->where_in('_status', [1,4])->or_group_start()->where('_pay_platform', 10)->where('_status', -1)->group_end()->get()->result_array();` | | 🔴 严重 | 文件顶部 (~L4) | **全局 CI 实例滥用**:`$CI = &get_instance();` 在类外部执行,违反框架生命周期管理,易引发内存泄漏、上下文污染及单元测试困难。 | 移除全局调用,在类构造函数中通过 `$this->load->model()` 加载依赖。 | `public function __construct() { parent::__construct(); $this->load->model('Simple_model'); }` | | 🟠 警告 | `get_list_export_v2` / `get_bill_goods_info` | **N+1 查询性能瓶颈**:在 `foreach` 循环中逐条调用 `$this->ahead_yc_order_extension_model->get_order_shopping_guide($val['id'])`,数据量过万时将导致数据库连接耗尽或请求超时。 | 循环外收集所有 ID,使用 `WHERE IN` 批量查询,在 PHP 层通过键值映射回填数据。 | 见下方重构示例 | | 🟠 警告 | `get_bill_goods_info` (~L465) | **死代码/调试残留**:`if (1) { ... }` 无条件执行,掩盖原始业务意图,且内部包含大量注释掉的旧逻辑,干扰阅读。 | 移除 `if (1)` 及对应闭合括号,清理无用注释,保留核心逻辑。 | 直接删除 `if (1)` 结构,保留内部代码块 | | 🟠 警告 | `get_detail` (~L115) | **金额计算未处理负数边界**:`$order_info['actual_pay'] - $order_info['refund_amount']` 在异常退款场景下可能为负值,直接 `number_format` 会导致财务对账异常。 | 增加业务边界校验,确保实付金额非负。 | `$actual = max(0, $order_info['actual_pay'] - $order_info['refund_amount']);` | | 🟡 建议 | 全局多处 (`get_detail`, `get_list` 等) | **严重违反 DRY 原则**:支付平台映射、格式化逻辑在 4 个方法中重复编写,维护成本极高。 | 抽取为受保护的私有方法,统一处理映射与格式化。 | `protected function resolvePayPlatform($platform, $shopId = null) { ... }` | | 🟡 建议 | 类属性定义 | **数组语法与命名不统一**:混用 `array()` 和 `[]`,属性如 `pay_id_arr` 语义模糊,不符合现代 PHP 规范。 | 统一使用短数组语法 `[]`,将静态映射提升为 `const` 常量,遵循 PSR-12。 | `const PAY_STATUS_MAP = ['-1' => '待支付', '1' => '已付款', ...];` | | 🟡 建议 | `get_detail` / `get_bill_goods_info` | **隐式依赖全局函数**:调用 `extractJsonAndText()` 和 `minToStr()` 未在类中声明或显式引入 Helper,降低代码可移植性与可测试性。 | 在文件顶部显式加载 Helper,或将其封装为独立服务类注入。 | `helper('custom_helper');` 或依赖注入 | --- ## 3. 总结与行动建议 ### 🚨 优先修复的关键问题 1. **立即修复 SQL 注入**:将 `get_bill_goods_info` 中的 `$sql` 拼接替换为 `$this->db->where()` 链式调用,杜绝注入风险。 2. **消除 N+1 查询**:在 `get_list_export_v2` 和 `get_bill_goods_info` 中,将循环内的单条查询改为批量查询(`WHERE IN`),在内存中完成数据关联。 3. **清理全局实例与死代码**:移除文件顶部的 `$CI = &get_instance();`,将模型加载移至 `__construct()`;删除 `if (1)` 及注释掉的冗余逻辑。 ### 🛠 后续重构与优化方向 1. **逻辑抽离与 DRY 化**: 支付平台展示、状态映射、金额格式化等逻辑高度重复。建议抽取为独立方法或 `OrderFormatter` 服务类: ```php protected function formatOrderItem(array $order, array $extensionData = []): array { $order['pay_platform_show'] = $this->resolvePayPlatform($order['pay_platform'], $order['shop_id']); $order['actual_pay'] = number_format(max(0, $order['actual_pay'] - $order['refund_amount']), 2, '.', ''); $order['timestamp'] = date('Y-m-d H:i:s', $order['timestamp']); return $order; } ``` 2. **批量查询优化示例**(替代循环内查库): ```php // 优化前:循环内查询 // $shopping_guide = $this->model->get_order_shopping_guide($val['id']); // 优化后:批量查询 + 映射 $orderIds = array_column($res, 'id'); $guideData = $this->ahead_yc_order_extension_model->get_shopping_guide_batch($orderIds); // 需实现批量方法 foreach ($res as &$val) { $val['shopping_guide'] = $guideData[$val['id']] ?? ''; } ``` 3. **框架适配说明**: > ⚠️ 注:当前代码呈现典型的 **CodeIgniter 3** 架构特征(如 `$CI = &get_instance()`、`$this->load->model()`、`system/helpers/` 目录结构)。若 `phpci` 为内部定制或二次开发框架,请确认其核心加载器是否完全兼容 CI3。建议后续逐步向 PSR-4 自动加载、依赖注入容器及现代 ORM(如 Eloquent/Doctrine)迁移,以提升架构健壮性。 4. **局限性提示**: 提供的代码片段在 `get_bill_goods_info` 方法末尾被截断(`$goods_info['goods_unit_nam`),未能审查完整逻辑。建议补充完整文件后再次进行边界条件与事务一致性审查。 --- *此 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