mirror of
http://124.126.16.154:8888/singularity/hdk-pay.git
synced 2026-01-15 07:15:06 +08:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7d836f50df | ||
|
|
0452910354 | ||
|
|
28b81f427e | ||
|
|
46da805cb4 |
@@ -0,0 +1,66 @@
|
||||
## 修复计划
|
||||
|
||||
### 问题分析
|
||||
在 `/Users/weili/Projects/HDK/Pay/src/Infrastructure/Repository/InvoiceRepo.php` 第131-137行,创建 `InvoiceProduct` 实例时缺少 `prices` 参数,导致构造函数调用失败。
|
||||
|
||||
### 错误原因
|
||||
1. `InvoiceProduct` 类构造函数需要6个参数:`caseId`, `uid`, `name`, `sku`, `description`, `prices`
|
||||
2. 当前代码只传递了5个参数,缺少 `prices` 参数
|
||||
3. `prices` 参数是 `PointPrice[]` 类型的数组,不能为空
|
||||
|
||||
### 修复步骤
|
||||
|
||||
1. **添加必要的导入**
|
||||
- 在 `InvoiceRepo.php` 中添加 `Money` 和 `Currency` 类的导入
|
||||
- 添加 `PointPrice` 类的导入
|
||||
|
||||
2. **处理API响应中的prices数据**
|
||||
- 从API响应中提取 `prices` 数据(路径:`$result['product']['prices']`)
|
||||
- 遍历 `prices` 数据,为每个价格创建 `PointPrice` 实例
|
||||
- 使用 `array_map` 函数简化处理过程
|
||||
|
||||
3. **完善InvoiceProduct实例创建**
|
||||
- 将处理好的 `prices` 数组传递给 `InvoiceProduct` 构造函数
|
||||
|
||||
### 预期结果
|
||||
- 修复后,`InvoiceRepo::getInvoiceInfo()` 方法能够成功创建 `InvoiceProduct` 实例
|
||||
- 不再出现构造函数参数缺失的错误
|
||||
- 代码能够正常运行,返回完整的 `InvoiceInfo` 对象
|
||||
|
||||
### 修复代码示例
|
||||
|
||||
```php
|
||||
// 1. 在InvoiceRepo.php顶部添加必要的导入
|
||||
use Money\Currency;
|
||||
use Money\Money;
|
||||
use Singularity\HDK\Pay\Domain\Invoice\Aggregate\Invoice\ValueObject\PointPrice;
|
||||
|
||||
// 2. 在getInvoiceInfo()方法中完善InvoiceProduct实例创建
|
||||
product: new InvoiceProduct(
|
||||
caseId: $result['case_id'],
|
||||
uid: $result['uid'],
|
||||
name: $result['product']['name'],
|
||||
sku: $result['product']['sku'],
|
||||
description: $result['product']['description'],
|
||||
prices: array_map(
|
||||
callback: fn(array $price) => new PointPrice(
|
||||
price: new Money(
|
||||
amount: bcmul((string)$price['amount'], '100', 2),
|
||||
currency: new Currency($price['currency']),
|
||||
),
|
||||
currencySymbol: $price['symbol'],
|
||||
),
|
||||
array: $result['product']['prices'],
|
||||
),
|
||||
),
|
||||
```
|
||||
|
||||
### 检查结果
|
||||
- 已检查所有使用 `InvoiceProduct` 的地方,只有 `InvoiceRepo.php` 中存在参数缺失问题
|
||||
- `InvoiceProductRepo.php` 中的实现是正确的,可以作为参考
|
||||
- 修复后,所有 `InvoiceProduct` 实例创建都会符合构造函数要求
|
||||
|
||||
### 测试建议
|
||||
- 修复后,运行相关测试用例验证修复效果
|
||||
- 可以使用 `./run-in-docker.sh APP_STATUS=false vendor/bin/pest --coroutine --prepend=tests/bootstrap.php` 运行测试
|
||||
- 检查是否还有其他类似的构造函数参数问题
|
||||
14
CHANGELOG.md
14
CHANGELOG.md
@@ -1,4 +1,18 @@
|
||||
# 版本更新日志
|
||||
### [1.12.2](http://124.126.16.154:8888/singularity/hdk-pay/compare/v1.12.1...v1.12.2) (2025-12-01)
|
||||
|
||||
### [1.12.1](http://124.126.16.154:8888/singularity/hdk-pay/compare/v1.12.0...v1.12.1) (2025-12-01)
|
||||
|
||||
|
||||
### 🐛 Bug Fixes | Bug 修复
|
||||
|
||||
* **InvoiceRepo:** 修复InvoiceProduct构造函数缺少prices参数的问题 ([46da805](http://124.126.16.154:8888/singularity/hdk-pay/commit/46da805cb41cdb777dbd9627a53f431e204904e2))
|
||||
|
||||
|
||||
### ✨ Features | 新功能
|
||||
|
||||
* **Invoice:** 添加价格和货币信息到发票信息 ([28b81f4](http://124.126.16.154:8888/singularity/hdk-pay/commit/28b81f427e7ca618b0b1d561d83e107dcbba3c9c))
|
||||
|
||||
## [1.12.0](http://124.126.16.154:8888/singularity/hdk-pay/compare/v1.11.1...v1.12.0) (2025-11-28)
|
||||
|
||||
|
||||
|
||||
@@ -69,5 +69,5 @@
|
||||
"url": "https://mirrors.aliyun.com/composer/"
|
||||
}
|
||||
},
|
||||
"version": "1.12.0"
|
||||
"version": "1.12.2"
|
||||
}
|
||||
|
||||
@@ -7,11 +7,13 @@
|
||||
* Powered by PhpStorm
|
||||
* Created on 2025/9/5
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Singularity\HDK\Pay\Domain\Invoice\Aggregate\Invoice;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Money\Money;
|
||||
use Singularity\HDK\Pay\Domain\Invoice\Aggregate\Invoice\ValueObject\PointBalance;
|
||||
|
||||
final readonly class InvoiceInfo
|
||||
@@ -27,8 +29,25 @@ final readonly class InvoiceInfo
|
||||
private Carbon $invoiceAt,
|
||||
private Carbon $designedAt,
|
||||
private string $patientName,
|
||||
private Money $price,
|
||||
private string $currencySymbol,
|
||||
) {}
|
||||
|
||||
public function getAmount(): float
|
||||
{
|
||||
return (float)bcdiv($this->price->getAmount(), '100', 2);
|
||||
}
|
||||
|
||||
public function getCurrencyCode(): string
|
||||
{
|
||||
return $this->price->getCurrency()->getCode();
|
||||
}
|
||||
|
||||
public function getCurrencySymbol(): string
|
||||
{
|
||||
return $this->currencySymbol;
|
||||
}
|
||||
|
||||
public function getInvoiceNo(): string
|
||||
{
|
||||
return $this->invoiceNo;
|
||||
@@ -78,4 +97,4 @@ final readonly class InvoiceInfo
|
||||
{
|
||||
return $this->patientName;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
* Powered by PhpStorm
|
||||
* Created on 2025/8/29
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Singularity\HDK\Pay\Infrastructure\Repository;
|
||||
@@ -23,6 +24,7 @@ use Singularity\HDK\Pay\Domain\Invoice\Aggregate\Invoice\Invoice;
|
||||
use Singularity\HDK\Pay\Domain\Invoice\Aggregate\Invoice\InvoiceInfo;
|
||||
use Singularity\HDK\Pay\Domain\Invoice\Aggregate\Invoice\InvoiceProduct;
|
||||
use Singularity\HDK\Pay\Domain\Invoice\Aggregate\Invoice\ValueObject\PointBalance;
|
||||
use Singularity\HDK\Pay\Domain\Invoice\Aggregate\Invoice\ValueObject\PointPrice;
|
||||
use Singularity\HDK\Pay\Domain\Invoice\Repository\InvoiceRepoInterface;
|
||||
|
||||
final class InvoiceRepo extends AbstractRepo implements InvoiceRepoInterface
|
||||
@@ -134,6 +136,7 @@ final class InvoiceRepo extends AbstractRepo implements InvoiceRepoInterface
|
||||
name: $result['product']['name'],
|
||||
sku: $result['product']['sku'],
|
||||
description: $result['product']['description'],
|
||||
prices: [],
|
||||
),
|
||||
balance: new PointBalance(
|
||||
total: $result['balance']['total'],
|
||||
@@ -144,6 +147,11 @@ final class InvoiceRepo extends AbstractRepo implements InvoiceRepoInterface
|
||||
invoiceAt: new Carbon($result['invoice_at']),
|
||||
designedAt: new Carbon($result['designed_at']),
|
||||
patientName: $result['patient_name'],
|
||||
price: new Money(
|
||||
bcmul((string)$result['price']['amount'], '100', 2),
|
||||
new Currency($result['price']['currency_code']),
|
||||
),
|
||||
currencySymbol: $result['price']['currency_symbol'],
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ it('should initial account balance', function () {
|
||||
type: PointType::from($point_balance['type']),
|
||||
basic: $point_balance['basic'],
|
||||
bonus: $point_balance['bonus'],
|
||||
expiredAt: $point_balance['expired_at'],
|
||||
expiredAt:$point_balance['expired_at'],
|
||||
version: $point_balance['version'],
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user