This commit is contained in:
ray zhou
2026-05-29 11:21:40 +08:00
parent 5d6d482efe
commit f71a5c59af
447 changed files with 32245 additions and 116 deletions

View File

@@ -0,0 +1,58 @@
---
name: update 返回值 intval
overview: 在 WalletUserStatModel::updateWithOptionalVersion 中对 ThinkORM update 返回值做 intval 显式转换,保证声明返回 int 与运行时一致,并统一所有经该方法的 apply*/incField 出口。
todos:
- id: apply-intval-updateWithOptionalVersion
content: updateWithOptionalVersion 使用 $result + return (int) intval 并补 PHPDoc
status: completed
isProject: false
---
# updateWithOptionalVersion 返回值显式转换
## 问题
[`app/model/WalletUserStatModel.php`](app/model/WalletUserStatModel.php) 中:
```php
private static function updateWithOptionalVersion(...): int {
// ...
return $query->update($data); // 当前仓库版本
}
```
- `incField` / `applyDeposit` / `applyWithdraw`**全部**`updateWithOptionalVersion` 返回「影响行数」。
- ThinkORM 链式 `static::where(...)->update($data)`**BaseQuery** 上文档为 `int`,但 IDE/静态分析常因 `Model::update()` 静态方法(返回 `Modelable`)产生 **联合类型**,与 `: int` 不匹配。
- 你本地已改为 `intval($result)`,这是正确做法:统一把 `false`、数字字符串等收敛为 `int`,避免类型告警与调用方误判。
## 修改(单点即可)
在 [`updateWithOptionalVersion`](app/model/WalletUserStatModel.php) 末尾改为:
```php
$result = $query->update($data);
return (int) $result;
```
`return intval($result);`(与你本地写法等价;项目内可统一用 `(int)``intval`,二选一即可)。
**无需** 在每个 `apply*` / `incField` 再包一层转换——它们已 `return static::updateWithOptionalVersion(...)`,改一处即全覆盖。
## PHPDoc可选一行补充
在方法 `@return` 说明中注明:「对 ORM `update` 结果做整型转换,无匹配行时为 0」。
## 验证
Docker 内复用既有冒烟(`incField` / `applyDeposit`),确认返回仍为 `1`/`0` 整数:
```bash
docker exec -w /app/www/ray/slot-wallet php82 php -r "
# bootstrap 后 WalletUserStatModel::incField(...)
"
```
## 不涉及
- 不改 MQ / WalletLogic
- 不恢复 `inc()->update()` 链式写法