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 82 in issue
id
Primary key.
INTEGER NOT NULL
repo_id
INTEGER
index
INTEGER
poster_id
INTEGER
original_author
TEXT
original_author_id
INTEGER
name
🔍 代码审查报告:pc-260519 - 需求 小程序问题设置 16268
TEXT
content
## 自动代码审查报告 **分支**: pc-260519 **提交**: `ec6a2fcf44c78065aacba544ce48bb101aab17cc` **提交人**: chenjunfeng (developer.jeff.c@gmail.com) **时间**: 2026-04-28 17:55:01 --- ## 1. 审查摘要 - **代码质量评分**:6 / 10 - **总体评价**:代码实现了完整的门店配置管理业务,功能覆盖较广。但存在明显的“上帝方法”(God Method)反模式,大量重复的权限校验与配置读写逻辑未抽象,违反单一职责原则(SRP)。部分历史遗留写法(如全局 `$CI` 实例化、直接操作 `$_SESSION`、错误抑制符 `@`)带来潜在的安全与稳定性风险。整体可维护性较低,需进行结构化重构。 - **风险等级**:🟠 中高风险(主要源于安全规范缺失、逻辑冗余及框架最佳实践偏离) ## 2. 问题详情 | 严重程度 | 文件/行号 | 问题描述 | 建议修改方案 | 代码示例 (可选) | | :--- | :--- | :--- | :--- | :--- | | 🔴 严重 | `Ahead_shop_config_model.php` 第5行 | **文件作用域全局实例化 `$CI`**:在类外部直接执行 `$CI = &get_instance();` 会导致每次加载该文件时强制初始化 CI 超级对象,破坏框架生命周期,且可能引发未定义变量或内存泄漏。 | 移除文件顶部的 `$CI` 实例化。模型内部应通过 `$this->load->model()` 或依赖注入获取依赖。 | `// 删除文件顶部这两行<br>class Ahead_shop_config_model extends Simple_model { ... }` | | 🔴 严重 | `Shop.php` `ShopList()` 方法 | **直接操作原生 `$_SESSION`**:绕过框架 Session 驱动,若后续将 Session 迁移至 Redis/DB 或开启加密,此处将直接失效或报错。 | 使用框架提供的 Session 库读取数据。 | `$merchant_id = $this->session->userdata('merchant_merchant_id');` | | 🔴 严重 | `Ahead_shop_config_model.php` 多处 | **使用 `@json_decode` 抑制错误**:静默忽略 JSON 解析失败,导致后续逻辑基于 `null` 或空数组运行,可能引发静默数据损坏或逻辑分支错误。 | 移除 `@`,增加 `json_last_error()` 校验或提供默认值。 | `if (json_last_error() !== JSON_ERROR_NONE) { throwError('配置数据格式异常'); }` | | 🟠 警告 | `Shop.php` `ShopAdd()` 方法 | **冗余且易错的 `insert_id()` 调用**:连续调用两次 `$this->db->insert_id()`,第二次赋值给未使用的 `$add_id`,若中间有其他 DB 操作会导致 ID 丢失或判断失效。 | 仅保留一次调用,并直接用于后续逻辑。 | `$shop_id = $this->db->insert_id();<br>if (!$shop_id) $this->error_response("插入记录失败");` | | 🟠 警告 | `Shop.php` `setShopPayAfterStatus()` | **危险的原生 SQL 翻转逻辑**:`_pay_after=_pay_after*-1` 依赖数据库字段当前值,若字段为 `0`、`NULL` 或非预期值,翻转逻辑将失效或产生脏数据。 | 先查询当前值,在 PHP 层完成状态切换后再更新。 | `$current = $this->ahead_shop_model->get_one($where, '_pay_after');<br>$new_val = ($current['_pay_after'] == 1) ? -1 : 1;<br>$this->ahead_shop_model->update(['_pay_after' => $new_val], $where);` | | 🟠 警告 | 两个文件 | **超长 `switch-case` 违反 SRP**:`get_config_list` 与 `edit` 方法包含数十个 `case`,每个分支耦合了查询、格式化、校验逻辑,导致方法臃肿、难以测试且极易引入回归 Bug。 | 拆分为独立方法,或采用“配置驱动+策略模式”。将配置类型映射到独立的 Handler 类。 | `// 策略模式示例<br>$handler = ConfigHandlerFactory::create($type);<br>return $handler->getList($where, $page, $page_size);` | | 🟠 警告 | `Shop.php` 多个 `get...Setting` 方法 | **重复的权限校验与分页逻辑**:约 20 个方法包含完全相同的 `$CI = &get_instance();` 权限判断、分页参数提取、模型调用与响应封装。 | 抽取为基类方法或 Trait,通过参数化配置类型实现复用。 | `protected function handleConfigSetting($type, $isGet = true) { ... }` | | 🟡 建议 | 全局 | **命名规范与魔法值泛滥**:大量使用 `_name`、`_merchant_id` 下划线前缀(非 PSR/CI 标准),且 `1`、`-1`、`'all'` 等魔法值散落各处,可读性差。 | 定义常量类或枚举,统一字段命名(建议移除 `_` 前缀),使用 `const` 或 `enum` 替代魔法值。 | `const STATUS_ON = 1; const STATUS_OFF = -1; const PRIV_ALL = 'all';` | | 🟡 建议 | `Ahead_shop_config_model.php` | **模型加载时机不当**:在 `switch` 分支内部动态 `$this->load->model()`,虽 CI 会缓存,但增加解析开销且破坏依赖明确性。 | 在控制器或模型构造函数中统一加载,或使用 CI 的 `autoload.php`。 | `public function __construct() { parent::__construct(); $this->load->model('Ahead_family_servers_model'); }` | ## 3. 总结与行动建议 ### 🔑 优先修复的关键问题 1. **移除文件级 `$CI` 实例化**:立即删除 `Ahead_shop_config_model.php` 顶部的全局代码,避免框架生命周期污染。 2. **替换原生 `$_SESSION`**:全面排查控制器,改用 `$this->session->userdata()`,确保 Session 驱动可插拔。 3. **修复 `insert_id()` 冗余与 `@json_decode` 隐患**:清理 `ShopAdd` 中的重复调用,全局替换 `@json_decode` 为带错误检查的安全解析。 4. **重构 `setShopPayAfterStatus` 翻转逻辑**:杜绝依赖数据库字段自增/自乘的脆弱写法,改为显式状态切换。 ### 🛠 后续重构与优化方向 1. **抽象配置管理基类/Trait**: 将 `get...Setting` / `set...Setting` 的重复逻辑抽离为 `ConfigControllerTrait`,通过传入 `$config_type` 自动路由至 `Ahead_shop_config_model` 的对应方法,减少 80% 的样板代码。 2. **策略模式替代巨型 Switch**: 为 `Ahead_shop_config_model` 创建 `ConfigTypeHandler` 接口,将 `app_pay_platform`、`screen_control` 等复杂配置拆分为独立类。模型仅负责路由分发,提升可测试性与扩展性。 3. **统一数据校验层**: 引入 CI 的 `Form_validation` 库或自定义 `Validator` 类,替代散落的 `isset()`、`empty()` 和 `throwError()`。对 JSON 配置、数组参数进行严格 Schema 校验。 4. **规范命名与常量管理**: - 移除数据库字段前缀 `_`(如 `_name` → `name`),保持与 CI 查询构建器习惯一致。 - 建立 `AppConstants.php` 或 `Enums/` 目录,集中管理状态码、支付类型、权限标识等魔法值。 5. **框架适配提示**: 当前代码基于 CodeIgniter 2/3 风格。若项目计划升级至 CI4 或 Laravel,建议提前将 `$this->db->query()` 替换为 Query Builder,将 `throwError()` 替换为标准异常抛出,并启用 PSR-4 自动加载。 > 💡 **审查说明**:由于未提供 `Simple_model`、`PcServer` 基类及自定义 Helper(如 `safe_replace`、`throwError`、`two_dimensional_arr_sort`)的源码,部分安全与逻辑判断基于 CI 标准实践推演。建议结合项目实际基类实现进行交叉验证。 --- *此 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