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 228 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 **提交**: `9508f796c462fe49f6d673e0f662e51fa6a7cfdc` **提交人**: LITTLEMAIDI (11833999+littlemaidi@user.noreply.gitee.com) **时间**: 2026-05-19 19:57:05 --- ## 1. 审查摘要 - **代码质量评分**:5.5 / 10 分 - **总体评价**:该模型承载了极其复杂的计费、时段匹配、跨天处理与VIP折扣逻辑,业务实现完整但高度耦合。代码中存在多处影响财务精度的浮点运算、数组遍历指针误用、潜在SQL注入风险及性能瓶颈。模型职责过重,混合了数据查询、业务计算与视图数据格式化,不符合现代 MVC 分层规范。 - **风险等级**:🔴 高 ## 2. 问题详情 | 严重程度 | 文件/行号 | 问题描述 | 建议修改方案 | 代码示例 (可选) | | :--- | :--- | :--- | :--- | :--- | | 🔴 严重 | `get_timing_by_room_id` (约第 70 行) | `foreach ($timingData as $key => &$timeItem)` 循环内部混用 `next($timingData)` 修改数组内部指针,且使用引用传递。PHP 的 `foreach` 会复制数组指针,混用会导致遍历错乱、跳过元素或死循环。 | 移除 `next()`,改用索引遍历或提前将“次日数据”独立查询并合并。避免在 `foreach` 中操作迭代器指针。 | `// 错误做法<br>foreach ($arr as $k => &$v) { next($arr); }<br><br>// 正确做法:使用 for 循环或提前构建映射数组<br>for ($i = 0; $i < count($timingData); $i++) { ... }` | | 🔴 严重 | `get_now_price`, `get_date_time_price_info` 等多处 | `where` 条件中直接拼接变量至 SQL 字符串(如 `FIND_IN_SET('{$room_id}', _room_ids)`)。若框架查询构造器未对该键值进行强制转义,将导致 SQL 注入。 | 使用参数绑定或框架提供的安全查询方法,确保所有外部输入经过严格过滤/转义。 | `$this->db->where("FIND_IN_SET(?, _room_ids)", $room_id);<br>// 或框架封装的安全写法<br>$where['where'][] = ['FIND_IN_SET(?, _room_ids)', $room_id];` | | 🔴 严重 | `calculate_timing_cost`, `calculate_timing_cost_count` 等多处 | 使用浮点数进行金额累加(`$cost += $priceFlag * $till;`)。PHP 浮点数精度缺陷会导致 `0.00000001` 级误差,长期累积或高并发下极易引发财务对账失败。 | 金额计算统一转为“分”(整数)或使用 `bcmath` 扩展。仅在最终返回时格式化为元。 | `$cost = bcadd($cost, bcmul($priceFlag, $till, 4), 2);<br>// 返回前转换<br>'cost' => number_format(bcdiv($cost, 100, 2), 2, '.', '')` | | 🟠 警告 | `get_date_time_price_info` (约第 450 行) | 使用 `for ($i = $start_time; $i < $end_time; $i += 300)` 按 5 分钟步长生成时间数组。跨天或长时段会生成数百个数组元素,内存占用高且无必要。 | 改为区间逻辑计算,仅在 API 响应前按需生成;或引入缓存/预计算表,避免实时循环生成。 | `// 改为区间记录,前端/视图层按需展开<br>$ranges[] = ['start' => $start_time, 'end' => $end_time, 'price' => $price];` | | 🟠 警告 | 全文多处 | 频繁调用未声明的全局函数(`throwError`, `hourToTime`, `preMinute`, `getNextUnitTime` 等)。若 Helper 未自动加载,将触发 `Fatal Error`。 | 在 `config/autoload.php` 中统一加载对应 Helper,或封装为静态工具类 `TimingHelper::hourToTime()` 并添加 `function_exists()` 防御。 | `if (!function_exists('hourToTime')) { throw new \RuntimeException('Helper not loaded'); }` | | 🟡 建议 | 全文 | 魔法数字泛滥(`86400`, `3600`, `0.01`, `8`, `9`, `300` 等),降低可读性与后期维护成本。 | 提取为类常量,集中管理业务阈值与类型标识。 | `const SECONDS_PER_DAY = 86400;<br>const TYPE_BD = 8;<br>const TYPE_NEXT_BD = 9;` | | 🟡 建议 | `get_timing_by_room_id` 等 | 参数命名不一致(`$extraParams` vs `$extParams`),存在拼写错误(`$startInitTiem`),且模型内重复调用 `$this->load->model()`。 | 统一参数命名规范;修复拼写错误;将依赖模型加载移至构造函数或父类初始化方法。 | `public function __construct() {<br> parent::__construct();<br> $this->load->model(['Ahead_family_servers_model', 'Ahead_yc_shop_model']);<br>}` | | 🟡 建议 | 整体架构 | 模型承担了大量业务计算、价格策略匹配与数据格式化逻辑,违反单一职责原则(SRP)。 | 将计费、时段匹配、VIP折扣逻辑抽离至独立的 `Service` 层(如 `RoomPricingService`),Model 仅保留数据存取与基础查询。 | `// Controller 调用<br>$pricing = new RoomPricingService($this->ahead_room_timing_model);<br>$result = $pricing->calculate($merchantId, $roomId, $start, $end);` | ## 3. 总结与行动建议 ### 🔑 优先修复的关键问题 1. **修复财务精度隐患**:立即将所有涉及金额加减乘除的逻辑替换为 `bcmath` 函数或整数(分)运算。这是计费系统的核心红线。 2. **消除数组遍历 Bug**:重构 `get_timing_by_room_id` 中的 `foreach` + `next()` 逻辑,改用索引遍历或独立构建 `$nextTimingData` 数组,确保时段匹配逻辑稳定。 3. **封堵 SQL 注入风险**:审查所有包含 `FIND_IN_SET`、`like`、`where` 的查询条件,确保外部参数通过参数绑定传入,禁止直接字符串拼接。 ### 🛠 后续重构与优化方向 1. **架构分层解耦**:当前 Model 已演变为“上帝类”。建议按职责拆分为: - `TimingModel`:仅负责数据库 CRUD 与基础查询。 - `PricingService`:处理计费规则匹配、跨天计算、VIP折扣策略。 - `TimingFormatter`:负责将原始数据转换为前端所需的 `time_str`、`is_default` 等展示格式。 2. **性能优化**: - 将 `get_date_time_price_info` 中的 5 分钟循环改为区间计算,或引入 Redis 缓存热点时段的定价规则。 - 统一在构造函数中加载依赖模型,避免方法内重复调用 `$this->load->model()`。 3. **规范与可维护性**: - 提取所有魔法数字为 `const` 常量。 - 统一参数命名风格(推荐 `$extraParams`),修复 `$startInitTiem` 等拼写错误。 - 补充 PHPDoc 类型声明(如 `@param int $merchantId`),便于静态分析工具(如 PHPStan/Psalm)介入。 4. **框架适配说明**:代码结构高度类似 CodeIgniter 3。若 `phpci` 为定制框架,请重点核对 `$this->select()` 与 `$this->get_one()` 对 `where` 数组中原始 SQL 片段的转义策略。若框架未自动转义,必须手动使用查询构造器的参数绑定语法。 > 💡 **提示**:建议在合并前补充单元测试(PHPUnit),重点覆盖:跨天时段匹配、VIP折扣叠加、不满一小时计费规则、以及边界时间(如 `23:59` 与 `00:00`)的精度验证。 --- *此 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