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 557 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 - 1
TEXT
content
## 自动代码审查报告 **分支**: pay-260616 **提交**: `8bccacc2593ec81377a40498adce4fbc00e21239` **提交人**: LITTLEMAIDI (11833999+littlemaidi@user.noreply.gitee.com) **时间**: 2026-06-05 13:43:13 --- ## 1. 审查摘要 - **代码质量评分**:6.5 / 10 分 - **总体评价**:代码完整实现了商户礼品/卡券的核心业务逻辑,数据流转清晰。但存在明显的架构与规范问题:类外部直接调用框架实例、核心方法严重违反 DRY 原则、SQL 拼接存在注入隐患、日期格式化不规范。整体可维护性较低,需优先进行安全加固与结构重构。 - **风险等级**:🔴 高 ## 2. 问题详情 | 严重程度 | 文件/行号 | 问题描述 | 建议修改方案 | 代码示例 (可选) | | :--- | :--- | :--- | :--- | :--- | | 🔴 严重 | 全局/第3行 | `$CI = &get_instance();` 在类外部定义。若文件在框架未完全初始化时被 `include/require`,将直接触发 Fatal Error。且模型内部应直接使用 `$this`。 | 移除全局 `$CI` 赋值。若需加载其他模型,应在 `__construct()` 中调用或按需延迟加载。 | `public function __construct() { parent::__construct(); }` | | 🔴 严重 | `get_sold_coupons_list` / `buying_gift_check_status` | **SQL 注入风险**:`$shop_id` 未经严格类型校验直接拼接至 `where_str`。攻击者可传入恶意字符串破坏查询逻辑或越权访问。 | 强制类型转换 `(int)$shop_id`,并优先使用框架查询构建器的参数绑定机制。若 `Simple_model` 不支持占位符,至少需做严格过滤。 | `$shop_id = (int)$shop_id;`<br>`$where_str[] = "(gift._shop_id = {$shop_id} OR FIND_IN_SET({$shop_id}, gift._satisfy_shop_ids))";` | | 🟠 警告 | `get_gift_data` / `create_gift_data` | **日期格式化隐患**:`date('Ymd 8:00:00', ...)` 格式非标准,依赖 PHP 宽松解析。在部分 PHP 版本或严格模式下可能返回 `false` 或错误时间戳。 | 统一使用标准格式 `Y-m-d 08:00:00`,并增加空值/异常保护。 | `date('Y-m-d 08:00:00', strtotime("+$validity day", $excute_time))` | | 🟠 警告 | `create_gift_data` | **严重违反 DRY 原则**:类型 1/2/3/4/5-8 的字段映射、时间计算、消息拼接逻辑高度重复(超 300 行)。新增券类型需修改多处,极易遗漏。 | 抽取私有方法 `build_coupon_payload($base, $type, $relation_data)` 统一处理公共逻辑,使用策略模式或配置数组驱动差异字段。 | *(见下方重构建议)* | | 🟠 警告 | 多处查询 | **性能瓶颈**:频繁使用 `FIND_IN_SET` 匹配逗号分隔的 `_satisfy_shop_ids`。该函数无法利用 B-Tree 索引,数据量增长后将导致全表扫描。 | 建议拆分为关联表 `merchant_gift_shop`(`gift_id`, `shop_id`)。若暂无法改表,可考虑 MySQL 5.7+ 的 JSON 字段 + `JSON_CONTAINS`。 | 架构级优化,需 DBA 配合 | | 🟡 建议 | 全文 | **魔法数字/字符串泛滥**:如 `'1'`, `'4'`, `86400`, `'当天生效'` 等硬编码散落各处,降低可读性与后期维护效率。 | 使用类常量集中管理业务状态与配置,如 `const TYPE_ROOM_PACKAGE = 4; const SECONDS_PER_DAY = 86400;`。 | `const STATUS_ACTIVE = 1;`<br>`const VALIDITY_TODAY = 1;` | | 🟡 建议 | `get_coupon_pay_page` | **依赖隐式全局函数**:`throwError()`, `timeToHour()`, `returnWeek()` 等未声明依赖,破坏类的内聚性与单元测试可行性。 | 将全局函数封装为服务类注入,或统一使用标准 `throw new \Exception()` / CI 的 `show_error()`。 | `if (!in_array($pay_platform, ['1','3','22'])) { throw new \InvalidArgumentException('非法支付方式'); }` | | 🟡 建议 | 全文 | **PSR-12 规范不符**:部分 `if/else` 缺少大括号、缩进混用(Tab/Space)、`array()` 与 `[]` 混用、超长行未换行。 | 配置 `PHP_CodeSniffer` 或 `PHP-CS-Fixer` 自动格式化,统一团队编码风格。 | `if (empty($fields)) { $fields = '...'; }` | ## 3. 总结与行动建议 ### 🚨 优先修复项(P0) 1. **移除全局 `$CI` 实例化**:改为在 `__construct()` 中初始化,或直接使用 `$this->load->model()`。 2. **修复 SQL 拼接漏洞**:对所有外部传入的 ID/参数执行 `(int)` 强转或白名单校验,杜绝直接字符串拼接。 3. **修正日期计算逻辑**:将 `date('Ymd 8:00:00', ...)` 替换为 `date('Y-m-d 08:00:00', ...)`,避免时间解析异常导致券过期时间错误。 ### 🛠 后续重构方向 1. **DRY 重构 `create_gift_data`**: 该方法是本次审查的核心痛点。建议将重复的“时间计算+字段映射”抽取为独立方法: ```php private function build_coupon_data(array $base, array $relation, int $type): array { $time = time(); $excute = ($base['_start_time'] == 1) ? $time : $time + self::SECONDS_PER_DAY; $validity = intval($base['_validity'] ?? 0) + 1; $expire = strtotime(date('Y-m-d 08:00:00', strtotime("+$validity day", $excute))); // 统一基础字段 $data = [ '_excute_time' => $excute, '_expire_time' => $expire, '_relation_id' => $relation['_id'] ?? $base['_relation_id'], '_name' => $base['_name'], '_quantity' => $base['_quantity'], // ... 其他公共字段 ]; // 按类型注入差异化字段 if ($type === self::GOODS_TYPE) { $data['_value'] = $relation['_cost_price']; } // ... 其他类型处理 return $data; } ``` 2. **数据库设计优化**:评估将 `_satisfy_shop_ids` 从逗号分隔字符串迁移至独立关联表。若业务强依赖当前结构,可考虑在应用层缓存门店映射关系,减少 `FIND_IN_SET` 查询频率。 3. **框架适配说明**:代码结构高度契合 **CodeIgniter 3** 规范。若 `phpci` 为内部定制框架,请确认 `Simple_model::select()` 是否支持预处理参数绑定(如 `?` 占位符)。若不支持,建议在框架底层升级查询构建器,或严格使用 `(int)`/`$this->db->escape()` 进行防御。 > 💡 **审查局限性提示**:本次审查仅基于提供的单一 Model 文件。未包含 `Simple_model` 基类实现、全局辅助函数(如 `throwError`, `turn_array_key`)及 Controller 层调用上下文。建议结合完整调用链进行集成测试,重点验证并发场景下的券库存扣减与时间边界条件。 --- *此 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