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 367 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 - 1
TEXT
content
## 自动代码审查报告 **分支**: pay-260519 **提交**: `58b9c6915931a7b047a3cba8208be79183192a18` **提交人**: LITTLEMAIDI (11833999+littlemaidi@user.noreply.gitee.com) **时间**: 2026-05-27 16:14:28 --- ## 1. 审查摘要 - **代码质量评分**:4 / 10 分 - **总体评价**:该类承担了订单创建、价格计算、会员折扣、优惠券匹配、服务费核算等核心业务,逻辑复杂度高。但实现方式较为陈旧,存在**SQL注入隐患、浮点数精度丢失、关键变量重复覆盖**等严重问题。方法体过长(超600行),严重违反单一职责原则,可维护性与扩展性较差。 - **风险等级**:🔴 高 - **⚠️ 局限性说明**:提交代码在 `$result['have_good` 处截断,本次审查仅基于可见部分。若截断处包含关键事务提交或状态更新逻辑,请补充后复核。 --- ## 2. 问题详情 | 严重程度 | 文件/行号 | 问题描述 | 建议修改方案 | 代码示例 (可选) | | :--- | :--- | :--- | :--- | :--- | | 🔴 严重 | `getOrderTypeInfo` 约 L240 | **SQL 注入风险**:使用 `implode` 拼接 `IN` 查询条件 `$pack_goods_where = "... in (" . implode(",", $id_array['package_id']) . ")"`,未对 `$id_array['package_id']` 进行类型过滤或参数绑定。 | 严格使用框架查询构建器的 `where_in` 方法,或对输入数组进行强制整型转换。 | `$ids = array_map('intval', $id_array['package_id']);`<br>`$this->CI->db->where_in('wares_package._package_id', $ids);` | | 🔴 严重 | 全文多处 | **金额计算精度丢失**:直接使用浮点数进行货币乘除(如 `$goods['_cost_price'] * $quantity`),PHP 浮点运算会导致 `0.1+0.2=0.30000000000000004` 类问题,极易引发财务对账差异。 | 财务计算必须使用 `bcmath` 扩展函数,或统一转换为“分”为单位的整数运算。 | `bcmul($price, $quantity, 2)`<br>或 `$price_cents = (int)round($price * 100);` | | 🔴 严重 | `getOrderTypeInfo` 约 L330 | **逻辑覆盖/冗余赋值**:`$order['_prime_service_charge']` 被连续赋值两次,后者直接覆盖前者,导致前置计算结果丢失,业务逻辑错误。 | 删除重复赋值行,明确业务意图。若需区分“折前”与“折后”服务费,应使用不同键名。 | 移除 `$order['_prime_service_charge'] = $service_charge;` 或改为 `$order['_final_service_charge'] = $service_charge;` | | 🟠 警告 | 全文多处 | **模型重复加载**:在方法内部多次调用 `$this->CI->load->model(...)`。虽然 CI 框架会缓存实例,但频繁调用增加解析开销且破坏代码整洁性。 | 将模型加载统一移至 `__construct()` 或方法顶部,按需使用。 | `// __construct 中统一加载`<br>`$this->CI->load->model(['Ahead_merchant_goods_model', 'Ahead_vip_level_model', ...]);` | | 🟠 警告 | `_create_insert_infos_data` 等 | **静态属性访问不规范 & 重复计算**:通过实例访问静态属性 `$this->CI->Ahead_vip_level_model::VIP_LEVEL_DEFAULT_NAME`,且在多处重复调用 `count()`。PHP 8+ 已废弃此写法。 | 直接通过类名访问静态属性,并将结果缓存为类属性,避免重复计算。 | `private $vip_max_level;`<br>`// 构造时赋值`<br>`$this->vip_max_level = count(Ahead_vip_level_model::VIP_LEVEL_DEFAULT_NAME);` | | 🟠 警告 | `getOrderTypeInfo` | **异常处理不规范**:使用全局函数 `throwError()` 中断流程,破坏面向对象封装,且无法被上层 `try-catch` 统一捕获,不利于事务回滚。 | 改用标准 `throw new \Exception()` 或自定义业务异常类,配合事务机制处理。 | `throw new \InvalidArgumentException("商品{$val['_goods_name']}已被禁用");` | | 🟡 建议 | 类定义/方法名 | **命名不符合 PSR-12**:类名 `Neworderservice` 未使用大驼峰;方法 `rest_goods_price_by_un_vip` 存在拼写错误(应为 `reset`);变量命名风格混杂。 | 遵循 PSR-12 规范:类名 `NewOrderService`,方法名 `resetGoodsPriceByUnVip`,属性使用小驼峰。 | `class NewOrderService { public function resetGoodsPriceByUnVip(...) }` | | 🟡 建议 | `getOrderTypeInfo` | **方法过长/违反单一职责**:该方法超 600 行,混合了数据校验、价格计算、优惠券匹配、订单组装等逻辑,圈复杂度过高,极难测试与维护。 | 拆分为独立私有方法或策略类,如 `validateGoods()`, `calculatePrice()`, `applyDiscounts()`, `buildOrderData()`。 | 提取 `private function calculatePackagePrice(...)` 等方法,主方法仅负责流程编排。 | --- ## 3. 总结与行动建议 ### 🔑 优先修复的关键问题 1. **立即修复 SQL 注入漏洞**:将 `implode` 拼接的 SQL 条件替换为框架查询构建器或严格类型过滤,防止恶意输入导致数据泄露或篡改。 2. **统一财务计算精度**:全局替换浮点数直接运算,引入 `bcmath` 或“分”单位整数计算,并在输出前统一格式化,确保财务数据绝对准确。 3. **修正重复赋值逻辑**:排查 `$order['_prime_service_charge']` 及 `$result['service_charge']` 的重复赋值问题,避免业务计算结果被意外覆盖。 ### 🛠 后续重构与优化方向 1. **架构拆分(SRP 原则)**: - 将 `getOrderTypeInfo` 拆分为:`校验层`(商品状态/库存/权限)、`计算层`(原价/会员价/折扣/服务费)、`组装层`(订单结构/明细)。 - 针对订单类型 `1/13` 与 `2/4`,建议引入 **策略模式(Strategy Pattern)**,将不同订单类型的计价逻辑抽离为独立类,消除庞大的 `switch-case`。 2. **依赖注入与模型管理**: - 避免在业务方法中动态 `load->model()`,改为在构造函数中注入或统一加载。若 `phpci` 支持 DI 容器,建议通过容器解析模型依赖。 3. **异常与事务控制**: - 使用 `try-catch` 包裹核心下单流程,结合数据库事务(`$this->CI->db->trans_start()` / `trans_complete()`),确保价格计算失败或库存校验不通过时能安全回滚。 4. **框架适配提示**: > 基于代码特征(`defined('BASEPATH')`, `get_instance()`, `$this->CI->load->model()`),该代码高度符合 **CodeIgniter 3** 架构。若 `phpci` 为内部定制框架,请查阅其官方文档确认: > - 查询构建器是否支持 `where_in` 参数绑定 > - 模型加载机制是否支持自动依赖注入 > - 全局异常处理钩子(`_exception_handler`)的配置方式 如需对截断部分或特定业务分支(如优惠券抵扣逻辑、会员升级推荐算法)进行深度审查,请提供完整代码片段。 --- *此 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