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
Delete row 212 from issue
id
212
repo_id
21
index
24
poster_id
1
original_author
original_author_id
0
name
🔍 代码审查报告:pay-260519 - 1
content
## 自动代码审查报告 **分支**: pay-260519 **提交**: `2a980b367
## 自动代码审查报告 **分支**: pay-260519 **提交**: `2a980b3670633e5727929484e767c544065612c4` **提交人**: LITTLEMAIDI (11833999+littlemaidi@user.noreply.gitee.com) **时间**: 2026-05-19 16:38:25 --- ## 1. 审查摘要 - **代码质量评分**:5.5 / 10 分 - **总体评价**:该 Model 承载了复杂的套餐查询、多端价格计算、会员折扣与社区模式适配逻辑,业务覆盖较全。但代码存在**高危 SQL 注入隐患**、**经典的 `unset` 引用失效 Bug**、**循环内性能损耗**及**不符合现代 PHP 规范的写法**。整体处于“功能可跑但架构脆弱”状态,需优先处理安全与核心逻辑缺陷,并进行职责拆分。 - **风险等级**:🔴 高 --- ## 2. 问题详情 | 严重程度 | 文件/行号 | 问题描述 | 建议修改方案 | 代码示例 (可选) | | :--- | :--- | :--- | :--- | :--- | | 🔴 严重 | `get_book_package_list` / `get_hot_sale_top5` 等多处 | **SQL 注入漏洞**:`$shop_name` 等参数未经转义直接拼接入 `LIKE` 语句。虽 `$city_id` 做了 `intval()`,但原始 SQL 拼接模式极易被绕过或引发语法错误。 | 全面替换为框架查询构造器(Query Builder)或使用 `$this->db->escape()`。禁止手动拼接 `WHERE` 条件。 | `$this->db->where('shop._city_id', $city_id)->like('shop._name', $shop_name)->get()->result_array();` | | 🔴 严重 | `get_package_price_list` (~L148)<br>`get_screen_list` (~L288) | **`unset($row)` 逻辑失效**:在 `foreach ($list as &$row)` 中执行 `unset($row)` 仅销毁局部引用,**不会**从原数组中移除元素,导致无效套餐仍被返回。 | 改用键值遍历 `foreach ($list as $key => $row)` 并 `unset($list[$key])`,或使用 `array_filter`。 | `foreach ($list as $key => $row) { if ($book_arrival_time < $order_end_time) { unset($list[$key]); } }` | | 🟠 警告 | 文件顶部 (~L5) | **全局 `$CI` 实例化时机错误**:`$CI = &get_instance();` 在文件被 `include` 时立即执行,此时框架可能未完全初始化,且破坏面向对象封装原则。 | 删除顶部代码。在方法内部统一使用 `$this->load->model()` / `$this->config->load()`。CI 框架会自动处理依赖注入。 | 移除 `$CI = &get_instance();` 及 `$CI->load->...`,全部替换为 `$this->load->...` | | 🟠 警告 | `get_package_price_list` / `get_screen_list` | **循环内 `array_unshift` 性能瓶颈**:在 `foreach` 中频繁调用 `array_unshift`,时间复杂度退化为 O(n²),数据量超 100 时极易导致 CPU 飙升或超时。 | 将推荐项与非推荐项分别收集到临时数组,循环结束后使用 `array_merge` 合并。 | `$rec[] = $row; $norm[] = $row; ... $result['drink'] = array_merge($rec, $norm);` | | 🟠 警告 | `get_book_package_list` (~L415) | **静态变量伪缓存**:`static $_shop_id_arr` 仅在单次 PHP-FPM 请求生命周期有效,无法跨请求共享,且无 TTL 控制,实际未起到缓存作用。 | 使用框架缓存组件(Redis/Memcached)替代静态变量,设置合理过期时间。 | `$key = "shop_dist_{$city_id}_{$lat}_{$lon}"; $ids = $this->cache->get($key) ?: $this->ahead_shop_model->get_id_by_distance(...); $this->cache->save($key, $ids, 300);` | | 🟡 建议 | 全局 | **魔法数字泛滥**:大量硬编码 `4`, `2`, `100`, `86400`, `-1` 等,降低可读性与后期维护效率。 | 提取为类常量或配置文件。已定义的 `const SCREEN_RENEW_TYPE = 4;` 需全局替换使用。 | `const PACKAGE_TYPE_GROUP = 4; const SECONDS_PER_DAY = 86400; const DISCOUNT_STATUS_ON = 1;` | | 🟡 建议 | 全局 | **命名规范不一致**:类名使用下划线 `Ahead_room_package_infos_model`,方法名混用驼峰与下划线,不符合 PSR-12 规范。 | 类名改为 `AheadRoomPackageInfosModel`,方法名统一为 `camelCase`。若受历史包袱限制,至少保持项目内一致。 | `class AheadRoomPackageInfosModel extends Simple_model` | | 🟡 建议 | `get_package_price_list` 等多处 | **重复加载模型**:同一方法内多次调用 `$this->load->model()`,虽 CI 会做单例拦截,但增加无谓开销且代码冗余。 | 将高频依赖模型移至 `__construct()` 或方法顶部统一加载。 | `public function __construct() { parent::__construct(); $this->load->model(['Ahead_vip_model', 'Ahead_vip_level_model', ...]); }` | --- ## 3. 总结与行动建议 ### 🔑 优先修复的关键问题 1. **立即修复 SQL 注入**:将 `get_book_package_list`、`get_hot_sale_top5` 及后续截断方法中的原生 SQL 全部迁移至 CI 查询构造器或预处理语句。 2. **修正 `unset` 逻辑漏洞**:全局搜索 `foreach ($arr as &$v) { unset($v); }` 模式,替换为键值遍历或 `array_filter`,否则将导致脏数据透传至前端。 3. **移除顶部 `$CI` 实例化**:避免框架初始化阶段的竞态条件与内存泄漏风险。 ### 🛠 后续重构与优化方向 1. **方法职责拆分**:`get_package_price_list` 单方法超过 150 行,混合了“条件构建、VIP计算、社区模式校验、数据格式化、分类排序”等多个职责。建议拆分为: - `buildPackageQueryConditions()` - `calculateVipPrice()` - `filterCommunityAvailablePackages()` - `formatPackageList()` 2. **引入 DTO/VO 模式**:当前直接返回裸数组,字段名混杂(如 `_id`、`id`、`package_id`)。建议定义 `PackageDTO` 类统一数据结构,提升类型安全与 IDE 提示体验。 3. **缓存策略升级**:套餐列表查询属于高频读操作。建议对 `get_package_price_list` 结果引入 Redis 缓存,以 `merchant_id_shop_id_room_type` 为 Key,设置 1~5 分钟 TTL,并在后台修改套餐时主动清除缓存。 4. **框架适配说明**:代码结构高度符合 **CodeIgniter 3.x** 规范。若 `phpci` 为内部定制框架,请确认 `$this->db`、`$this->load`、`$this->cache` 的底层实现是否与 CI3 一致。若存在差异,需针对性调整查询构造器与缓存调用方式。 > ⚠️ **局限性说明**:文件末尾 `get_book_package_list_group_by_shop` 方法在 `$special_city_id = [2, 3, 4, 5, 34,` 处被截断,无法审查其完整逻辑与潜在风险。请补充完整代码以便进行二次深度审查。 --- *此 Issue 由代码审查服务自动创建*
...
milestone_id
0
priority
0
is_closed
0
is_pull
0
num_comments
0
ref
deadline_unix
0
created_unix
1779179905
updated_unix
1779179905
closed_unix
0
is_locked
0
content_version
0
time_estimate
0
Delete
Cancel