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 462 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 - Merge branch 'pay-260616' of https://gitea.g-hi.co
TEXT
content
## 自动代码审查报告 **分支**: pay-260616 **提交**: `bf1edff88440429c70c62cec00506846bb56d7e2` **提交人**: linyangrui (yangruilin888@gmail.com) **时间**: 2026-06-02 13:52:49 --- ## 1. 审查摘要 - **代码质量评分**:5.5 / 10 分 - **总体评价**:代码实现了复杂的订单计价、预订校验与支付退款逻辑,业务覆盖较全。但存在明显的**财务精度隐患**、**遗留调试代码**、**事务控制不规范**及**大量魔法数字**。代码结构偏向“过程式堆砌”,缺乏面向对象封装,且未遵循现代 PHP 编码规范。 - **风险等级**:🟠 中(涉及资金计算与支付回调,精度与事务问题可能引发资损或数据不一致) > 📌 **框架说明**:根据代码结构(`BASEPATH`、`get_instance()`、`system/` 目录规范),当前项目实际基于 **CodeIgniter 3** 框架,而非 `phpci`。以下审查将严格基于 CI3 架构与 PHP 最佳实践进行。 --- ## 2. 问题详情 | 严重程度 | 文件/位置 | 问题描述 | 建议修改方案 | 代码示例 (可选) | | :--- | :--- | :--- | :--- | :--- | | 🔴 严重 | `Neworderservice.php`<br>`getOrderTypeInfo` 方法内 | **遗留调试代码**:循环中存在 `echo $vip_upgrade_data_actual_pay;`。在 API/Service 层直接输出会破坏 JSON/XML 响应结构,导致前端解析失败或支付回调异常。 | 立即删除 `echo`,如需排查请改用 `log_message('debug', ...)` 或框架日志组件。 | `// 删除该行<br>log_message('debug', '升级金额: ' . $vip_upgrade_data_actual_pay);` | | 🔴 严重 | `Neworderservice.php`<br>多处价格计算逻辑 | **浮点数精度丢失风险**:金额计算直接使用 `float` 运算,仅用 `sprintf("%.2f")` 格式化。PHP 浮点数运算存在固有精度问题(如 `0.1+0.2=0.30000000000000004`),长期运行易导致账目不平。 | 财务计算必须统一转为**整数(分)**或使用 `bcmath` 扩展。所有加减乘除使用 `bcadd`, `bcmul`, `bcsub` 等。 | `$actual_pay = bcmul($price, $quantity, 2);<br>$total = bcadd($total, $actual_pay, 2);` | | 🟠 警告 | `Ahead_book_order_model.php`<br>`check_notify` 方法 | **事务控制不规范**:使用 `$this->db->trans_start()` 配合 `try-catch` 手动 `trans_rollback()`。CI3 的 `trans_start()` 已内置自动回滚机制,混合使用可能导致状态混乱或重复回滚。 | 改用显式事务控制:`trans_begin()` → 业务逻辑 → `trans_status()` 判断 → `trans_commit()` / `trans_rollback()`。 | 见下方重构示例 | | 🟠 警告 | 多个文件<br>业务方法内部 | **模型重复加载**:在循环或方法体内频繁调用 `$this->CI->load->model()`。CI3 的 Loader 虽支持重复加载不报错,但会增加不必要的 I/O 与内存开销。 | 将依赖模型统一移至 `__construct()` 中加载,或配置 `config/autoload.php`。 | `public function __construct() {<br> parent::__construct();<br> $this->load->model('Ahead_vip_level_model');<br>}` | | 🟠 警告 | `Ahead_shop_book_time_info_model.php` | **静态缓存脏数据风险**:大量使用 `public static $xxx = []` 缓存门店/日期数据。在 PHP-FPM 长连接或 CLI 守护进程下,静态变量不会随请求释放,易引发内存泄漏或跨请求数据污染。 | 改为实例属性 `private $cache = []`,或引入 Redis/Memcached。若必须用静态缓存,需在请求结束或关键节点 `unset()`。 | `private static $cache = [];<br>// 使用完后清理<br>self::$cache = [];` | | 🟡 建议 | `Neworderservice.php`<br>`Ahead_book_order_model.php` | **魔法数字泛滥**:大量使用 `-1, 1, 2, 3, 4, 5, 7, 13, 14, 22` 表示状态、支付渠道、业务类型。可读性极差,后期维护极易出错。 | 定义类常量或独立配置类集中管理。 | `const PAY_WECHAT = 1;<br>const PAY_VIP = 3;<br>const STATUS_DISABLED = -1;` | | 🟡 建议 | 全部文件 | **未遵循 PSR-12 规范**:缩进不一致、混用 `array()` 与 `[]`、单行过长、注释风格老旧(如 `//add by nan 210317`)。 | 使用 `PHP-CS-Fixer` 或 IDE 自动格式化。统一短数组语法、4空格缩进、移除过时注释。 | 全局替换 `array()` → `[]`<br>统一注释为 `/** ... */` 或 `// ` | | 🟡 建议 | `Ahead_book_order_model.php`<br>`send_success_msg` | **敏感信息日志泄露**:`doLog(var_export($order_data, true))` 可能记录用户手机号、支付流水号等敏感信息,违反数据安全规范。 | 日志输出前进行脱敏处理(如手机号掩码、流水号截断)。 | `doLog('退款请求: ' . json_encode($safe_data), 'refund');` | ### 🔧 事务控制重构示例(CI3 推荐写法) ```php $this->db->trans_begin(); try { // 1. 执行数据库操作 $this->db->insert('table', $data); $this->db->update('table', $data, ['id' => $id]); // 2. 检查事务状态 if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); return ['status' => false, 'msg' => '数据库操作失败']; } // 3. 提交事务 $this->db->trans_commit(); return ['status' => true, 'msg' => '成功']; } catch (Exception $e) { $this->db->trans_rollback(); log_message('error', '事务异常: ' . $e->getMessage()); return ['status' => false, 'msg' => '系统异常']; } ``` --- ## 3. 总结与行动建议 ### 🚨 优先修复项(P0/P1) 1. **立即移除 `echo` 调试代码**,防止破坏 API 响应流。 2. **全面替换浮点数运算为 `bcmath` 或整数分计算**,财务模块必须保证精度绝对安全。 3. **规范数据库事务写法**,采用 `trans_begin()` + `trans_status()` 显式控制,避免隐式回滚导致的状态不一致。 4. **模型依赖前置**,将 `load->model()` 移至构造函数,提升执行效率。 ### 🛠 后续重构方向 1. **架构分层优化**:当前 `Neworderservice` 承担了过多职责(价格计算、优惠券校验、套餐组装、状态映射)。建议拆分为: - `PriceCalculator`(纯计算逻辑,无副作用) - `OrderAssembler`(数据组装与持久化) - `CouponValidator`(优惠券规则校验) 2. **常量与配置抽离**:建立 `config/order_constants.php`,集中管理支付渠道、订单状态、业务类型等魔法数字。 3. **引入 DTO/VO 模式**:使用数组传递大量业务数据极易出现键名拼写错误或类型不一致。建议定义 `OrderDTO`、`GoodsDTO` 等数据结构类,提升类型安全与 IDE 提示体验。 4. **静态缓存治理**:评估 `Ahead_shop_book_time_info_model` 中的静态缓存必要性。高频查询建议接入 Redis,低频数据使用实例级缓存即可。 > ⚠️ **局限性说明**:提供的 `Neworderservice.php` 与 `Ahead_shop_book_time_info_model.php` 代码在末尾被截断,部分循环逻辑、边界条件处理及辅助函数(如 `mergeTimeRanges`、`throwError`)无法完整评估。建议补充完整代码以便进行更精准的边界测试与安全审计。 --- *此 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