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 633 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 remote-tracking branch 'origin/pay-260616' i
TEXT
content
## 自动代码审查报告 **分支**: pay-260616 **提交**: `7c248c9a19979d2d197232e1464ccf25c88a3a70` **提交人**: LITTLEMAIDI (11833999+littlemaidi@user.noreply.gitee.com) **时间**: 2026-06-09 14:40:10 --- ## 1. 审查摘要 - **代码质量评分**:5.5 / 10 分 - **总体评价**:代码实现了较为复杂的订单计价、优惠券抵扣、支付回调及退款逻辑,业务覆盖全面。但核心方法严重臃肿(God Method),存在未清理的调试输出、变量重复赋值、潜在 SQL 注入及频繁加载 Model 等性能隐患。整体代码风格与 PSR-12 规范差距较大,可维护性与安全性亟待提升。 - **风险等级**:🔴 高 ## 2. 问题详情 > *注:因提供的代码片段存在截断,行号为基于上下文估算的近似位置,实际审查请以完整文件为准。* | 严重程度 | 文件/行号 | 问题描述 | 建议修改方案 | 代码示例 (可选) | | :--- | :--- | :--- | :--- | :--- | | 🔴 严重 | `Neworderservice.php` ~L380 | 遗留 `echo $vip_upgrade_data_actual_pay;` 调试语句。在 API 或 JSON 响应场景下会直接破坏输出结构,导致前端解析失败。 | 彻底移除 `echo`/`var_dump`/`print_r`,统一替换为框架日志组件(如 `log_message()` 或 `doLog()`)。 | `// 移除该行,改用日志:<br>doLog("VIP升级金额累加: {$vip_upgrade_data_actual_pay}", 'order_calc');` | | 🔴 严重 | `Ahead_yc_order_model.php` ~L250 | 原始 SQL 字符串拼接存在 **SQL 注入风险**。`$sql = '_unique_key="' . $unique_key . '" AND ...'` 未对 `$unique_key` 进行转义或参数绑定。 | 使用框架查询构造器或参数化查询,杜绝手动拼接。 | `$this->db->where('_unique_key', $unique_key)<br> ->where_in('_status', [1, 4])<br> ->where('_timestamp >', time() - 7 * 86400)<br> ->get()->result_array();` | | 🔴 严重 | `Neworderservice.php` ~L430 | 关键订单字段被**重复赋值覆盖**。`$order['_prime_service_charge']` 先赋 `$prime_after_paid_service_charge`,紧接着又被 `$service_charge` 覆盖;`$result['service_charge']` 同理。 | 梳理业务语义,确认应保留的值,删除冗余赋值,避免金额计算错乱。 | `$order['_prime_service_charge'] = $service_charge; // 仅保留最终计算值<br>// 删除重复的 $order['_prime_service_charge'] = $service_charge;` | | 🟠 警告 | `Ahead_shop_group_buying_coupon_model.php` ~L30 | `FIND_IN_SET` 拼接未严格过滤,且 CI 查询构造器不支持 `$where['where'][] = [implode(...)]` 这种嵌套语法,易引发 SQL 语法错误或注入。 | 强制类型转换后使用原生 `where` 字符串,或改用 CI 的 `where()` 链式调用。 | `$shop_id = (int)$shop_id;<br>$this->db->where("FIND_IN_SET({$shop_id}, _satisfy_shop_ids) > 0");` | | 🟠 警告 | `Ahead_book_order_model.php` ~L110 | 异常分支中 `$result['msg']` 未定义直接返回,触发 PHP Notice,且可能导致前端收到 `null` 错误信息。 | 使用空合并运算符 `??` 提供默认值,或提前初始化响应数组。 | `$subMsg = $res_data['response']['result']['sub_msg'] ?? '未知错误';<br>return ['status' => false, 'msg' => '退款失败: ' . $subMsg];` | | 🟠 警告 | 全局多处 | 频繁在方法内部调用 `$this->CI->load->model()` 或 `$this->load->model()`。每次调用都会触发文件 I/O 与实例化,严重拖慢高并发下的订单计算与退款流程。 | 将高频依赖的 Model 移至构造函数统一加载,或配置自动加载。 | `public function __construct() {<br> parent::__construct();<br> $this->load->model(['Ahead_vip_level_model', 'Ahead_merchant_goods_model', 'Ahead_pay_log_model']);<br>}` | | 🟡 建议 | `Neworderservice.php` `getOrderTypeInfo` | 方法长度超 500 行,嵌套层级深,违反单一职责原则(SRP)。计价、折扣、服务费、免单逻辑耦合严重,极难单元测试。 | 按业务域拆分为独立私有方法:`calcGoodsPrice()`, `calcPackagePrice()`, `applyRewardDiscount()`, `calcServiceCharge()` 等。 | `// 主方法仅保留流程编排<br>$goodsData = $this->calcGoodsPrice($id_array, $goods_quantity);<br>$packageData = $this->calcPackagePrice($id_array, $goods_quantity);<br>return $this->assembleOrderResult($goodsData, $packageData);` | | 🟡 建议 | 全局 | 大量魔法数字(`-1`, `1`, `100`, `2`, `3`)与混合数组语法 `array()`/`[]` 并存,不符合 PSR-12 规范,降低可读性。 | 定义类常量/枚举,统一使用短数组语法 `[]`,建议文件头部添加 `declare(strict_types=1);`。 | `const STATUS_DISABLED = -1;<br>const DISCOUNT_FULL = 100;<br>const PAY_TYPE_WECHAT = 1;<br>// 统一使用 [] 替代 array()` | ## 3. 总结与行动建议 ### 🔑 优先修复的关键问题 1. **清理调试输出**:立即全局搜索并移除 `echo`、`var_dump`、`print_r`,避免生产环境输出污染。 2. **修复 SQL 注入隐患**:将 `Ahead_yc_order_model.php` 中的原始 SQL 拼接全部替换为查询构造器或参数绑定。 3. **修正重复赋值 Bug**:核对 `Neworderservice.php` 中 `$order['_prime_service_charge']` 与 `$result['service_charge']` 的业务意图,保留正确逻辑。 4. **防御性编程**:对 `FIND_IN_SET`、`implode` 等动态拼接处增加严格类型校验(如 `(int)` 强转),防止恶意参数注入。 ### 🛠 后续重构与优化方向 1. **架构解耦(拆分 God Method)**:`Neworderservice::getOrderTypeInfo` 承载了过多职责。建议引入 **策略模式(Strategy Pattern)** 或 **工厂模式**,将 `case '13'/'1'`(酒水/售货柜)与 `case '2'/'4'`(开房套餐)的计价逻辑抽离为独立的 `PriceCalculator` 类。 2. **性能优化**: - 将循环内的 `$this->load->model()` 提前至构造器。 - 批量查询替代循环查询:如 `get_merchant_goods_by_ids` 已实现,但后续价格策略查询可考虑一次性拉取后内存匹配,减少 DB 往返。 - 金额计算统一使用 `bcmath` 扩展或框架内置的货币处理工具,避免浮点数精度丢失(当前大量使用 `sprintf("%.2f")` 和直接乘除,存在精度风险)。 3. **规范与可维护性**: - 启用 `PSR-12` 代码风格检查器(如 `PHP_CodeSniffer` 或 `PHP-CS-Fixer`)进行自动化格式化。 - 将状态码、支付类型、折扣标识等硬编码提取为 `const` 常量或独立配置类。 - 补充关键业务方法的 PHPDoc 注释,明确参数类型、返回值及异常抛出条件。 > 💡 **框架适配说明**:当前代码结构高度契合 **CodeIgniter 3.x** 规范。若 `phpci` 为内部定制或升级版本,请重点核对:① 事务处理是否推荐使用 `trans_begin()/trans_commit()/trans_rollback()` 替代 `trans_start()/trans_complete()`;② Model 自动加载机制是否已优化。建议查阅 `phpci` 官方文档确认组件生命周期差异。 --- *此 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