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 490 in issue
id
Primary key.
INTEGER NOT NULL
repo_id
INTEGER
index
INTEGER
poster_id
INTEGER
original_author
TEXT
original_author_id
INTEGER
name
🔍 代码审查报告:app-260616 - 1
TEXT
content
## 自动代码审查报告 **分支**: app-260616 **提交**: `9757cffc5a8cc8098f078dfe0b0ccf5cabca1dfb` **提交人**: LITTLEMAIDI (11833999+littlemaidi@user.noreply.gitee.com) **时间**: 2026-06-03 10:34:54 --- ## 1. 审查摘要 - **代码质量评分**:6.5 / 10 分 - **总体评价**:该模型业务逻辑覆盖较全,能够支撑社区门店营收统计的核心场景。但存在**高危 SQL 注入漏洞**、**静态缓存设计缺陷**、**财务计算精度隐患**及多处不符合现代 PHP 编码规范的问题。代码结构高度契合 CodeIgniter 3 风格,若 `phpci` 为定制框架,需重点核对底层查询构造器与生命周期是否兼容。 - **风险等级**:🔴 高 ## 2. 问题详情 | 严重程度 | 文件/行号 | 问题描述 | 建议修改方案 | 代码示例 (可选) | | :--- | :--- | :--- | :--- | :--- | | 🔴 严重 | `get_community_revenues_sum_data`<br>`get_community_revenues_detail_data` | **SQL 注入风险**:手动拼接 `pay_platform_where` 字符串,若 `$params['pay_platform_arr']` 来自外部输入,将直接导致 SQL 注入。 | 严禁字符串拼接 SQL 条件。应使用框架提供的参数绑定或查询构造器方法(如 `where_in`、`or_where`)。 | `$this->db->group_start();`<br>`foreach (...) { $this->db->or_where(...); }`<br>`$this->db->group_end();` | | 🔴 严重 | `get_date_type_info` | **静态缓存污染**:`self::$date_type_info` 为静态变量,首次加载后缓存了特定 `$shop_id` 的营业时间。若同请求处理多商户或定时任务,将返回错误的时间范围。 | 移除静态属性,改为实例属性缓存,或按 `$shop_id` 作为键值隔离缓存。 | `protected $date_type_cache = [];`<br>`if (empty($this->date_type_cache[$shop_id])) { ... }` | | 🟠 警告 | 全局金额计算 | **财务精度丢失**:使用 `+`/`-` 直接对浮点数进行加减,PHP 浮点运算存在精度误差(如 `0.1+0.2 != 0.3`),可能导致对账不平。 | 财务计算必须使用 `bcmath` 扩展或统一转换为“分”(整数)运算,最后再格式化输出。 | `bcsub($income, $refund, 2)`<br>`bcmul($amount, 100, 0)` | | 🟠 警告 | 文件顶部 | **框架实例滥用**:`$CI = &get_instance();` 在类文件顶部全局执行,不符合 CI/现代框架规范,易引发作用域污染与内存泄漏。 | 模型已继承基类,应直接使用 `$this`。如需访问核心实例,应在构造函数中赋值。 | `public function __construct() { parent::__construct(); }` | | 🟠 警告 | `get_community_revenues_trend` | **循环内查询**:在 `foreach ($result as &$v)` 中执行 `$this->select()`,虽仅循环 2 次,但违背批量查询最佳实践,增加 DB 连接开销。 | 提取所有时间范围,使用单次 `IN` 查询或 `GROUP BY` 批量获取,在 PHP 层进行数据映射。 | 见下方优化建议 | | 🟡 建议 | 类/方法命名 | **违反 PSR-12**:类名 `Jh_community_shop_revenues_detail_model` 与方法名使用蛇形命名,不符合 PHP 规范。 | 类名改为大驼峰(PascalCase),方法名改为小驼峰(camelCase)。 | `class JhCommunityShopRevenuesDetailModel`<br>`public function addByBookOrderRefund()` | | 🟡 建议 | 多处方法 | **魔法数字泛滥**:大量硬编码 `1, 2, 8, 9, 17` 等代表业务状态,可读性差且易遗漏维护。 | 提取为类常量,配合类型提示提升可维护性。 | `const TYPE_INCOME = 1;`<br>`const PLATFORM_WX = 1;` | | 🟡 建议 | 模型加载 | **重复加载模型**:各方法内频繁调用 `$this->load->model()`,增加框架 I/O 开销。 | 统一在构造函数中加载,或使用依赖注入容器管理。 | `__construct() { $this->load->model('ahead_yc_merchant_model'); }` | ## 3. 总结与行动建议 ### 🔑 优先修复项(P0/P1) 1. **修复 SQL 注入**:立即重构 `get_community_revenues_sum_data` 与 `detail_data` 中的 `pay_platform_arr` 条件拼接逻辑。若 `phpci` 查询构造器支持,请使用参数绑定: ```php // 安全写法示例 $this->db->group_start(); foreach ($params['pay_platform_arr'] as $platform) { $parts = explode('_', $platform); if (!empty($parts[1])) { $this->db->or_where(['a._pay_platform' => $parts[0], 'a._second_pay_platform' => $parts[1]]); } else { $this->db->or_where('a._pay_platform', $parts[0]); } } $this->db->group_end(); ``` 2. **解决静态缓存错乱**:将 `public static $date_type_info = [];` 改为实例属性 `protected $date_type_info = [];`,并在 `get_date_type_info` 中按 `$shop_id` 隔离缓存。 3. **财务计算精度**:全局替换 `+`/`-` 金额计算为 `bcmath` 函数,例如: ```php $result['wx_amount'] = change_number_format(bcsub($wx_income_amount, $wx_refund_amount, 2)); ``` ### 🛠 后续重构方向 - **规范命名与注释**:全面遵循 PSR-12 规范,修正类名、方法名及 `@return` 类型(`true` → `bool`)。补充关键业务逻辑的注释,特别是 `sales_type_map` 与 `revenues_pay_platform_arr` 的映射关系。 - **查询性能优化**:将 `get_community_revenues_trend` 中的循环查询改为单次聚合查询。例如: ```php // 优化思路:一次性查出所有时间段数据,PHP 层按 key 映射 $where['where_in'][] = ['_business_date', array_merge($start_dates, $end_dates)]; $data = $this->select($where, $fields); // 使用 array_column 或哈希表快速匹配 ``` - **异常处理标准化**:将全局函数 `throwError()` 替换为 PHP 标准异常或框架异常类(如 `throw new \RuntimeException('营业收入走势查询时间错误');`),便于统一捕获与日志记录。 - **框架适配确认**:代码中大量使用 `$this->set_table_v2()`、`$this->enforce_con_db()` 等自定义方法。请确保这些方法在 `Report_model` 基类中已正确处理事务、读写分离与表名动态切换。若 `phpci` 官方文档有推荐的动态表名或分库分表方案,建议对齐官方最佳实践。 > 💡 **局限性说明**:本次审查仅基于提供的单文件代码。若 `Report_model` 基类、全局辅助函数(如 `get_business_date`)或控制器层存在未暴露的上下文逻辑,部分边界条件(如事务回滚、并发写入)需结合完整调用链进一步验证。建议补充单元测试覆盖核心统计方法。 --- *此 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