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 623 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 **提交**: `0cc49c07974a677777bf4123cfd006e244468930` **提交人**: LITTLEMAIDI (11833999+littlemaidi@user.noreply.gitee.com) **时间**: 2026-06-09 10:54:42 --- ## 1. 审查摘要 - **代码质量评分**:6.0 / 10 分 - **总体评价**:业务逻辑覆盖全面,订单计价、会员折扣、套餐组合及退款流程设计较为完整。但存在**高危 SQL 注入隐患**、**资金计算精度缺失**、**事务边界混乱**及**调试代码残留**等严重问题。代码规范与框架最佳实践有较大优化空间。 - **风险等级**:🔴 高(涉及资金安全、数据一致性及系统稳定性) > 📌 **框架说明**:提交代码中大量使用 `get_instance()`、`$this->load->model()`、`$this->db->trans_start()` 等语法,属于典型的 **CodeIgniter 3 (CI3)** 架构。`phpci` 实为持续集成服务器(CI/CD 工具),并非 PHP 框架。以下审查将严格基于 **CI3 最佳实践** 与 **PSR-12 规范** 进行。 ## 2. 问题详情 | 严重程度 | 文件/行号 | 问题描述 | 建议修改方案 | 代码示例 (可选) | | :--- | :--- | :--- | :--- | :--- | | 🔴 严重 | `Neworderservice.php`<br>约 330 行 | **SQL 注入风险**:`$pack_goods_where = "wares_package._package_id in (" . implode(",", $id_array['package_id']) . ")";` 未对数组元素进行类型过滤,若传入恶意字符串将直接拼接至 SQL。 | 强制类型转换或使用 CI 查询构建器 `where_in()`。 | `$ids = array_map('intval', $id_array['package_id']);`<br>`$this->db->where_in('wares_package._package_id', $ids);` | | 🔴 严重 | `Ahead_book_order_model.php`<br>`refund_by_notify` 方法内 | **SQL 注入风险**:`$log_where = '_relation_id="' . $order_data['_id'] . '" and _status=1 and _type in (5,13)';` 直接拼接变量至查询条件,未做转义或参数化。 | 使用 CI Query Builder 替代原生字符串拼接。 | `$this->db->where('_relation_id', $order_data['_id'])`<br>`->where('_status', 1)`<br>`->where_in('_type', [5, 13]);` | | 🔴 严重 | `Neworderservice.php`<br>多处计价逻辑 | **资金计算精度丢失**:大量使用浮点数直接相乘/相加(如 `$goods_actual_pay = $v[$price_key] * $v['_quantity'];`),PHP 浮点数遵循 IEEE 754,易产生 `0.00000001` 级误差,导致对账失败。 | 涉及金额计算统一使用 `bcmath` 扩展或 `round()`,建议底层以“分”为单位计算。 | `$goods_actual_pay = round(bcmul($v[$price_key], $v['_quantity'], 2), 2);` | | 🔴 严重 | `Ahead_book_order_model.php`<br>`check_notify` 方法 | **事务边界混乱**:`try` 块内调用 `trans_complete()`,`catch` 块内又调用 `trans_rollback()`。若异常发生在 `trans_complete()` 之后,可能导致重复回滚或状态不一致。 | 移除 `try-catch` 中的手动回滚,统一使用 `trans_begin()` + `trans_status()` 显式控制。 | 见下方重构示例 | | 🟠 警告 | `Neworderservice.php`<br>约 415 行 | **调试代码残留**:循环中存在 `echo $vip_upgrade_data_actual_pay;`,生产环境会破坏 JSON/XML 响应结构,导致前端解析崩溃。 | 立即删除或替换为日志记录。 | `log_message('debug', 'vip_upgrade_actual_pay: ' . $vip_upgrade_data_actual_pay);` | | 🟠 警告 | `Neworderservice.php`<br>多个私有方法 | **重复加载模型**:在 `_create_insert_infos_data`、`get_goods_vip_price`、`getOrderTypeInfo` 中多次调用 `$this->CI->load->model()`,增加不必要的 I/O 开销。 | 将高频模型移至 `__construct()` 统一加载,或配置 `autoload.php`。 | `public function __construct() {`<br>` $this->CI =& get_instance();`<br>` $this->CI->load->model(['Ahead_vip_level_model', 'Ahead_merchant_goods_model']);`<br>`}` | | 🟠 警告 | `Ahead_book_order_model.php`<br>`refund` 方法 | **事务外状态更新**:在开启事务前执行 `$this->update()` 将订单状态改为 4。若后续退款逻辑失败回滚,订单状态已变更,造成数据不一致。 | 将状态更新移入 `trans_start()` 之后,确保原子性。 | 将 `update` 语句移至 `$this->db->trans_start();` 下方 | | 🟡 建议 | 全局文件 | **魔法数字泛滥**:硬编码如 `100`, `-1`, `9999999999999`, `13`, `14`, `58`, `56` 等散落各处,可读性差且后期维护成本极高。 | 提取为类常量或配置文件,如 `const STATUS_PENDING = -1; const DISCOUNT_BASE = 100;`。 | `const MAX_DEDUCT_AMOUNT = 9999999999999;`<br>`const PAY_SCENE_WX_BOOK = '5';` | | 🟡 建议 | `Neworderservice.php`<br>约 480 行 | **重复赋值冗余**:`$result['service_charge'] = $service_charge;` 连续赋值两次,无实际意义。 | 删除冗余行,保持代码整洁。 | 直接删除重复行 | ## 3. 总结与行动建议 ### 🚨 优先修复的关键问题 1. **立即修复 SQL 注入**:替换所有字符串拼接的 SQL 条件,全面改用 CI3 的 `$this->db->where()` / `where_in()` 或预处理语句。 2. **统一资金计算规范**:引入 `bcmath` 或封装 `MoneyCalculator` 类,所有金额运算强制保留 2 位小数,杜绝浮点数直接运算。 3. **修正事务控制逻辑**: ```php // 推荐的事务控制模式(替代 trans_start/trans_complete 混用) $this->db->trans_begin(); try { // 执行所有数据库操作 if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); return ['status' => false, 'msg' => '数据库操作失败']; } $this->db->trans_commit(); return ['status' => true, 'msg' => '成功']; } catch (\Exception $e) { $this->db->trans_rollback(); log_message('error', 'Transaction failed: ' . $e->getMessage()); return ['status' => false, 'msg' => '系统异常']; } ``` 4. **清理生产环境调试代码**:全局搜索 `echo`、`var_dump`、`print_r`,替换为 `log_message()` 或移除。 ### 🛠 后续重构与优化方向 - **架构解耦**:`Neworderservice.php` 承担了过多职责(计价、校验、组装、优惠券匹配)。建议拆分为 `OrderPricingService`、`CouponValidator`、`OrderAssembler`,符合单一职责原则。 - **常量与配置集中化**:将状态码、支付场景、折扣基数、最大抵扣额等提取至 `config/constants.php` 或类常量,提升可维护性。 - **模型加载优化**:CI3 支持自动加载,建议在 `application/config/autoload.php` 中配置高频模型/辅助函数,避免运行时重复 `load`。 - **规范对齐**:严格遵循 PSR-12 命名规范(类名 `PascalCase`,方法/属性 `camelCase` 或 `snake_case` 统一),清理历史注释(如 `//add by nan 22.07.11`),改用 Git Commit 记录变更。 - **安全加固**:对 `$order_data['_book_mobile']`、`$param['vip_card']` 等外部输入增加严格过滤与白名单校验;敏感操作(退款、状态变更)建议增加幂等性校验与操作日志审计。 > 💡 **提示**:若需针对 `phpci` 持续集成流水线配置代码扫描(如 PHP_CodeSniffer、PHPStan、SonarQube),可提供具体 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