Compare commits

...

12 Commits

Author SHA1 Message Date
李东云
0573ff595f chore(release): 1.13.2 2025-12-24 15:26:41 +08:00
李东云
72004d3916 chore(release): 1.13.1 2025-12-24 14:11:33 +08:00
李东云
7ade038f0f fix(ProductRepo): 将isset检查改为!empty检查以确保数据有效性 2025-12-24 14:11:13 +08:00
李东云
175a170dec chore(release): 1.13.0 2025-12-02 17:59:45 +08:00
李东云
19e95016fa feat(发票): 为发送发票接口添加可选邮箱参数
在发送发票接口中添加可选的邮箱参数,允许指定接收发票的邮箱地址。当不指定邮箱时,保持原有行为不变。
2025-12-02 17:59:18 +08:00
李东云
6fd7f2f421 chore(release): 1.12.4 2025-12-02 16:05:11 +08:00
李东云
1d1cdd7829 fix(invoice): 修正发票金额计算逻辑
- 将金额乘以100改为除以100以获得正确的数值
- 确保货币金额在存储前被正确转换为浮点数
- 保留两位小数精度以匹配财务数据标准
2025-12-02 16:04:53 +08:00
李东云
98fa6262a9 chore(release): 1.12.3 2025-12-01 15:32:07 +08:00
李东云
7d836f50df chore(release): 1.12.2 2025-12-01 15:18:19 +08:00
李东云
0452910354 chore(release): 1.12.1 2025-12-01 15:00:34 +08:00
李东云
28b81f427e feat(Invoice): 添加价格和货币信息到发票信息
- 在 InvoiceInfo 类中添加 price 和 currencySymbol 属性,并提供相关获取方法
- 修改 InvoiceRepo 以适配新的 InvoiceInfo 结构
2025-12-01 15:00:07 +08:00
李东云
46da805cb4 fix(InvoiceRepo): 修复InvoiceProduct构造函数缺少prices参数的问题
添加PointPrice数组参数到InvoiceProduct构造函数调用中,确保API响应中的价格数据被正确处理。同时添加必要的类导入声明。
2025-12-01 14:04:36 +08:00
8 changed files with 150 additions and 11 deletions

View File

@@ -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` 运行测试
- 检查是否还有其他类似的构造函数参数问题

View File

@@ -1,4 +1,43 @@
# 版本更新日志
### [1.13.2](http://124.126.16.154:8888/singularity/hdk-pay/compare/v1.13.1...v1.13.2) (2025-12-24)
### [1.13.1](http://124.126.16.154:8888/singularity/hdk-pay/compare/v1.13.0...v1.13.1) (2025-12-24)
### 🐛 Bug Fixes | Bug 修复
* **ProductRepo:** 将isset检查改为!empty检查以确保数据有效性 ([7ade038](http://124.126.16.154:8888/singularity/hdk-pay/commit/7ade038f0fb1c6a857428d75667ccb2289d392fd))
## [1.13.0](http://124.126.16.154:8888/singularity/hdk-pay/compare/v1.12.4...v1.13.0) (2025-12-02)
### ✨ Features | 新功能
* **发票:** 为发送发票接口添加可选邮箱参数 ([19e9501](http://124.126.16.154:8888/singularity/hdk-pay/commit/19e95016fae1230cce88b3ead5c9ae2474bfdafc))
### [1.12.4](http://124.126.16.154:8888/singularity/hdk-pay/compare/v1.12.3...v1.12.4) (2025-12-02)
### 🐛 Bug Fixes | Bug 修复
* **invoice:** 修正发票金额计算逻辑 ([1d1cdd7](http://124.126.16.154:8888/singularity/hdk-pay/commit/1d1cdd7829942984f4dcdd16e7e0d1ba9ac9d1ce))
### [1.12.3](http://124.126.16.154:8888/singularity/hdk-pay/compare/v1.12.2...v1.12.3) (2025-12-01)
### [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)

View File

@@ -69,5 +69,5 @@
"url": "https://mirrors.aliyun.com/composer/"
}
},
"version": "1.12.0"
"version": "1.13.2"
}

View File

@@ -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;
}
}
}

View File

@@ -1,4 +1,5 @@
<?php
/**
* InvoiceRepoInterface.php@Pay
*
@@ -33,14 +34,15 @@ interface InvoiceRepoInterface
/**
* @param string $invoiceNo
* @param string|null $email
* @return void
* @throws GuzzleException
*/
public function send(string $invoiceNo): void;
public function send(string $invoiceNo, ?string $email): void;
/**
* @param string $invoiceNo
* @return InvoiceInfo
*/
public function findOne(string $invoiceNo): InvoiceInfo;
}
}

View File

@@ -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
@@ -45,7 +47,7 @@ final class InvoiceRepo extends AbstractRepo implements InvoiceRepoInterface
'country' => $cmd->country,
'zip' => $cmd->zipCode,
'price' => [
'amount' => (float)bcmul($money->getAmount(), '100', 2),
'amount' => (float)bcdiv($money->getAmount(), '100', 2),
'currency' => [
'code' => $money->getCurrency()->getCode(),
'symbol' => $cmd->currencySymbol,
@@ -83,12 +85,17 @@ final class InvoiceRepo extends AbstractRepo implements InvoiceRepoInterface
/**
* @inheritDoc
*/
public function send(string $invoiceNo): void
public function send(string $invoiceNo, ?string $email): void
{
if (empty($invoiceNo)) {
throw new ValidateException(message: 'invoice no is required.');
}
$this->requestService->requestGet(url: "/rpc/v2/invoice/invoices/$invoiceNo/email");
$this->requestService->requestGet(
url: "/rpc/v2/invoice/invoices/$invoiceNo/email",
data: [
'email' => $email,
],
);
}
/**
@@ -134,6 +141,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 +152,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'],
);
}
}
}

View File

@@ -148,7 +148,7 @@ final class ProductRepo extends AbstractRepo implements RechargeProductRepoInter
$result = Json::decode($content);
return new RechargeProduct(
oneTime: isset($result['one_time'])
oneTime: !empty($result['one_time'])
? new ProductItem(
id: $result['one_time']['id'],
description: $result['one_time']['name'],
@@ -164,7 +164,7 @@ final class ProductRepo extends AbstractRepo implements RechargeProductRepoInter
),
)
: null,
renew: isset($result['renew'])
renew: !empty($result['renew'])
? new ProductItem(
id: $result['renew']['id'],
description: $result['renew']['name'],

View File

@@ -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'],
);
}