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 258 in issue
id
Primary key.
INTEGER NOT NULL
repo_id
INTEGER
index
INTEGER
poster_id
INTEGER
original_author
TEXT
original_author_id
INTEGER
name
🔍 代码审查报告:app-260519 - 预订开房后去开房订单退款,更新自助营业两个报表
TEXT
content
## 自动代码审查报告 **分支**: app-260519 **提交**: `4d56bfce58b5a6aa4f3a82b3b494c92db85e6ec4` **提交人**: LITTLEMAIDI (11833999+littlemaidi@user.noreply.gitee.com) **时间**: 2026-05-20 18:51:13 --- ## 1. 审查摘要 - **代码质量评分**:5.5 / 10 分 - **总体评价**:该 Model 承载了支付流水、账单查询、报表统计、退款核心逻辑及第三方 API 调用,功能完整但**职责严重越界**。代码存在明显的 SQL 注入风险、循环内 N+1 查询性能瓶颈、事务与异常处理不一致等问题。类型处理松散、硬编码较多,不符合现代 PHP 工程化规范。 - **风险等级**:🔴 高 ## 2. 问题详情 | 严重程度 | 文件/行号 | 问题描述 | 建议修改方案 | 代码示例 (可选) | | :--- | :--- | :--- | :--- | :--- | | 🔴 严重 | `update_refund_amount` / `refund` | **SQL 注入漏洞**:多处使用字符串拼接构造 `WHERE` 和 `UPDATE` 语句(如 `'_relation_id="' . $relation_id . '"`),未进行参数绑定或转义。 | 全面替换为框架查询构造器(Query Builder)或预处理语句,严禁直接拼接用户/业务输入。 | `$this->db->where('_relation_id', $relation_id)->where('_type', $type)->where_in('_status', [1,4])->update($this->table_name, $data);` | | 🔴 严重 | `refund` 方法 | **事务与异常处理不一致**:使用自定义 `throwError()` 中断流程,若该函数非标准 `Exception` 或包含 `exit/die`,可能导致事务状态混乱或重复回滚。 | 统一使用 PHP 标准异常 `throw new \RuntimeException()`,配合 `try-catch-finally` 确保事务安全提交/回滚。 | `try { $this->db->trans_begin(); /* 业务逻辑 */ $this->db->trans_commit(); } catch (\Exception $e) { $this->db->trans_rollback(); throw $e; }` | | 🟠 警告 | `get_bill_pay_log` / `get_refundable_pay_log` | **N+1 查询性能瓶颈**:在 `foreach` 循环内频繁调用 `get_one()` 加载关联模型(订单、扩展、用户、配置等),数据量稍大即导致数据库连接耗尽与响应超时。 | 提取循环所需 ID,使用 `WHERE IN` 批量查询,在内存中通过 `array_column` 或键值映射进行关联。 | `$ids = array_column($log_data, 'relation_id'); $orders = $this->ahead_yc_order_model->get_list(['where_in' => ['_id', $ids]]); $orderMap = turn_array_key($orders, '_id');` | | 🟠 警告 | `get_bill_pay_log` | **未定义变量风险**:`$bondsman_data` 仅在 `if (!empty($bondsman))` 内赋值,后续 `$bondsman_data['_name'] ?? ''` 在 PHP 8+ 会触发 `Undefined variable` 警告。 | 在循环外或条件分支前初始化变量。 | `$bondsman_data = []; if (!empty($bondsman)) { $bondsman_data = $this->ahead_yc_merchant_user_model->get_one(...); }` | | 🟠 警告 | `get_business` | **时间范围校验缺陷**:`strtotime()` 可能返回 `false`,直接参与减法运算会导致逻辑错误或类型警告。 | 增加时间格式校验,或使用 `DateTime` 对象进行安全计算。 | `$start = strtotime($params['start_time']); $end = strtotime($params['end_time']); if ($start === false || $end === false || ($end - $start) > 31 * 86400) throwError("...");` | | 🟡 建议 | 类定义顶部 | **模型加载位置不当**:类外部使用 `$CI = &get_instance(); $CI->load->model('Simple_model');`,破坏封装性且可能引发重复加载。 | 移除外部加载,依赖框架自动加载或在 `__construct()` 中处理。若 `Simple_model` 为父类,直接 `extends` 即可。 | `class Ahead_pay_log_model extends Simple_model { public function __construct() { parent::__construct(); } }` | | 🟡 建议 | `mobile_refund` | **硬编码敏感信息**:MD5 盐值 `'1441600902'`、`'2017040606573534'` 及 Redis DB 索引硬编码在业务逻辑中,存在泄露风险且不利于多环境配置。 | 将密钥、盐值、Redis 配置移至 `config/` 目录,通过 `$this->config->item()` 读取。 | `$salt = $this->config->item('wx_refund_salt'); $data['refund_key'] = md5($order_info['_id'] . $order_info['_trade_no'] . $salt);` | | 🟡 建议 | 全局多处 | **类型不一致与松散比较**:数组键混用字符串 `'1'` 与整型 `1`,`in_array` 未开启严格模式,易引发隐式类型转换 Bug。 | 统一使用整型作为键/值,所有比较操作使用严格模式 `===` 或 `in_array($val, $arr, true)`。 | `const PAY_LOG_TITLE_MAP = [1 => '订单支付', 2 => '账单支付']; if (!in_array($type, array_keys(self::PAY_LOG_TITLE_MAP), true)) { ... }` | | 🟡 建议 | `add_order_pay_log` | **冗余计算与死代码**:`$actual_pay += $params['_actual_pay'];` 累加后从未使用,增加无意义内存开销。 | 移除未使用的变量,或明确其业务用途(如返回给调用方)。 | `// 删除 $actual_pay 相关累加逻辑` | > 📝 **框架适配说明**:基于 `$CI = &get_instance()`、`$this->load->model()`、`$this->db->trans_begin()` 等特征,判定代码运行于 **CodeIgniter 3** 或高度定制的同构框架。以下建议基于 CI3 最佳实践。若 `phpci` 为内部自研框架,请核对事务管理与查询构造器 API 是否一致。 ## 3. 总结与行动建议 ### 🔑 优先修复的关键问题 1. **立即修复 SQL 注入**:`update_refund_amount` 与 `refund` 中的原始 SQL 拼接是最高危漏洞,必须替换为 Query Builder 或参数绑定。 2. **统一异常与事务机制**:废弃全局 `throwError()` 中断模式,改用 `try-catch` 包裹事务块,确保资金操作具备强一致性。 3. **消除 N+1 查询**:`get_bill_pay_log` 等列表方法必须改为批量查询+内存映射,否则在并发或数据量增长时将直接拖垮数据库。 ### 🛠 后续重构与优化方向 - **架构分层(SRP 原则)**:当前 Model 承担了数据持久化、业务规则校验、第三方 API 调用、Redis 操作、报表计算等职责。建议拆分为: - `Model`:仅负责 CRUD 与基础查询构造。 - `Service/Domain`:处理退款流程、状态机流转、跨模型事务协调。 - `Gateway/Client`:封装微信/支付宝退款 API 调用。 - **配置集中化**:将支付类型映射、自定义支付平台、MD5 盐值、Redis 索引等全部抽离至 `config/` 文件,便于多环境部署与安全审计。 - **类型安全与 PSR-12 规范**:启用 PHP 8 严格类型声明(`declare(strict_types=1);`),统一方法命名(驼峰或下划线保持一致),补充 PHPDoc 类型注解(`@param int $type`, `@return array` 等)。 - **代码片段局限性说明**:末尾 `add_by_vip_recharge_order` 方法被截断,无法评估其完整逻辑与潜在风险。建议补充完整代码后二次审查。 > 💡 **行动建议**:建议先建立自动化测试用例覆盖核心退款与流水插入流程,随后按 `安全修复 → 性能优化 → 架构重构` 的顺序迭代。如涉及资金结算,务必在预发环境进行全链路压测与事务回滚验证。 --- *此 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