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 334 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 - 合并会员卡积分变动日志记录
TEXT
content
## 自动代码审查报告 **分支**: pay-260519 **提交**: `53e9ba9bef5ef72ae4ccd9aaef192b93a0582061` **提交人**: LITTLEMAIDI (11833999+littlemaidi@user.noreply.gitee.com) **时间**: 2026-05-26 15:50:43 --- ## 1. 审查摘要 - **代码质量评分**:5.5 / 10 分 - **总体评价**:业务功能覆盖较全,但代码存在明显的架构臃肿、安全漏洞与性能瓶颈。模型层承担了过多业务逻辑(支付、短信、事务、配置加载),违反单一职责原则;多处使用字符串拼接构建 SQL,存在注入风险;循环内重复查询导致 N+1 性能问题;部分逻辑存在变量作用域 Bug。整体需进行安全加固与架构重构。 - **风险等级**:🔴 高 ## 2. 问题详情 | 严重程度 | 文件/行号 | 问题描述 | 建议修改方案 | 代码示例 (可选) | | :--- | :--- | :--- | :--- | :--- | | 🔴 严重 | `Ahead_vip_model.php` / `check_is_register` | **SQL 注入风险**:直接使用字符串拼接构建 `WHERE` 条件,未使用查询构建器或参数绑定,若 `$uid` 或 `$mobile` 未严格过滤将导致注入。 | 使用 CI 查询构建器或参数化查询替代字符串拼接。 | `$this->db->where("(_ahead_user_id = ? OR _mobile = ?) AND (_expiry_date = -1 OR _expiry_date > ?)", [$uid, $mobile, $now_time]);` | | 🔴 严重 | `Ahead_vip_model.php` / `pay_order`, `notify_book` | **危险 SQL 更新**:使用 `$up = "_account=_account-'" . $amount . "'";` 直接拼接 UPDATE 语句,绕过框架转义,易引发注入或语法错误。 | 使用 `$this->db->set()` 安全更新,或交由自定义基类处理参数绑定。 | `$this->db->set('_account', '_account - ' . (float)$amount, FALSE)->where($vip_where)->update($this->table_name);` | | 🔴 严重 | `Ahead_vip_points_log_model.php` / `add_by_point_goods` | **变量作用域 Bug**:`$smsExt['_id'] = $v['_order_id'];` 位于 `foreach` 循环外部,实际获取的是最后一次迭代的值,导致短信关联订单 ID 错误。 | 将短信发送逻辑移至循环内部,或收集所有订单 ID 后统一批量处理。 | 将 `send_sms` 调用移入 `foreach` 内部,或重构为 `$order_ids[] = $v['_order_id'];` 后统一发送。 | | 🟠 警告 | `Ahead_vip_model.php` / `register` | **事务管理不规范**:手动 `trans_rollback()` 与 `trans_complete()` 混用,且 `catch` 中未正确终止流程,可能导致事务状态不一致或重复回滚。 | 统一使用 `trans_begin()` / `trans_commit()` / `trans_rollback()`,或依赖 `trans_complete()` 自动回滚机制。 | 移除手动 `trans_rollback()`,在 `catch` 中直接 `return ['success'=>false, 'msg'=>'注册失败'];`,由框架自动处理回滚。 | | 🟠 警告 | `Ahead_vip_model.php` / `get_my_vip_card_list` | **N+1 查询性能瓶颈**:在 `foreach` 循环中重复调用 `get_card_info()`,数据量增大时数据库查询次数呈线性爆炸。 | 提前批量查询配置数据,构建映射数组,在循环中通过键值赋值。 | `$settings = $this->ahead_vip_setting_model->get_list_by_merchant_ids($merchantIds);`<br>`$value['user_self_recharge'] = $settings[$value['merchant_id']]['_user_self_recharge'] ?? '';` | | 🟠 警告 | `Ahead_vip_model.php` / `register` | **硬编码敏感配置**:`public $encrypt = "Vs!Fs7VT";` 直接暴露在模型中,违反安全规范且不利于多环境部署。 | 移至配置文件或环境变量,通过 `$this->config->item()` 读取。 | `protected $encrypt_key; public function __construct() { parent::__construct(); $this->encrypt_key = config_item('vip_encrypt_key'); }` | | 🟠 警告 | `Ahead_vip_model.php` / `register` | **依赖不可信外部变量**:使用 `$_SERVER['SERVER_NAME']` 构建支付回调 URL,易受 Host 头攻击导致回调失败或钓鱼。 | 使用框架配置的基础 URL 或明确配置项。 | `$notifyUrl = rtrim(config_item('base_url'), '/') . '/pay/wx/WxNotify/vipRegister';` | | 🟡 建议 | 全局 / 多个方法 | **违反单一职责原则**:`register` 方法超 200 行,混合了注册校验、支付路由、订单创建、配置加载等逻辑,维护成本极高。 | 拆分为独立服务类(如 `VipRegistrationService`、`PaymentRouterService`),Model 仅负责数据持久化。 | 提取支付逻辑至 `PaymentService::generateJsApiPay()`,Model 仅调用并返回结果。 | | 🟡 建议 | 全局 / 模型顶部 | **框架反模式**:文件顶部使用 `$CI = &get_instance();` 加载模型,在 CI3/类 CI 架构中非标准做法,CLI 环境下易报错。 | 移除顶部代码,在模型构造函数或方法内按需 `$this->load->model()`。 | 删除顶部两行,改为 `public function __construct() { parent::__construct(); $this->load->model('Simple_model'); }` | | 🟡 建议 | 全局 / 代码规范 | **缺乏类型声明与 PSR-12 规范**:无 PHP 7+ 类型提示,命名风格不统一(驼峰/下划线混用),魔法数字泛滥(如 `'1'`, `'-1'`, `200`)。 | 添加参数/返回值类型声明,统一命名规范,提取状态/类型常量。 | `public function register(int $merchantId, int &$shopId, int $uid, array $params): array`<br>`const STATUS_DISABLED = -1; const STATUS_ACTIVE = 1;` | ## 3. 总结与行动建议 ### 🔑 优先修复的关键问题 1. **立即修复 SQL 注入与危险更新**:替换 `check_is_register` 中的字符串拼接,以及 `pay_order`/`notify_book` 中的原始 SQL 拼接。这是最高优先级的安全红线。 2. **修复 `add_by_point_goods` 变量作用域 Bug**:该问题会导致积分兑换短信关联错误的订单号,直接影响客诉与对账。 3. **规范事务处理流程**:统一使用 `trans_begin()` / `trans_commit()` / `trans_rollback()` 或依赖 `trans_complete()` 自动回滚,避免手动干预导致的数据不一致。 ### 🛠 后续重构与优化方向 1. **架构解耦(Service 层引入)**:当前 Model 层承载了支付路由、短信发送、配置读取等职责。建议引入 `Service` 层处理业务流程,Model 仅保留 CRUD 与基础查询,符合 MVC 与 DDD 设计思想。 2. **性能优化策略**: - 消除循环内 DB 查询,改用 `WHERE IN` 批量获取数据后内存映射。 - 对高频读取的配置数据(如会员设置、等级信息)引入 Redis/Memcached 缓存,降低 DB 压力。 3. **代码规范与可维护性提升**: - 全面启用 PHP 7.4+ 类型声明(`declare(strict_types=1);`、参数类型、返回值类型)。 - 提取魔法数字为类常量或枚举,统一命名规范(建议数据库字段映射使用下划线,业务逻辑使用驼峰)。 - 清理注释代码与过期 `//edit by...` 标记,使用 Git 提交记录追溯变更。 4. **框架适配说明**:代码语法高度符合 **CodeIgniter 3** 规范。若 `phpci` 为内部定制框架,请确认其事务管理器与查询构建器是否与 CI3 一致。若存在差异,请以官方文档为准调整 `trans_*` 与 `where()` 的调用方式。 > ⚠️ **局限性提示**:`Ahead_vip_model.php` 末尾 `notify_preorder` 方法代码被截断,未能完整审查其后续逻辑。建议补充完整代码后再次进行闭环审查。 --- *此 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