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 405 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-260519 - 1
TEXT
content
## 自动代码审查报告 **分支**: pay-260519 **提交**: `9978533a1ccd2fbb3c2a20826c7dac089ae6c785` **提交人**: LITTLEMAIDI (11833999+littlemaidi@user.noreply.gitee.com) **时间**: 2026-05-28 15:44:18 --- ## 1. 审查摘要 - **代码质量评分**:5/10 分 - **总体评价**:该模型承载了极其复杂的预订时间计算逻辑,业务覆盖全面,但存在严重的架构设计问题。方法过长、职责不清、静态缓存未做参数隔离、直接污染全局 CI 对象、大量魔法数字与隐式依赖,导致代码可维护性差、潜在逻辑漏洞多、性能瓶颈明显。 - **风险等级**:🔴 高 ## 2. 问题详情 | 严重程度 | 文件/行号 | 问题描述 | 建议修改方案 | 代码示例 (可选) | | :--- | :--- | :--- | :--- | :--- | | 🔴 严重 | `get_book_days_info()` | **静态缓存未区分参数**:`self::$book_days_info` 作为静态缓存,未结合 `$merchant_id`、`$shop_id`、`$check_date` 等参数生成 Key。同一请求内多次调用不同门店/日期时,会返回错误的缓存数据。 | 移除全局静态缓存,改用带复合 Key 的缓存机制(如 CI Cache 或 Redis),或改为实例级缓存并严格校验参数一致性。 | `// 错误示例<br>if (!empty(self::$book_days_info)) return self::$book_days_info;<br><br>// 建议方案<br>$cache_key = "book_days:{$merchant_id}:{$shop_id}:{$check_date}";<br>$cached = $this->cache->get($cache_key);<br>if ($cached !== false) return $cached;` | | 🔴 严重 | `get_book_days_info()` | **类属性被意外永久修改**:`$this->book_days += 1;` 在方法内部直接修改了类属性。若该方法被多次调用,`book_days` 会持续累加,导致后续日期计算严重偏离预期。 | 使用局部变量进行计算,绝不修改类属性状态。 | `$days_to_check = $add_day ? $this->book_days + 1 : $this->book_days;` | | 🔴 严重 | `get_book_day_time_info()` | **遍历中修改数组**:`foreach ($time_info as $k => &$v) { ... unset($time_info[$k]); }` 在 `foreach` 循环中直接 `unset` 当前数组元素,会导致指针错乱、跳过元素或触发 PHP 警告。 | 改用 `array_filter` 过滤,或收集需删除的 Key 在循环结束后统一 `unset`。 | `$time_info = array_filter($time_info, function($v) use ($today, $now_hour_time) {<br> return !($v['date'] == $today && $v['time'] <= $now_hour_time);<br>});` | | 🟠 警告 | 多处 (`set_shop_config`, `set_room_info`) | **全局 CI 对象状态污染**:频繁使用 `$CI->operational_scene = ...` 直接修改超全局对象属性。这破坏了封装性,极易在并发或后续请求中引发难以追踪的副作用。 | 通过方法返回值、DTO 对象或 Session/Config 传递状态,避免直接操作 `$CI` 属性。 | `// 建议通过返回值或独立配置类传递<br>$scene = $this->determineOperationalScene($room_id);<br>$this->config->set('operational_scene', $scene);` | | 🟠 警告 | `get_book_day_time_info()` | **严重违反单一职责原则 (SRP)**:该方法长达 300+ 行,混合了数据查询、时间范围合并、套餐校验、营业规则过滤、状态标记等数十种逻辑,嵌套层级深,极难测试与维护。 | 拆分为独立的方法或策略类。例如:`calculateBusinessHours()`、`checkVoucherConstraints()`、`applyLockRules()`、`filterAvailableSlots()`。 | `// 拆分后主流程示例<br>$slots = $this->generateTimeSlots($date, $business_from, $business_end);<br>$slots = $this->applyVoucherRules($slots, $params);<br>$slots = $this->applyLockRules($slots, $params);<br>return $this->formatOutput($slots);` | | 🟠 警告 | `get_book_day_time_info()` | **高频重复数据库查询**:`$this->get_one()`、`$this->ahead_shop_config_second_model->get_shop_setting()` 在循环或多次调用中重复执行,且缺乏有效的请求级缓存。 | 在构造函数或初始化阶段批量加载配置,或使用 CI 的 `$this->db->cache_on()` / 内存缓存池。 | `// 构造函数中预加载<br>$this->shop_config = $this->ahead_shop_config_second_model->get_all_settings($merchant_id, $shop_id);<br>// 后续直接读取数组` | | 🟡 建议 | 全局 | **魔法数字与字符串泛滥**:代码中大量使用 `'1'`, `'2'`, `'3'`, `'7'`, `'-1'`, `86400`, `3600` 等硬编码值,缺乏语义化,易引发维护歧义。 | 在类顶部定义 `const` 常量,或使用枚举类(PHP 8.1+)。 | `const SCENE_KTV = '1';<br>const SCENE_BILLIARDS = '2';<br>const SECONDS_PER_DAY = 86400;` | | 🟡 建议 | 全局 | **命名规范不符合 PSR-12**:大量类属性使用 `snake_case`(如 `$book_time_limit_after_close_room`),而方法使用 `camelCase`。PHP 社区推荐统一使用 `camelCase`。 | 统一属性与方法命名为 `camelCase`,保持代码风格一致。 | `public $bookTimeLimitAfterCloseRoom = 1200;` | | 🟡 建议 | 全局 | **强依赖未声明的全局辅助函数**:大量调用 `throwError()`, `timeToHour()`, `mergeTimeRanges()` 等全局函数,未通过命名空间或依赖注入引入,降低可测试性。 | 将辅助函数封装为独立的 `Helper` 类或 `Service`,通过构造函数注入,或确保在框架自动加载范围内。 | `// 使用服务类替代全局函数<br>$timeHelper = new TimeHelper();<br>$timeHelper->mergeRanges($ranges);` | ## 3. 总结与行动建议 ### 🔑 优先修复的关键问题 1. **修复静态缓存与状态污染**:立即移除 `self::$book_days_info` 等无参数隔离的静态缓存,改用带 Key 的缓存或实例变量。彻底禁止在 Getter 方法中修改 `$this->book_days` 等核心属性。 2. **消除 `foreach` 中 `unset` 的风险**:将 `get_book_day_time_info()` 中的数组过滤逻辑改为 `array_filter` 或收集 Key 后批量删除,避免运行时指针异常。 3. **解耦全局 CI 对象操作**:停止使用 `$CI->xxx = ...` 传递业务状态。改为通过方法参数、返回值或独立的 `Context/DTO` 对象传递,确保请求隔离。 ### 🛠 后续重构与优化方向 1. **方法拆分与策略模式应用**: - `get_book_day_time_info()` 必须拆分。建议采用 **责任链模式** 或 **策略模式** 处理各类校验规则(如:营业时间校验、团购券校验、包厢锁定校验、最低时长校验)。每个规则独立成类,便于单元测试与动态开关。 2. **性能优化**: - 引入 **请求级内存缓存**(如 `static $cache_pool = []` 配合复合 Key),避免同一请求内重复查询数据库或重复计算时间区间。 - 时间区间合并/交集计算(`array_intersect`, `mergeTimeRanges`)在数据量大时复杂度较高,建议将时间轴离散化为固定步长(如 5 分钟)的位图(BitMap)或使用区间树算法优化。 3. **类型安全与规范升级**: - 启用 `declare(strict_types=1);`,为所有方法添加参数类型与返回类型声明。 - 将硬编码状态码(`'1'`, `'-1'`)替换为枚举或常量,提升代码可读性。 - 遵循 PSR-12 规范统一命名风格,补充完整的 PHPDoc 注释。 4. **框架适配说明**: > ⚠️ 注:当前代码结构高度符合 **CodeIgniter 3** 的 MVC 模式(如 `get_instance()`、`$this->load->model()`)。若 `phpci` 为内部定制框架,请查阅其官方文档确认是否提供原生的缓存组件、依赖注入容器或生命周期钩子。建议优先使用框架内置的 `$this->cache` 替代手动静态缓存,并利用框架的 `config` 或 `session` 管理跨方法状态。 > 📝 **局限性说明**:提供的代码片段在 `_get_un_book_time()` 方法末尾被截断,部分时间边界计算与次日逻辑未完全展示。以上审查基于已提供部分进行深度分析,若需完整评估跨日时间轴计算逻辑,请补充完整文件内容。 --- *此 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