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 205 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-260519 - 需求 批量更新套餐价格 16243
TEXT
content
## 自动代码审查报告 **分支**: pc-260519 **提交**: `41d42b37c5fb501da45919d9db8f657fea3e6ba5` **提交人**: chenjunfeng (developer.jeff.c@gmail.com) **时间**: 2026-05-19 15:58:20 --- ## 1. 审查摘要 - **代码质量评分**:6.5 / 10 分 - **总体评价**:代码整体业务逻辑清晰,实现了包断价格与计时开房的核心增删改查功能,并考虑了软删除、时间重叠校验及多门店/包厢关联查询。但存在**变量拼写错误、循环内状态污染、SQL 注入风险**等严重缺陷,且多处违反框架生命周期规范与 PSR 编码习惯,需优先修复。 - **风险等级**:🔴 高 ## 2. 问题详情 | 严重程度 | 文件/行号 | 问题描述 | 建议修改方案 | 代码示例 (可选) | | :--- | :--- | :--- | :--- | :--- | | 🔴 严重 | `Ahead_room_timing_bd_model.php`<br>`add_bd_prise_set` 方法内 | 变量名拼写错误 `$param` 应为 `$params`,导致所有动态 VIP 价格字段均被赋值为默认值 `0`,造成资损。 | 修正变量引用,确保读取正确的入参数组。 | `$addData['_bd_vip_level'.$i.'_price'] = $params['bd_vip_level'.$i.'_price'] ?? 0;` | | 🔴 严重 | `Ahead_room_timing_bd_model.php`<br>`_check_time_overlap` 方法内 | 循环内直接修改 `$targetStartTime` 与 `$targetEndTime`,未使用临时变量。第二次及后续循环迭代将基于已偏移的时间进行校验,导致重叠检测逻辑完全失效。 | 在每次循环开始时重置时间变量,或使用独立临时变量进行跨天偏移计算。 | 见下方 `✅ 修复示例` | | 🔴 严重 | `Ahead_room_timing_bd_model.php`<br>`get_bd_price_set_list` 方法内 | `FIND_IN_SET({$params['room_type']}, \`_room_type\`)` 直接拼接用户输入,未做类型过滤或参数绑定,存在 **SQL 注入** 风险。 | 强制类型转换或使用查询构建器的参数绑定机制。 | `$roomType = (int)$params['room_type'];`<br>`$where['where'] = ["FIND_IN_SET(?, `_room_type`)", $roomType];` | | 🟠 警告 | `Ahead_room_timing_bd_model.php`<br>`_validate_params` 方法内 | 使用 `empty($params[$field])` 校验必填项,会将合法值 `0` 或 `'0'` 误判为空,导致价格或 ID 为 0 时拦截失败。 | 改用严格空值判断 `!isset()` 或 `=== ''` / `=== null`。 | `if (!isset($params[$field]) || $params[$field] === '') { throwError("【{$fieldName}】参数不能为空"); }` | | 🟠 警告 | 两文件多处<br>(顶部及方法内) | 文件顶部使用 `$CI = &get_instance();` 加载模型,且在业务方法中频繁调用 `$this->load->model()`。违反框架生命周期,易引发上下文污染与性能损耗。 | 移除顶部全局加载,统一在 `__construct()` 中预加载依赖模型。 | `public function __construct() { parent::__construct(); $this->load->model(['ahead_vip_level_model', 'ahead_shop_model']); }` | | 🟠 警告 | `Ahead_room_timing_bd_model.php`<br>`add_bd_prise_set` / `update_bd_price_set` | `try-catch` 捕获异常后直接调用 `throwError()`,丢弃了原始异常堆栈信息,极大增加线上问题排查难度。 | 记录完整异常日志,或抛出携带原始异常的自定义业务异常。 | `catch (Exception $e) { log_message('error', $e->getMessage()); throwError('操作失败,请联系管理员'); }` | | 🟡 建议 | `Ahead_room_timing_bd_model.php`<br>L19 | 方法名 `add_bd_prise_set` 存在拼写错误 (`prise` → `price`),影响代码可读性与团队协作。 | 全局重命名为 `add_bd_price_set`。 | `public function add_bd_price_set($merchantId, $adminUid, $params)` | | 🟡 建议 | 两文件多处 | 动态拼接 `$fields` 字段字符串的 `for` 循环在每次请求中重复执行。VIP 等级配置通常固定,可缓存或提取为静态属性。 | 使用 `static` 变量缓存字段字符串,避免重复计算。 | `private static $vip_fields = null;`<br>`if (self::$vip_fields === null) { /* 拼接逻辑 */ }` | ### 🔴 严重问题修复示例(时间重叠检测逻辑) ```php private function _check_time_overlap($merchantId, $shopId, $params, $id = 0) { $where = [ '_deleted_at' => 0, '_merchant_id' => $merchantId, '_shop_id' => $shopId, ]; if ($id > 0) { $where['_id != '] = $id; } $result = $this->select($where); $msg = ''; if (!empty($result)) { foreach ($result as $item) { $weekCycle = explode(',', $item['_week_cycle']); $newWeekCycle = explode(',', $params['week_cycle']); if (empty(array_intersect($weekCycle, $newWeekCycle))) continue; $roomType = explode(',', $item['_room_type']); if (empty(array_intersect($roomType, $params['room_type']))) continue; // ✅ 使用临时变量,避免污染后续循环 $checkStart = $params['start_time']; $checkEnd = $params['end_time']; $overlap = $this->_validate_time($item['_start_time'], $item['_end_time'], $checkStart, $checkEnd); if (!$overlap) { $msg = $this->_buildOverlapMsg($item['_week_cycle'], $item['_start_time'], $item['_end_time'], $checkStart, $checkEnd); break; } // 跨天偏移校验 $offsetStart = $checkEnd > 86400 ? $checkStart - 86400 : $checkStart + 86400; $offsetEnd = $checkEnd > 86400 ? $checkEnd - 86400 : $checkEnd + 86400; $overlap2 = $this->_validate_time($item['_start_time'], $item['_end_time'], $offsetStart, $offsetEnd); if (!$overlap2) { $msg = $this->_buildOverlapMsg($item['_week_cycle'], $item['_start_time'], $item['_end_time'], $offsetStart, $offsetEnd); break; } } } if ($msg) throwError($msg); } // 提取消息构建逻辑,提升可读性 private function _buildOverlapMsg($weekCycle, $dbStart, $dbEnd, $targetStart, $targetEnd) { $week = returnWeek(current(explode(',', $weekCycle)), '星期'); $timeStr = timeToHour(max($dbStart, $targetStart)) . '~' . timeToHour(min($dbEnd, $targetEnd)); return "当前包厢类型【{$week}{$timeStr}】重复设置"; } ``` ## 3. 总结与行动建议 ### 🚨 优先修复项(P0) 1. **修复 `$param` 拼写错误**:直接导致 VIP 价格写入为 0,属于资损级 BUG,需立即修正。 2. **重构时间重叠校验循环**:消除循环内变量污染,确保跨天时间校验逻辑准确。 3. **修复 SQL 注入漏洞**:对 `FIND_IN_SET` 中的 `$params['room_type']` 进行强制 `(int)` 转换或改用参数绑定。 ### 🛠 后续重构与优化方向 1. **规范框架生命周期**: - 移除文件顶部的 `$CI = &get_instance();` 与外部 `load->model()`。 - 将依赖模型统一收敛至 `__construct()` 中,符合 MVC 依赖注入/懒加载最佳实践。 2. **统一异常处理机制**: - 避免 `try { ... } catch (Exception $e) { throwError('失败2'); }` 这种“吞异常”写法。建议引入全局异常处理器,或在 `catch` 中调用 `log_message('error', $e->getTraceAsString())` 保留调试链路。 3. **性能与可维护性提升**: - `FIND_IN_SET` 无法命中索引,数据量大时会导致全表扫描。建议后续架构演进时,将 `room_type` 拆分为独立关联表或使用 JSON 字段(MySQL 5.7+)。 - 动态字段拼接逻辑可提取为 `protected function getVipFields()` 静态方法,减少重复计算。 4. **代码规范对齐**: - 补充 PHP 7+ 类型声明(如 `public function add_bd_price_set(int $merchantId, int $adminUid, array $params): array`)。 - 统一方法命名(如 `add_bd_price_set`),并完善 `@throws` 与 `@return` 注释。 > 💡 **框架适配说明**:基于目录结构、`$CI = &get_instance()` 及 `$this->load->model()` 等特征,该代码高度疑似基于 **CodeIgniter 3** 或同类衍生框架(phpci)。若 `phpci` 为内部定制框架,请确认其 `Simple_model` 基类是否已封装参数绑定与事务管理。上述建议均遵循标准 CI 生命周期与 PSR-12 规范,可直接平滑迁移。 --- *此 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