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 458 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 **提交**: `86c4ad47ffe62ac1ed36e7dfc000b075636d8d47` **提交人**: LITTLEMAIDI (11833999+littlemaidi@user.noreply.gitee.com) **时间**: 2026-06-02 13:35:51 --- ## 1. 审查摘要 - **代码质量评分**:5.5 / 10 分 - **总体评价**:代码实现了复杂的多场景(KTV/台球/棋牌/酒馆)包厢预订时间计算逻辑,业务覆盖较全。但存在严重的**状态管理混乱**、**方法职责过重**、**静态缓存设计缺陷**及**潜在运行时错误**。代码结构偏向“上帝类”,违反单一职责原则(SRP),可维护性与测试性较差。 - **风险等级**:🔴 高 - **框架说明**:注:从目录结构、`$CI = &get_instance()`、`load->model()` 等特征判断,该代码实际基于 **CodeIgniter 3 (CI3)** 架构。以下审查基于 CI3 最佳实践,若 `phpci` 为内部定制版本,核心 PHP 规范与逻辑建议依然适用。 ## 2. 问题详情 | 严重程度 | 文件/行号 | 问题描述 | 建议修改方案 | 代码示例 (可选) | | :--- | :--- | :--- | :--- | :--- | | 🔴 严重 | `get_book_days_info` / `self::$shop_data` 等静态属性 | 静态缓存未区分商户/门店ID。同一请求周期内若传入不同 `merchant_id`/`shop_id`,将直接返回错误缓存数据,导致严重业务串扰。 | 移除静态缓存或改用复合键缓存。建议改为实例属性或使用请求级缓存(如 CI 的 `$this->cache`)。 | `$key = "shop_{$merchant_id}_{$shop_id}"; if (!isset(self::$shop_data[$key])) { self::$shop_data[$key] = $this->ahead_shop_model->get_one(...); }` | | 🔴 严重 | `get_book_day_time_info` / `foreach` 循环内 | 在 `foreach ($time_info as $k => &$v)` 中直接使用 `unset($time_info[$k])` 会破坏数组内部指针,导致后续元素跳过或遍历异常。 | 改用 `array_filter` 过滤,或收集待删除键后统一 `unset`。 | `$time_info = array_filter($time_info, fn($v) => $date != $today || $v['time'] > $now_hour_time);` | | 🔴 严重 | `get_book_day_time_info` / `array_intersect` | `array_intersect(...array_values($all_room_book_time))` 在数组为空或元素不足时,PHP 8+ 会抛出 `Argument unpacking` 警告/错误,导致脚本中断。 | 增加元素数量校验,或使用 `call_user_func_array` 安全解包。 | `if (count($all_room_book_time) > 1) { $un_book_time = array_intersect(...array_values($all_room_book_time)); }` | | 🟠 警告 | `get_book_days_info` | `$this->book_days += 1;` 直接修改类属性状态。若该方法被多次调用,天数会持续累加,造成不可预期的逻辑污染。 | 使用局部变量计算,保持实例状态不可变。 | `$days = $this->book_days + ($add_day ? 1 : 0); for ($i = 0; $i < $days; $i++) { ... }` | | 🟠 警告 | `__construct` 及多处方法 | 频繁调用 `$CI = &get_instance()` 且未复用,增加不必要的函数调用开销。 | 在构造函数中统一赋值给 `$this->ci`,后续统一使用。 | `protected $ci; public function __construct() { parent::__construct(); $this->ci =& get_instance(); }` | | 🟠 警告 | `get_book_day_time_info` | 方法体超 300 行,嵌套层级深,混合了时间计算、套餐校验、营业时间判断、DB查询等逻辑,违反单一职责原则。 | 拆分为独立私有方法或提取至 `BookingTimeService` 服务层。模型仅保留数据访问。 | 将 `_check_package_time()`, `_check_business_hours()`, `_merge_unavailable_times()` 拆分为独立方法。 | | 🟠 警告 | 全局 `$params` 使用 | 直接使用 `$params['date']`, `$params['merchant_id']` 等,缺乏类型校验与白名单过滤,存在越权或非法参数注入风险。 | 引入显式类型转换或 CI 表单验证库,关键参数需做合法性校验。 | `$merchant_id = filter_var($params['merchant_id'], FILTER_VALIDATE_INT); if (!$merchant_id) throwError('商户ID无效');` | | 🟡 建议 | 全局多处 | 存在大量魔法数字/字符串(如 `86400`, `'1'`, `'2'`, `'7'`, `'3600'`),降低可读性且易引发维护错误。 | 提取为类常量或配置文件枚举。 | `const SECONDS_PER_DAY = 86400; const SCENE_KTV = '1'; const SCENE_BILLIARDS = '2';` | | 🟡 建议 | `get_book_day_time_info` | 变量名拼写错误:`opreational_scene`(应为 `operational_scene`)。 | 全局搜索替换修正拼写,避免后续维护混淆。 | 统一修正为 `operational_scene`。 | | 🟡 建议 | 全局方法签名 | 缺少 PHP 7+ 类型声明(参数类型、返回类型),不符合现代 PHP 编码规范。 | 补充 `int`, `string`, `array`, `bool` 等类型提示,提升静态分析能力。 | `public function get_book_days_info(int $merchant_id, int $shop_id, string $check_date = '', bool $add_day = false): array` | ## 3. 总结与行动建议 ### 🚨 优先修复项(P0/P1) 1. **修复静态缓存串扰**:立即将 `self::$shop_data`、`self::$date_time_info` 等静态属性改为带业务主键的数组缓存,或彻底移除静态缓存改用实例属性。这是当前最高风险点。 2. **修复 `foreach` 中的 `unset` 与数组解包**:替换为 `array_filter` 并增加 `count()` 判断,避免 PHP 8+ 环境下的致命错误。 3. **消除状态污染**:将 `$this->book_days += 1` 等直接修改实例属性的操作改为局部变量计算,确保对象可复用。 ### 🛠 架构与重构方向 1. **模型瘦身(Model-Service 分离)**:当前模型承担了过多业务逻辑。建议将时间计算、套餐规则校验、不可用时间合并等逻辑抽离至独立的 `BookingTimeCalculatorService` 或 `PackageRuleValidator`。模型仅保留 `get_one()`, `get_shop_setting()` 等数据访问方法。 2. **统一 CI 实例引用**:在 `__construct` 中缓存 `$this->ci = &get_instance()`,避免重复调用。 3. **引入配置常量**:将 `86400`、`3600`、场景标识 `'1'/'2'/'3'` 等提取为类常量或独立配置文件,提升代码可读性与可维护性。 4. **补充输入校验**:在方法入口处对 `$params` 进行类型强转与合法性校验,避免脏数据流入核心计算逻辑。 ### 📝 局限性说明 提供的代码片段在 `_get_un_book_time` 方法末尾被截断(`$this->next_date_room_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