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 380 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 **提交**: `9526c8bb434751493f71e1b7d7d1e13f97bc89bf` **提交人**: LITTLEMAIDI (11833999+littlemaidi@user.noreply.gitee.com) **时间**: 2026-05-27 16:37:55 --- ## 1. 审查摘要 - **代码质量评分**:5.5 / 10 分 - **总体评价**:代码实现了复杂的包厢预订时间计算逻辑,但存在明显的架构反模式(如模型强状态化、静态缓存键冲突、超长方法违反单一职责)。业务规则交织严重,可维护性与并发安全性较低。部分逻辑存在重复与潜在的性能瓶颈。 - **风险等级**:🔴 高(状态污染与缓存键冲突可能导致线上预订数据错乱) > 📌 **框架说明**:从目录结构(`system/helpers/`、`application/models/`)及 `$CI = &get_instance()` 的调用方式判断,该代码实际基于 **CodeIgniter 3** 架构。若 `phpci` 为内部定制框架,请结合其官方文档对生命周期与组件加载方式进行微调。 --- ## 2. 问题详情 | 严重程度 | 文件/行号 | 问题描述 | 建议修改方案 | 代码示例 (可选) | | :--- | :--- | :--- | :--- | :--- | | 🔴 严重 | `get_book_days_info` (约 L158) | **静态缓存键冲突**:`self::$book_days_info` 未区分 `$merchant_id`、`$shop_id`、`$date` 等参数。同一请求内多次调用不同参数时,会返回错误缓存数据,导致日期状态错乱。 | 移除静态变量缓存,改用 CI 缓存驱动(`$this->cache->save()`)或构建复合键。若必须用静态缓存,需使用参数哈希作为键名。 | `// 推荐方案:使用复合键缓存<br>$cache_key = md5(__METHOD__ . serialize(func_get_args()));<br>if (isset(self::$cache_pool[$cache_key])) return self::$cache_pool[$cache_key];` | | 🔴 严重 | 全局 (Model 属性) | **模型强状态化反模式**:大量 `public` 属性(如 `$book_room_id`, `$ignore_tuangou_time_limit`, `$tuangou`)用于存储单次请求上下文。在并发请求或同一请求多次实例化时极易发生状态污染。 | 模型应保持无状态。将请求上下文封装为 DTO 对象或通过方法参数传递。复杂业务逻辑应剥离至 `Service` 层。 | `// 错误:$this->book_room_id = $id;<br>// 正确:public function calculate($params, $room_id) { ... }` | | 🟠 警告 | `set_shop_config` & `set_room_info` | **逻辑重复**:两个方法中计算 `$shop_config_scene` 及加载配置的代码高度重复,违反 DRY 原则。 | 提取为私有方法 `private function resolveShopConfigScene($scene)`,统一调用。 | `private function resolveSceneConfig($scene) {<br> $map = ['2'=>'billiards_', '3'=>'card_', '4'=>'tavern_'];<br> return $map[$scene] ?? '';<br>}` | | 🟠 警告 | `get_book_day_time_info` (约 L190-L450) | **方法过长 & 违反单一职责**:该方法超 250 行,混合了营业时间计算、套餐规则过滤、不可用时间合并、跨天逻辑、状态标记等。极难测试与维护。 | 拆分为独立私有方法:`_calculateBusinessHours()`, `_applyPackageRules()`, `_mergeUnavailableTimes()`, `_filterTimeSlots()`。主方法仅负责流程编排。 | `// 主方法仅保留流程控制<br>$time_info = $this->_buildBaseTimeSlots($date);<br>$time_info = $this->_applyPackageConstraints($time_info, $params);<br>$time_info = $this->_filterByAvailability($time_info, $un_book_time);` | | 🟠 警告 | 多处 (`$CI = &get_instance()`) | **频繁获取 CI 实例**:在多个方法中重复调用 `&get_instance()`,且直接读取控制器属性(如 `$CI->merchant_id`)。破坏封装性且增加开销。 | 在构造函数中统一赋值 `$this->ci = &get_instance();`,后续使用 `$this->ci`。控制器上下文应通过参数或 Session/Config 传递。 | `public function __construct() {<br> parent::__construct();<br> $this->ci = &get_instance();<br>}` | | 🟡 建议 | `get_book_day_time_info` (约 L195) | **输入校验不足**:仅判断 `$date` 是否为空,未校验格式(如 `Ymd`)。非法日期传入 `strtotime` 会导致静默失败或返回错误时间戳。 | 增加正则或 `DateTime::createFromFormat` 校验,失败时抛出明确异常。 | `if (!preg_match('/^\d{8}$/', $date)) {<br> throwError('日期格式错误,应为 YYYYMMDD');<br>}` | | 🟡 建议 | 全局 (硬编码字符串) | **魔法值泛滥**:`'1'`, `'2'`, `'3'`, `'merchantApp'`, `'-1'` 等散落在业务逻辑中,语义不明确且易改漏。 | 在类顶部定义常量:`const SCENE_KTV = '1'; const SCENE_BILLIARDS = '2'; const SOURCE_MERCHANT_APP = 'merchantApp';` | `if ($scene === self::SCENE_BILLIARDS) { ... }` | | 🟡 建议 | `_get_un_book_time` (末尾截断) | **代码片段不完整**:方法在 `if (empty($this->next_date_room_book_time))` 处中断,无法审查后续逻辑(如次日时间合并、边界处理)。 | 请补充完整代码以便进行闭环审查。当前可见部分已存在多次重复的 `get_one` 查询,建议合并为批量查询。 | *(待补充)* | --- ## 3. 总结与行动建议 ### 🚨 优先修复的关键问题 1. **消除模型状态污染**:立即将 `$book_room_id`、`$ignore_tuangou_time_limit`、`$tuangou` 等请求级状态移出 Model 属性。建议创建 `BookingTimeCalculator` 服务类,通过构造函数或方法参数注入上下文。 2. **修复静态缓存键冲突**:`self::$book_days_info` 等静态缓存必须加入参数指纹(如 `md5($merchant_id . $shop_id . $date)`),否则在多门店/多日期并发查询时必现数据串扰。 3. **拆分巨型方法**:`get_book_day_time_info` 是典型“上帝方法”。请按“数据获取 → 规则计算 → 状态过滤 → 结果格式化”四个阶段拆分为独立方法,并补充单元测试。 ### 🛠 后续重构与优化方向 - **架构分层**:遵循 `Controller → Service → Model` 分层。Model 仅负责数据库 CRUD 与基础数据映射;时间计算、套餐规则、营业逻辑等复杂业务下沉至 Service 层。 - **性能优化**: - 将 `_get_un_book_time` 中对前一日、当日、后一日的多次 `get_one` 查询合并为单次 `get_where_in` 批量查询,减少 DB 往返。 - 时间区间计算可考虑引入 `Carbon` 或自定义 `TimeRange` 值对象,替代散落的 `strtotime`/`date`/字符串拼接,提升可读性与准确性。 - **规范与安全**: - 全面替换魔法值为类常量。 - 对 `$params` 中的 `date`、`merchant_id`、`shop_id` 增加严格类型与格式校验,防御越权与异常输入。 - 若项目运行在 PHP 7.4+,建议为所有方法添加返回类型声明(如 `: array`, `: void`),提升静态分析能力。 > 💡 **提示**:由于提供的代码在 `_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