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 653 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 - 现场扫码退款
TEXT
content
## 自动代码审查报告 **分支**: pay-260616 **提交**: `1de21f24942458f96482e04d4bf8b4502dfe44e4` **提交人**: LITTLEMAIDI (11833999+littlemaidi@user.noreply.gitee.com) **时间**: 2026-06-09 19:12:04 --- ## 1. 审查摘要 - **代码质量评分**:6.5 / 10 分 - **总体评价**:代码实现了较为复杂的预订、支付回调、退款及账单聚合业务,整体业务闭环完整。但存在明显的架构反模式、事务与外部API耦合、SQL注入风险、N+1查询性能瓶颈以及硬编码敏感信息等问题。部分方法逻辑冗长,缺乏常量抽象与错误边界控制。 - **风险等级**:🔴 高(存在致命运行时错误、SQL注入隐患及事务锁表风险) > 📌 **框架说明**:从 `$CI = &get_instance()`、`$this->load->model()`、`$this->db->trans_start()` 等特征判断,当前代码基于 **CodeIgniter 3** 架构开发。若 `phpci` 为内部定制框架,以下建议仍完全适用,请结合官方文档微调生命周期调用。 --- ## 2. 问题详情 | 严重程度 | 文件/行号 | 问题描述 | 建议修改方案 | 代码示例 (可选) | | :--- | :--- | :--- | :--- | :--- | | 🔴 严重 | `Ahead_yc_notice_model.php`<br>`insert_after` 方法 | 将布尔属性 `$this->push_notice` 当作方法调用:`return $this->push_notice($arr);`,将直接触发 `Fatal Error: Function name must be a string` 导致服务崩溃。 | 明确区分属性与方法名,或改为条件判断后调用同名方法。 | `if ($this->push_notice === true) { return $this->push_notice($arr); }` | | 🔴 严重 | `Ahead_yc_order_model.php`<br>`get_bill_goods_info` | 直接字符串拼接 SQL 条件:`$sql = '_unique_key="' . $unique_key . '" ...'`,未做任何过滤或参数绑定,存在高危 SQL 注入漏洞。 | 全面改用 CI 查询构造器或参数绑定,杜绝手动拼接。 | `$this->db->where('_unique_key', $unique_key)->where('_status IN (1,4)')->get($this->table_name)->result_array();` | | 🔴 严重 | `Ahead_book_order_model.php`<br>`check_notify` & `refund_by_notify` | 数据库事务中包裹了外部支付退款 API 调用(如 `WxPayApi::refund`)。网络请求耗时不可控,极易导致数据库连接池耗尽、长事务锁表或超时回滚失败。 | **事务与外部调用必须解耦**。先更新本地状态并提交事务,再通过异步队列、定时任务或独立流程调用退款接口,最后通过回调对账。 | 移除 `refund_by_notify` 中的 `WxPayApi` 调用,改为记录退款任务表,由 Cron 或消息队列异步执行。 | | 🟠 警告 | `Ahead_book_order_model.php`<br>`check_notify` | 事务回滚逻辑不完整。当 `refund_by_notify` 返回 `['status'=>false]` 时,方法直接 `return`,未显式执行 `$this->db->trans_rollback()`,依赖框架隐式行为存在脏数据风险。 | 统一使用 `$this->db->trans_begin()`、`trans_commit()`、`trans_rollback()` 显式控制,或在所有异常/失败分支前显式回滚。 | `if (!$res['status']) { $this->db->trans_rollback(); return $res; }` | | 🟠 警告 | `Ahead_book_order_model.php`<br>`get_list` | 循环内执行数据库查询:`foreach ($order_info as &$v) { $merchant_data = $this->ahead_merchant_model->get_one(...); }`,典型 N+1 查询问题,数据量增长时性能呈指数级下降。 | 提取所有 `merchant_id` 使用 `where_in` 批量查询,或在主查询中使用 `JOIN` 一次性获取。 | `$ids = array_column($order_info, 'merchant_id'); $merchants = $this->ahead_merchant_model->where_in('_id', $ids)->get()->result_array();` | | 🟠 警告 | `Ahead_yc_order_model.php`<br>类属性定义 | 硬编码加密密钥:`public $encrypt = "Vs!Fs7VT";`。密钥随代码库分发,违反安全规范,一旦仓库泄露将导致历史数据可被解密。 | 移至 `config/config.php` 或 `.env` 环境变量中,通过配置项读取。 | `protected $encrypt_key; public function __construct() { $this->encrypt_key = config_item('encrypt_key'); }` | | 🟡 建议 | 全局多处 | 大量使用魔法数字(如状态 `-1, 1, 2, 3, 4, 5`,支付平台 `1, 3, 14, 22` 等),业务含义不透明,维护成本高。 | 定义类常量或独立枚举类,提升可读性与可维护性。 | `const STATUS_PENDING = -1; const PAY_PLATFORM_WECHAT = 1;` | | 🟡 建议 | `Ahead_book_order_model.php`<br>文件顶部 | 顶部直接使用 `$CI = &get_instance();` 加载模型。在 CI 架构中,模型文件被 `include` 时即执行,此时 CI 核心可能未完全初始化,易引发未定义变量或加载失败。 | 移除顶部代码,在类构造函数或具体方法内按需 `$this->load->model()`。 | 删除顶部两行,在 `__construct()` 中调用 `$this->load->model('Simple_model');` | | 🟡 建议 | `send_success_msg` 等方法 | 存在大量注释掉的废弃代码(如旧版短信发送逻辑、时间判断分支),且变量拼写错误 `$rooom_data`。 | 清理无用注释代码,依赖 Git 管理历史版本;修正拼写错误。 | 删除 `/* ... */` 块,将 `$rooom_data` 改为 `$room_data`。 | | 🟡 建议 | `Ahead_book_order_model.php`<br>`create_community_shop_book_order` | 代码在 `if ($this->tuangou->verify_token) {` 处被截断,无法评估后续逻辑完整性与事务闭合情况。 | 补充完整代码后重新提交审查,确保 `trans_complete()` 或 `trans_rollback()` 成对出现。 | *(需补充完整代码)* | --- ## 3. 总结与行动建议 ### 🚨 优先修复项(P0) 1. **修复致命调用错误**:立即修正 `Ahead_yc_notice_model::insert_after` 中的属性/方法名冲突,避免线上 Fatal Error。 2. **消除 SQL 注入风险**:将 `get_bill_goods_info` 及 `refund_by_notify` 中所有手动拼接的 SQL 条件替换为 CI 查询构造器或参数绑定。 3. **事务与外部调用解耦**:将微信支付/银联退款等网络请求移出数据库事务。采用“本地状态更新 → 提交事务 → 异步退款任务 → 回调对账”的标准支付架构。 ### 🛠 后续重构与优化方向 1. **架构规范化**: - 移除文件顶部的 `$CI = &get_instance();`,遵循 CI 模型生命周期。 - 统一使用 `$this->db->trans_begin()` / `trans_commit()` / `trans_rollback()` 替代 `trans_start()` + `try/catch` 的混合写法,提升事务可控性。 2. **性能与可维护性**: - 消除 N+1 查询,对列表类接口采用批量查询或 `JOIN` 优化。 - 提取魔法数字为类常量(如 `OrderStatus::PAID`、`PayPlatform::WECHAT`),必要时引入 PHP 8.1+ `enum`。 - 拆分超长方法(如 `get_bill_goods_info` 超过 300 行),按职责拆分为 `calculateTotals()`、`mergeGoods()`、`formatBill()` 等私有方法。 3. **安全与规范**: - 敏感配置(加密串、API 密钥、模板 ID)全部迁移至配置文件或环境变量。 - 清理历史注释代码,统一数组语法为 `[]`,遵循 PSR-12 命名与缩进规范。 - 日志记录避免直接输出 `$e->getTrace()`,改为记录 `$e->getMessage()` 与 `$e->getFile().':'.$e->getLine()`,防止敏感路径泄露。 > 💡 **提示**:若 `phpci` 为内部封装框架,请确认其事务管理器与 CI3 原生行为是否一致。建议在核心支付链路补充单元测试(PHPUnit)与集成测试,覆盖正常支付、退款失败、并发扣减库存等边界场景。 --- *此 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