Compare commits

...

7 Commits

Author SHA1 Message Date
李东云
e92a6f46a4 chore(release): 1.11.1 2025-11-27 16:01:04 +08:00
李东云
e0748e444b chore(release): 1.11.0 2025-11-27 11:52:19 +08:00
李东云
244dd1220a feat(invoice): 添加发票金额和货币支持
- 在 CreateInvoiceCmd 中新增 price 和 currencySymbol 字段
- 在 Invoice 聚合根中集成 Money 对象并添加相关方法
- 更新 InvoiceRepo 以处理价格数据的序列化与反序列化
- 在测试中增加对新字段的验证
2025-11-27 11:51:46 +08:00
李东云
8a9971bc59 chore(release): 1.10.0 2025-11-25 16:01:52 +08:00
李东云
4c5dde9020 feat(invoice): 引入点数价格值对象并更新发票产品结构
- 新增 PointPrice 值对象用于表示金额与货币符号
- 修改 InvoiceProduct 结构以支持多个 PointPrice 实例
- 更新 InvoiceProductRepo 以映射数据库中的价格数据
- 在测试中验证 prices 字段的正确性和类型安全
2025-11-25 16:01:25 +08:00
李东云
1cb20a7c7e test(product): 移除测试中的 only 标记
- 移除了 QueryPointRateTest 中两个测试用例的 only 标记
- 确保所有测试用例都能正常执行
- 避免因 only 标记导致其他测试被跳过
2025-11-25 15:30:06 +08:00
李东云
028721feb1 chore(deps): 移除 Carbon 依赖包
- 从 composer.json 中移除了 nesbot/carbon 依赖
- 保留了 swoole/ide-helper 依赖包
- 更新了依赖包列表格式以保持整洁
2025-11-25 14:54:22 +08:00
12 changed files with 656 additions and 481 deletions

View File

@@ -1,4 +1,30 @@
# 版本更新日志
### [1.11.1](http://124.126.16.154:8888/singularity/hdk-pay/compare/v1.11.0...v1.11.1) (2025-11-27)
## [1.11.0](http://124.126.16.154:8888/singularity/hdk-pay/compare/v1.10.0...v1.11.0) (2025-11-27)
### ✨ Features | 新功能
* **invoice:** 添加发票金额和货币支持 ([244dd12](http://124.126.16.154:8888/singularity/hdk-pay/commit/244dd1220a2c19197ef08f41a82bcb273d0900e8))
## [1.10.0](http://124.126.16.154:8888/singularity/hdk-pay/compare/v1.9.7...v1.10.0) (2025-11-25)
### 🚀 Chore | 构建/工程依赖/工具
* **deps:** 移除 Carbon 依赖包 ([028721f](http://124.126.16.154:8888/singularity/hdk-pay/commit/028721feb1079eaa4fe80f20066912d46634f3df))
### ✅ Tests | 测试
* **product:** 移除测试中的 only 标记 ([1cb20a7](http://124.126.16.154:8888/singularity/hdk-pay/commit/1cb20a7c7e2c1a26c7b72669e6885d39f8d16005))
### ✨ Features | 新功能
* **invoice:** 引入点数价格值对象并更新发票产品结构 ([4c5dde9](http://124.126.16.154:8888/singularity/hdk-pay/commit/4c5dde9020364573d0e9673138620d967149e9f0))
### [1.9.7](http://124.126.16.154:8888/singularity/hdk-pay/compare/v1.9.6...v1.9.7) (2025-10-30)

View File

@@ -36,8 +36,7 @@
"firebase/php-jwt": "^6.8.0",
"hyperf/testing": "^3.1",
"friendsofhyperf/pest-plugin-hyperf": "3.1.*",
"swoole/ide-helper": "^4.8.13",
"nesbot/carbon": "^2.0"
"swoole/ide-helper": "^4.8.13"
},
"minimum-stability": "beta",
"prefer-stable": true,
@@ -70,5 +69,5 @@
"url": "https://mirrors.aliyun.com/composer/"
}
},
"version": "1.9.7"
"version": "1.11.1"
}

987
composer.lock generated

File diff suppressed because it is too large Load Diff

View File

@@ -11,16 +11,21 @@ declare(strict_types=1);
namespace Singularity\HDK\Pay\Application\Command;
final readonly class CreateInvoiceCmd {
use Money\Money;
final readonly class CreateInvoiceCmd
{
public function __construct(
public string $caseId,
public bool $setFreqInvAddr,
public string $receiver,
public string $patientName,
public string $address,
public string $city,
public string $state,
public string $country,
public string $zipCode,
public string $caseId,
public bool $setFreqInvAddr,
public string $receiver,
public string $patientName,
public string $address,
public string $city,
public string $state,
public string $country,
public string $zipCode,
public Money $price,
public string $currencySymbol,
) {}
}

View File

@@ -11,6 +11,7 @@ declare(strict_types=1);
namespace Singularity\HDK\Pay\Domain\Invoice\Aggregate\Invoice;
use Money\Money;
use Singularity\HDK\Pay\Domain\AggregateRoot;
final class Invoice extends AggregateRoot
@@ -22,8 +23,25 @@ final class Invoice extends AggregateRoot
private readonly Address $address,
private readonly bool $setFreqInvAddr,
private readonly string $receiver,
private readonly Money $price,
private readonly 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;

View File

@@ -11,12 +11,23 @@ declare(strict_types=1);
namespace Singularity\HDK\Pay\Domain\Invoice\Aggregate\Invoice;
use Singularity\HDK\Pay\Domain\Invoice\Aggregate\Invoice\ValueObject\PointPrice;
final readonly class InvoiceProduct {
/**
* @param string $caseId
* @param string $uid
* @param string $name
* @param string $sku
* @param string $description
* @param PointPrice[] $prices
*/
public function __construct(
public string $caseId,
public string $uid,
public string $name,
public string $sku,
public string $description,
public array $prices,
) {}
}

View File

@@ -0,0 +1,23 @@
<?php
/**
* PointPrice.php@Pay
*
* @author 李东云 <Dongyun.Li@LuxCreo.Ai>
* Powered by PhpStorm
* Created on 2025/11/25
*/
declare(strict_types=1);
namespace Singularity\HDK\Pay\Domain\Invoice\Aggregate\Invoice\ValueObject;
use Money\Money;
use Singularity\HDK\Pay\Domain\Account\Enum\PointType;
final readonly class PointPrice
{
public function __construct(
public Money $price,
public string $currencySymbol,
) {}
}

View File

@@ -12,7 +12,10 @@ declare(strict_types=1);
namespace Singularity\HDK\Pay\Infrastructure\Repository;
use Hyperf\Codec\Json;
use Money\Currency;
use Money\Money;
use Singularity\HDK\Pay\Domain\Invoice\Aggregate\Invoice\InvoiceProduct;
use Singularity\HDK\Pay\Domain\Invoice\Aggregate\Invoice\ValueObject\PointPrice;
use Singularity\HDK\Pay\Domain\Invoice\Repository\InvoiceProductRepoInterface;
final class InvoiceProductRepo extends AbstractRepo implements InvoiceProductRepoInterface
@@ -33,6 +36,16 @@ final class InvoiceProductRepo extends AbstractRepo implements InvoiceProductRep
name: $result['name'],
sku: $result['sku'],
description: $result['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['prices'],
),
);
}
}

View File

@@ -13,6 +13,8 @@ namespace Singularity\HDK\Pay\Infrastructure\Repository;
use Carbon\Carbon;
use Hyperf\Codec\Json;
use Money\Currency;
use Money\Money;
use Psr\Http\Message\ResponseInterface;
use Singularity\HDK\Core\Exceptions\ValidateException;
use Singularity\HDK\Pay\Application\Command\CreateInvoiceCmd;
@@ -30,6 +32,7 @@ final class InvoiceRepo extends AbstractRepo implements InvoiceRepoInterface
*/
public function create(CreateInvoiceCmd $cmd): Invoice
{
$money = $cmd->price;
$response = $this->requestService->requestPost(
url: "/rpc/v2/account/logs/points/$cmd->caseId/invoices",
data: [
@@ -41,12 +44,20 @@ final class InvoiceRepo extends AbstractRepo implements InvoiceRepoInterface
'state' => $cmd->state,
'country' => $cmd->country,
'zip' => $cmd->zipCode,
'price' => [
'amount' => (float)bcmul($money->getAmount(), '100', 2),
'currency' => [
'code' => $money->getCurrency()->getCode(),
'symbol' => $cmd->currencySymbol,
],
],
],
);
$content = $response->getBody()->getContents();
$result = Json::decode($content);
$price = $result['price'];
return new Invoice(
invoiceNo: $result['invoice_no'],
uid: $result['uid'],
@@ -61,6 +72,11 @@ final class InvoiceRepo extends AbstractRepo implements InvoiceRepoInterface
),
setFreqInvAddr: $result['set_freq_addr'],
receiver: $result['receiver'],
price: new Money(
bcmul((string)$price['amount'], '100', 2),
new Currency($price['code']),
),
currencySymbol: $price['symbol'],
);
}

View File

@@ -8,6 +8,7 @@
* Created on 2025/8/29
*/
use Money\Money;
use Psr\Http\Message\ResponseInterface;
use Singularity\HDK\Pay\Application\Command\CreateInvoiceCmd;
use Singularity\HDK\Pay\Domain\Invoice\Aggregate\Invoice\Invoice;
@@ -29,6 +30,8 @@ it('should can create invoice', function () {
state: "Illinois",
country: "United States",
zipCode: "67890-1234",
price: Money::EUR('19900'),
currencySymbol: '€'
),
);

View File

@@ -10,16 +10,20 @@
use Singularity\HDK\Pay\Domain\Invoice\Aggregate\Invoice\InvoiceProduct;
use Singularity\HDK\Pay\Domain\Invoice\Aggregate\Invoice\ValueObject\PointPrice;
use Singularity\HDK\Pay\Infrastructure\Repository\InvoiceProductRepo;
use function Hyperf\Support\make;
it('should can query case invoice product', function () {
/** @var InvoiceProductRepo $invoiceProductRepo */
$invoiceProductRepo = make(InvoiceProductRepo::class);
$caseId = '68affb136c01d';
$result = $invoiceProductRepo->getCaseProduct(caseId: $caseId);
expect($result)->toBeInstanceOf(InvoiceProduct::class);
expect($result)->toBeInstanceOf(InvoiceProduct::class)
->prices->toBeArray()
->each->toBeInstanceOf(PointPrice::class);
});

View File

@@ -23,7 +23,7 @@ it('can query point rate', function () {
$rate = $repo->getRate($from, $to, $uid);
expect($rate)->toBeFloat();
})->only();
});
it('can query point rate with uid', function () {
$repo = make(ProductRepo::class);
@@ -35,4 +35,4 @@ it('can query point rate with uid', function () {
$rate = $repo->getRate($from, $to, $uid);
expect($rate)->toBeFloat();
})->only();
});