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 548 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-260616 - 获取卡券判断消费方式
TEXT
content
## 自动代码审查报告 **分支**: pay-260616 **提交**: `6033d9a98806fe6c3fa96c71d81bb15bdcd882f0` **提交人**: LITTLEMAIDI (11833999+littlemaidi@user.noreply.gitee.com) **时间**: 2026-06-05 10:04:34 --- ## 1. 审查摘要 - **代码质量评分**:5/10 分 - **总体评价**:代码实现了较为复杂的团购券与会员优惠券业务逻辑,但存在严重的 SQL 注入风险、框架生命周期误用、N+1 查询性能瓶颈以及大量硬编码与拼写错误。整体架构偏向“面条式代码”,方法职责过重,缺乏分层设计,可维护性与安全性亟待提升。 - **风险等级**:🔴 高 ## 2. 问题详情 | 严重程度 | 文件/行号 | 问题描述 | 建议修改方案 | 代码示例 (可选) | | :--- | :--- | :--- | :--- | :--- | | 🔴 严重 | `Ahead_shop_group_buying_coupon_model.php` ~L38<br>`Ahead_user_reward_model.php` ~L115, L130 | **SQL 注入风险**:多处使用字符串直接拼接构造 `WHERE` 条件(如 `FIND_IN_SET`、`LIKE`、`REGEXP`),未对 `$shop_id`、`$params['name']` 等外部输入进行转义或参数化绑定。 | 严格使用框架查询构建器(Query Builder)或 `$this->db->escape()` 进行安全转义。禁止直接拼接用户可控参数。 | `$this->db->where("FIND_IN_SET(".$this->db->escape($shop_id).", _satisfy_shop_ids)");`<br>或 `$this->db->where("FIND_IN_SET(?, _satisfy_shop_ids)", $shop_id, FALSE);` | | 🔴 严重 | 两文件顶部 | **框架生命周期违规**:在类定义外部直接调用 `$CI = &get_instance();`。在 CI 架构中,文件被 `include` 时容器可能未完全初始化,易引发 `Fatal Error` 或全局状态污染。 | 移除顶部全局 `$CI` 赋值。模型内部应直接使用 `$this->load->model()` 或 `$this->db`。若需访问全局实例,应在方法内部或构造函数中获取。 | `// 删除文件顶部的 $CI = &get_instance();`<br>`// 内部直接使用 $this->load->model('Simple_model');` | | 🔴 严重 | `Ahead_user_reward_model.php` ~末尾 | **语法错误/代码截断**:`get_valid_coupon` 方法末尾 `continue` 后缺失分号,且缺少闭合大括号 `}`,直接导致 PHP 解析失败。 | 补全缺失的语法符号,并核对 Git 提交完整性。建议配置 CI/CD 流水线进行语法静态检查。 | `continue;`<br>`}`<br>`}` | | 🟠 警告 | `Ahead_user_reward_model.php` `build_reward_data` 及循环内 | **N+1 查询与性能瓶颈**:在 `foreach` 循环中频繁调用 `get_miniprogram_consumption_methods`、`get_package_shop_ids` 等模型方法。数据量稍大时将引发数据库连接风暴。 | 采用“批量预加载 + 内存映射”模式。循环前一次性查询所有关联数据,通过数组键值在循环内 O(1) 匹配。 | `$shop_ids = array_unique(array_column($reward_data, 'use_immediately_shop_id'));`<br>`$configs = $this->config_model->get_batch_by_shop_ids($shop_ids);`<br>`// 循环内直接 $configs[$shop_id] 取值` | | 🟠 警告 | 多处 | **硬编码与魔法数字泛滥**:大量使用 `'23_1'`, `'23_3'`, `1`, `2`, `9` 等业务状态/类型标识,散落在逻辑中,缺乏集中管理。 | 将业务常量提取至类常量或独立配置文件中,使用语义化命名,提升可读性与后期维护效率。 | `const FROM_PLACE_DOUYIN = '23_1';`<br>`const STATUS_USED = 9;`<br>`const TYPE_OPEN_ROOM = 4;` | | 🟠 警告 | `Ahead_user_reward_model.php` `get_my_reward_list` | **重复加载模型**:同一模型(如 `ahead_shop_config_second_model`)在多个方法或循环中重复 `load->model()`。虽框架有缓存机制,但增加解析开销且不符合规范。 | 统一在 `__construct()` 中加载高频依赖模型,或启用框架的自动加载(Autoload)配置。 | `public function __construct() { parent::__construct(); $this->load->model('ahead_shop_config_second_model'); }` | | 🟡 建议 | 全局 | **拼写错误与命名不规范**:存在 `$fileds` (应为 `$fields`)、`from_palce` (应为 `from_place`)、`TYPR_DADA` (应为 `TYPE_DATA`) 等拼写错误,且未遵循 PSR-12 规范。 | 修正拼写错误,统一命名风格。建议引入 `PHP_CodeSniffer` 或 `PHPStan` 进行自动化规范检查。 | `public $fields = "...";`<br>`const TYPE_DATA = [...];` | | 🟡 建议 | `Ahead_user_reward_model.php` `build_reward_data` | **方法职责过重(违反单一职责原则)**:该方法超 150 行,混合了数据组装、时间计算、门店匹配、URL 生成、状态映射等逻辑,难以测试与复用。 | 拆分为独立的服务类或辅助方法(如 `RewardUrlGenerator`, `ShopMatcher`, `TimeCalculator`),主方法仅负责流程编排。 | `// 拆分逻辑`<br>`$row['exchange_url'] = $this->rewardUrlService->build($row);`<br>`$row['shop_names'] = $this->shopMatcher->resolveNames($row);` | ## 3. 总结与行动建议 ### 🔑 优先修复项(P0) 1. **修复 SQL 注入漏洞**:立即替换所有字符串拼接的 `WHERE` 条件,全面改用框架 Query Builder 的 `where()`, `like()`, `where_in()` 方法,或至少使用 `$this->db->escape()`。 2. **修正语法与框架误用**:删除文件顶部的 `$CI = &get_instance();`,补全 `get_valid_coupon` 末尾缺失的 `;` 和 `}`,确保代码可正常解析。 3. **消除 N+1 查询**:将 `build_reward_data` 及列表方法中的循环内数据库查询提取至循环外,改为批量查询(Batch Query)+ 内存数组映射。 ### 🛠 后续重构方向 1. **架构分层**:当前 Model 承担了过多业务逻辑(URL 拼接、时间计算、状态映射)。建议引入 `Service` 层处理复杂业务编排,`Model` 仅负责数据持久化与基础查询。 2. **常量与配置集中化**:建立 `config/reward_constants.php` 或在类顶部定义 `const`,统一管理来源、状态、场景映射,避免魔法数字散落。 3. **静态分析与规范落地**: - 集成 `PHPStan` (Level 5+) 或 `Psalm` 进行类型推断与潜在 Bug 扫描。 - 配置 `PHP_CodeSniffer` 强制遵循 PSR-12,修复拼写错误与缩进问题。 4. **框架适配说明**:代码结构高度类似 **CodeIgniter 3**。若 `phpci` 为内部定制版本,请核对官方文档中关于 `Query Builder` 安全绑定、模型自动加载及生命周期钩子的差异。建议优先使用框架原生组件替代原生 SQL 拼接。 > 💡 **提示**:本次审查基于提供的代码片段。若涉及支付、核销、库存扣减等核心链路,建议补充事务控制(`$this->db->trans_start()` / `$this->db->trans_complete()`)及并发锁机制的审查。 --- *此 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