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
Delete row 488 from issue
id
488
repo_id
22
index
61
poster_id
1
original_author
original_author_id
0
name
🔍 代码审查报告:app-260616 - 1
content
## 自动代码审查报告 **分支**: app-260616 **提交**: `94f1af278
## 自动代码审查报告 **分支**: app-260616 **提交**: `94f1af2781fb88f4aa18866c5d0f6cffc6e416b9` **提交人**: LITTLEMAIDI (11833999+littlemaidi@user.noreply.gitee.com) **时间**: 2026-06-03 10:26:07 --- ## 1. 审查摘要 - **代码质量评分**:6.5 / 10 - **总体评价**:代码整体业务逻辑完整,覆盖了多种营收场景的日志记录与报表查询。但存在**静态缓存污染、SQL注入风险、高频N+1查询**等核心缺陷,且代码复用率低、框架规范遵循度不足。在并发写入或复杂查询场景下易引发数据丢失、性能瓶颈及安全漏洞。 - **风险等级**:🔴 高 ## 2. 问题详情 | 严重程度 | 文件/行号 | 问题描述 | 建议修改方案 | 代码示例 (可选) | | :--- | :--- | :--- | :--- | :--- | | 🔴 严重 | `get_date_type_info` 方法 | 使用 `public static $date_type_info` 缓存时间配置,但未以 `$shop_id` 为键。同一请求内切换不同门店时,会错误返回首次加载的门店数据,导致报表时间范围错乱。 | 改为以 `$shop_id` 为键的二维数组缓存,或移除静态缓存改为实例属性。 | `if (!isset(self::$date_type_info[$shop_id])) { self::$date_type_info[$shop_id] = [...]; }` | | 🔴 严重 | `_add_log` / `ORDER_TYPE` 常量 | `sales_type_map` 中存在 `11 => 13` 映射,但 `ORDER_TYPE` 中 `'13'` 已被注释。导致 `_add_log` 中 `isset(self::ORDER_TYPE[$insert['_order_type']])` 校验失败,**静默丢弃该类型日志**,造成财务数据丢失。 | 取消注释 `ORDER_TYPE['13']`,或在映射前增加类型白名单校验。 | `const ORDER_TYPE = [ ..., '13' => 'App-计时开房', ... ];` | | 🔴 严重 | `get_community_revenues_sum_data` / `detail_data` | `$params['pay_platform_arr']` 直接通过字符串拼接构造 SQL 条件:`'a._pay_platform=' . $pay_platform`。若参数来自前端未过滤,将导致 **SQL 注入漏洞**。 | 强制类型转换 `(int)`,或改用框架查询构造器的参数绑定机制。 | `$pay_platform = (int)($pay_platform_arr[0] ?? 0);`<br>`$this->db->where('a._pay_platform', $pay_platform);` | | 🟠 警告 | `_add_log` 方法 | 每次写入营收明细时,均调用 `get_room_info_by_order` 查询数据库获取包厢信息。在订单高频写入场景下,会引发严重的 **N+1 查询性能瓶颈**。 | 将包厢信息作为参数传入,或改为批量查询/Redis缓存。避免在写入链路中同步查库。 | `private function _add_log($insert, $order_data, $room_info = [])`<br>`if (empty($room_info)) { $room_info = $this->get_room_info_by_order($order_data); }` | | 🟠 警告 | 全局 `$CI = &get_instance();` | 文件顶部直接调用 `get_instance()` 并赋值给全局变量 `$CI`,且在 `_add_log` 中读取 `$CI->guotong_refund_id`。破坏 MVC 分层,且全局状态在 CLI/异步任务中极易引发致命错误。 | 移除全局 `$CI`。国通退款单号应通过方法参数传入,或存储于 Session/Config 中。 | `private function _add_log($insert, $order_data, $guotong_refund_id = null)`<br>`if ($insert['_type'] == 2 && !empty($guotong_refund_id)) { ... }` | | 🟠 警告 | `get_community_revenues_*` 系列方法 | 多个查询方法存在大量重复代码(社区商家校验、表名切换、时间解析、DB连接切换)。违反 DRY 原则,后期维护成本高。 | 提取为私有方法 `prepare_query_context($merchant_id, $params)` 统一处理前置逻辑。 | `private function prepare_query_context($merchant_id, $params) { ... return $where; }` | | 🟠 警告 | `get_community_revenues_trend` | 循环内直接修改 `$where` 数组:`$where['_business_date >='] = $v['start_date'];`。若后续迭代中其他条件变化,会携带上一次迭代的日期条件,导致查询结果污染。 | 每次循环前克隆基础 `$where` 数组,确保条件隔离。 | `$query_where = $base_where;`<br>`$query_where['_business_date >='] = $v['start_date'];` | | 🟡 建议 | 全文件 / 类定义 | 类名 `Jh_community_shop_revenues_detail_model` 使用蛇形命名,不符合 PSR-12 规范;DocBlock 中 `@return true` 类型标注错误;魔法数字(如 `1,2,8,9`)散落各处。 | 类名改为 `JhCommunityShopRevenuesDetailModel`;修正 `@return bool`;将支付类型、订单类型提取为类常量。 | `class JhCommunityShopRevenuesDetailModel extends Report_model`<br>`const PAY_PLATFORM_WX = 1;` | | 🟡 建议 | 多处方法 | 频繁在业务方法内部调用 `$this->load->model()`。在 CI 架构中,模型加载应在构造函数或自动加载器中完成,重复加载增加 I/O 开销。 | 将依赖模型移至 `__construct()` 中统一加载,或使用框架的依赖注入容器。 | `public function __construct() { parent::__construct(); $this->load->model('ahead_yc_merchant_model'); ... }` | ## 3. 总结与行动建议 ### 🔑 优先修复的关键问题 1. **修复数据丢失漏洞**:立即恢复 `ORDER_TYPE` 中键 `'13'` 的定义,或修正 `sales_type_map` 映射关系,确保所有订单类型均能正常落库。 2. **消除 SQL 注入风险**:对所有来自 `$params` 的数组参数进行严格类型校验(`(int)` 或 `filter_var`),禁止直接字符串拼接 SQL 片段。建议全面迁移至框架提供的 Query Builder 参数绑定语法。 3. **解决静态缓存污染**:将 `self::$date_type_info` 改为按 `$shop_id` 隔离的缓存结构,或改为实例级属性,避免多租户/多门店场景下的数据串扰。 ### 🛠 后续重构与优化方向 - **架构解耦**:移除全局 `$CI` 依赖,将外部状态(如 `guotong_refund_id`)通过方法参数或上下文对象传递,提升代码的可测试性与 CLI 兼容性。 - **性能调优**: - 将 `_add_log` 中的包厢信息查询改为**异步写入**或**批量预加载**,避免阻塞主交易链路。 - 报表聚合逻辑(如 `wx_income_amount` 等)可考虑下沉至数据库层,使用 `SUM(CASE WHEN _type=1 THEN _amount ELSE -_amount END)` 替代 PHP 循环累加,减少内存占用与网络传输。 - **规范与可维护性**: - 统一遵循 PSR-12 命名规范,提取魔法数字为语义化常量。 - 补充输入参数校验(如 `start_time`、`page` 等),使用框架的 `Validation` 组件或自定义守卫方法,避免 `Undefined index` 报错。 - 若 `phpci` 为内部定制框架,建议查阅官方文档确认 `enforce_con_db()` 的连接池管理机制,确保高并发下连接释放正确,避免连接泄漏。 > 💡 **注**:代码结构高度契合 CodeIgniter 3 规范。若 `phpci` 为基于 CI 的二次开发框架,上述建议均适用。涉及框架底层组件(如 `enforce_con_db`、`throwError`)的用法,请以贵司内部技术文档为准。 --- *此 Issue 由代码审查服务自动创建*
...
milestone_id
0
priority
0
is_closed
0
is_pull
0
num_comments
0
ref
deadline_unix
0
created_unix
1780453567
updated_unix
1780453567
closed_unix
0
is_locked
0
content_version
0
time_estimate
0
Delete
Cancel