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 418 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 **提交**: `bc2d373503a6800f7a8011d91dd9c460e3ff14d5` **提交人**: LITTLEMAIDI (11833999+littlemaidi@user.noreply.gitee.com) **时间**: 2026-06-01 14:10:36 --- ## 1. 审查摘要 - **代码质量评分**:4/10 - **总体评价**:该 Model 承载了过重的业务逻辑,存在明显的 SQL 注入风险、循环内重复加载模型、缺乏数据库事务保护等核心问题。代码风格偏向老旧的 CI2/CI3 混合写法,部分全局函数依赖和硬编码配置降低了可维护性。整体处于**高风险**状态,需优先进行安全加固与架构拆分。 - **风险等级**:🔴 高 > 📌 **框架说明**:根据代码特征(`get_instance()`、`$this->load->model()`、`DB_driver.php` 目录结构等),该代码实际基于 **CodeIgniter 3 (CI3)** 架构。若您使用的是内部定制版 `phpci`,请对照其官方文档确认底层 Query Builder 与 Session 组件的差异。以下建议基于 CI3 标准实践。 ## 2. 问题详情 | 严重程度 | 文件/行号 | 问题描述 | 建议修改方案 | 代码示例 (可选) | | :--- | :--- | :--- | :--- | :--- | | 🔴 严重 | `get_bill_goods_info` | **SQL 注入漏洞**:直接拼接 `$unique_key` 和 `time()` 到 SQL 字符串,未使用参数绑定或查询构建器。 | 使用 CI 查询构建器或 `$this->db->where()` 安全过滤。 | `$this->db->where('_unique_key', $unique_key)->where('_timestamp >', time() - 7*86400)->get($this->table_name)->result_array();` | | 🔴 严重 | `get_detail` (约第 180 行) | **引用赋值失效**:`foreach ($goods_info as $k => $v)` 未使用 `&`,修改 `$v['actual_amount']` 不会影响原数组。 | 改为引用遍历或直接通过键修改。 | `foreach ($goods_info as $k => &$v) { $v['actual_amount'] = '0.00'; } unset($v);` | | 🟠 警告 | `get_list` / `get_detail` | **循环内加载 Model**:在 `foreach` 中反复调用 `$this->load->model()`,导致重复初始化,严重拖慢性能。 | 将 `load->model()` 移至循环外部或类构造函数中。 | `$this->load->model(['ahead_room_package_model', 'ahead_wares_package_model']);` 放在循环前 | | 🟠 警告 | `confirm_receipt` / `close_room_after` | **缺乏数据库事务**:连续执行 `insert`/`update` 操作,若中途失败会导致订单状态与流水记录不一致。 | 使用 `$this->db->trans_start()` 包裹关键写操作。 | `if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); }` | | 🟠 警告 | `encode_group_buying_order` | **命名与实现不符**:MD5 是单向哈希,不可逆,方法名 `encode` 易误导调用方。实为签名校验。 | 重命名为 `verify_group_buying_sign()`,并明确返回布尔值。 | `public function verify_group_buying_sign($order_id, $sign) { return md5($order_id . $this->encrypt) === $sign; }` | | 🟠 警告 | `get_detail` (约第 145 行) | **死代码/未定义变量**:`$order_data['before_payment'] = ...` 赋值后从未使用或返回,且 `$order_data` 未初始化。 | 移除无用代码,或补充至返回数组 `$data['before_payment']`。 | 删除该行或改为 `$data['before_payment'] = $before_order_info_data['_actual_pay'] ?? '';` | | 🟡 建议 | 类属性/常量区 | **拼写错误与冗余**:`ORDRE_WARES_TPE`、`WCHAT_WEB` 拼写错误;`$pay_platform_arr` 与 `const ORDER_PAY_PLATFORM_ARR` 内容重复。 | 修正拼写,统一使用 `const` 或 `private static array`,移除冗余数组。 | `const ORDER_WARES_TYPE = 2;`<br>`const WECHAT_WEB = '...';` | | 🟡 建议 | `get_vip_order` | **非标准 Session 访问**:`$CI->session->{$CI->session_prefix . 'sp_month'}` 为 CI2 遗留写法,CI3 应使用 Session 库。 | 使用 `$this->session->userdata('sp_month')` 或配置项。 | `if ($this->session->userdata('sp_month')) { $where['_timestamp>'] = strtotime('-3 month'); }` | | 🟡 建议 | 全局依赖 | **强依赖全局函数**:多处调用 `throwError()`、`minToStr()`、`send_wx_pay_order()`,破坏封装性且难以单元测试。 | 封装为 Helper 或 Service 类,通过依赖注入或静态方法调用。 | `Helper::throwError('订单不存在');` 或 `$this->load->helper('common');` | ## 3. 总结与行动建议 ### 🔑 优先修复的关键问题 1. **立即修复 SQL 注入**:`get_bill_goods_info` 中的 `$sql` 拼接必须替换为 CI Query Builder 或预处理语句。 2. **修复数组引用 Bug**:`get_detail` 中 `pay_platform == 9` 的循环修改无效,会导致前端展示原价错误。 3. **补充事务控制**:所有涉及多表状态变更的方法(如 `confirm_receipt`、`close_room_after`、`bindingOrder`)必须包裹在数据库事务中,防止脏数据。 ### 🛠 后续重构与优化方向 1. **拆分超长方法**:`get_detail` 和 `get_bill_goods_info` 均超过 200 行,严重违反单一职责原则(SRP)。建议: - 将“订单基础信息组装”、“商品明细处理”、“团购/积分/支付场景扩展”拆分为独立的 `private` 方法或移至 `OrderService` 层。 - 使用策略模式(Strategy Pattern)处理不同 `pay_platform` 或 `type` 的差异化逻辑,替代冗长的 `if/elseif`。 2. **规范 CI3 最佳实践**: - 移除文件顶部的 `$CI = &get_instance();`,Model 内部应直接使用 `$this->load->...` 或 `$this->db->...`。 - 统一数组语法为短数组 `[]`,遵循 PSR-12 缩进与命名规范。 - 将硬编码的 `$encrypt` 移至 `config.php` 或环境变量中,避免敏感信息硬编码。 3. **性能优化**: - 消除 N+1 查询:`get_list` 中通过循环查套餐图片,可改为 `WHERE IN` 批量查询后内存映射。 - 缓存静态字典:`$pay_id_arr`、`$type_arr` 等配置型数组可移至 `config` 文件或 Redis 缓存,减少类实例化开销。 > ⚠️ **局限性说明**:您提供的代码在 `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