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 599 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 **提交**: `a43870d55562d5a4c204a97c0b0fbc9421fc6b87` **提交人**: LITTLEMAIDI (11833999+littlemaidi@user.noreply.gitee.com) **时间**: 2026-06-08 18:39:13 --- ## 1. 审查摘要 - **代码质量评分**:6.5 / 10 分 - **总体评价**:代码实现了较为复杂的预订、支付回调、退款及门店配置逻辑,业务闭环完整。但存在明显的**事务控制不规范**、**SQL 拼接隐患**、**巨型 Switch 结构**以及**硬编码泛滥**等问题。部分方法职责过重,模型加载分散,不利于后期维护与性能扩展。 - **风险等级**:🟠 中高风险(主要源于事务状态混乱、潜在 SQL 注入及敏感日志泄露) > 📌 **框架说明**:基于 `$CI = &get_instance()`、`$this->load->model()`、`$this->db->trans_start()` 等特征,代码高度符合 **CodeIgniter 3** 架构规范。若 `phpci` 为内部定制框架,请结合其官方文档对事务与模型加载机制进行微调。 --- ## 2. 问题详情 | 严重程度 | 文件/行号 | 问题描述 | 建议修改方案 | 代码示例 (可选) | | :--- | :--- | :--- | :--- | :--- | | 🔴 严重 | `Ahead_book_order_model.php`<br>`refund_by_notify` 约第 380 行 | **原始 SQL 拼接存在注入风险**。<br>`$log_where = '_relation_id="' . $order_data['_id'] . '" and ...'` 直接拼接字符串,若 `_id` 来源不可控将导致 SQL 注入。 | 使用 CI 查询构建器或参数绑定,彻底杜绝拼接。 | `$this->db->where('_relation_id', $order_data['_id'])<br> ->where('_status', 1)<br> ->where_in('_type', [5, 13]);` | | 🔴 严重 | `Ahead_book_order_model.php`<br>`check_notify` 约第 60-110 行 | **事务控制逻辑混乱**。<br>`trans_start()` 开启自动事务模式,但内部手动调用 `trans_rollback()` 后又未正确配对 `trans_complete()`,极易导致数据库连接状态异常或死锁。 | 统一使用 `trans_begin()` / `trans_commit()` / `trans_rollback()` 手动控制,或完全依赖 `trans_start()` + `trans_complete()` 自动提交/回滚。 | `// 推荐手动控制模式<br>$this->db->trans_begin();<br>try {<br> // 业务逻辑...<br> $this->db->trans_commit();<br>} catch (Exception $e) {<br> $this->db->trans_rollback();<br> throw $e;<br>}` | | 🟠 警告 | `Ahead_shop_config_second_model.php`<br>`get_shop_setting` 全方法 | **巨型 Switch 违反开闭原则**。<br>近 300 行 Switch 导致方法臃肿,新增配置需修改核心逻辑,且每次调用都会遍历匹配,性能与可维护性差。 | 采用**配置数组映射**或**策略模式**。将字段名与默认值/处理逻辑解耦。 | `private $config_map = [<br> 'book_refund_time_limit' => ['default' => 2, 'status_field' => 'book_refund_time_limit_status'],<br> // ...<br>];<br>public function get_shop_setting($mid, $sid, $field) {<br> $cfg = $this->load_config($mid, $sid);<br> return $cfg[$field] ?? ($this->config_map[$field]['default'] ?? '');<br>}` | | 🟠 警告 | `Ahead_shop_config_second_model.php`<br>`deal_audio_content_params` 约第 410 行 | **变量未初始化直接使用**。<br>`$total_time` 仅在 `if` 内部赋值,若条件不满足,PHP 8+ 会抛出 `Undefined variable` 警告。 | 在循环前显式初始化变量。 | `$total_time = ''; // 提前初始化<br>if (!empty($room_data['_open_id'])) { ... }` | | 🟠 警告 | `Ahead_book_order_model.php`<br>`send_success_msg` 全方法 | **模型重复加载 & 硬编码索引**。<br>方法内多次 `load->model()`;`$wx_template[14]['color']` 等硬编码索引脆弱且难以追踪。 | 模型应在构造函数或类属性中预加载;模板配置应提取为常量或独立配置数组。 | `// 类顶部定义<br>const WX_TMPL_BOOK_ORDER = 14;<br>// 使用时<br>$color = $wx_template[self::WX_TMPL_BOOK_ORDER]['color'] ?? '#333';` | | 🟠 警告 | `Ahead_book_order_model.php`<br>`renewal_audio_broadcast` | **循环内执行数据库查询 (N+1)**。<br>`foreach` 嵌套中调用 `get_end_time_room()`,门店/账单量大时将产生严重性能瓶颈。 | 改为批量查询:先收集所有 `end_time`,使用 `WHERE IN` 一次性拉取,再在内存中分组匹配。 | `$end_times = array_map(fn($t) => $time + $t*60, $billiards_renewal_audio_time);<br>$bill_list = $this->ahead_bill_model->get_end_time_rooms_batch($shop, $business_date, $end_times);` | | 🟡 建议 | 全局多处 | **魔法数字/字符串泛滥**。<br>`1`, `-1`, `5`, `13`, `58`, `56`, `2333` 等状态码/类型码散落各处,语义不明。 | 在类顶部定义 `const` 常量,或统一收口至配置类/枚举类。 | `const STATUS_UNPAID = -1;<br>const STATUS_PAID = 1;<br>const PAY_SCENE_WECHAT = '5';` | | 🟡 建议 | `Ahead_book_order_model.php`<br>`get_list` 约第 530 行 | **循环内查询商户信息(虽有缓存但仍可优化)**。<br>虽使用 `$merchant_business_model` 缓存,但首次请求仍会逐条查询。 | 提取所有 `merchant_id` 去重后,使用 `WHERE IN` 批量查询,再映射回数组。 | `$mids = array_unique(array_column($order_info, 'merchant_id'));<br>$merchants = $this->ahead_merchant_model->get_where_in('_id', $mids, '_id,_business_model');` | | 🟡 建议 | `Ahead_book_order_model.php`<br>`refund_by_notify` 日志记录 | **日志可能包含敏感支付信息**。<br>`doLog(var_export($input, true)...)` 会明文记录交易流水号、金额、商户号等。 | 记录前对敏感字段进行脱敏(如掩码处理)。 | `function mask_sensitive($data) {<br> $data['_trade_no'] = substr($data['_trade_no'], 0, 4) . '****';<br> return $data;<br>}` | --- ## 3. 总结与行动建议 ### 🚨 优先修复项(P0/P1) 1. **修复 SQL 注入隐患**:立即将 `refund_by_notify` 中的 `$log_where` 字符串拼接替换为 CI Query Builder 或参数绑定。 2. **规范事务生命周期**:统一 `check_notify` 及 `create_book_order` 中的事务写法。建议采用 `trans_begin()` -> 业务逻辑 -> `trans_commit()` / `trans_rollback()` 显式控制,避免与 `trans_start()` 混用导致状态机错乱。 3. **变量初始化与 PHP 8 兼容**:修复 `deal_audio_content_params` 中未初始化变量问题,避免生产环境日志报错或逻辑中断。 ### 🛠 后续重构与优化方向 1. **配置模型解耦**:`Ahead_shop_config_second_model::get_shop_setting` 建议重构为**配置映射表 + 缓存策略**。可引入 CI Cache 库(如 Redis/Memcached)替代 `self::$shop_config` 静态缓存,解决 PHP-FPM 进程驻留导致的配置脏读问题。 2. **提取业务常量与枚举**:将支付场景、订单状态、短信模板 ID 等魔法值抽离为独立配置类或 PHP 8.1+ `enum`,提升代码自解释能力。 3. **模型加载集中化**:将 `send_success_msg`、`refund_by_notify` 中频繁 `load->model()` 的操作移至类构造函数或 `__get()` 魔术方法中,减少运行时开销。 4. **批量查询优化**:针对 `renewal_audio_broadcast`、`get_list` 等循环查库场景,全面改为 `WHERE IN` 或 `JOIN` 批量拉取,降低数据库连接压力。 > ⚠️ **局限性说明**:`Ahead_book_order_model.php` 末尾的 `create_community_shop_book_order` 方法代码被截断(结束于 `if ($this->tuangou->verify_token) {`),未能对该方法的完整逻辑、团购券核销及组合支付分支进行审查。建议补充完整代码后再次进行专项评审。 --- *此 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