From 4c5dde9020364573d0e9673138620d967149e9f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E4=B8=9C=E4=BA=91?= Date: Tue, 25 Nov 2025 16:01:25 +0800 Subject: [PATCH] =?UTF-8?q?feat(invoice):=20=E5=BC=95=E5=85=A5=E7=82=B9?= =?UTF-8?q?=E6=95=B0=E4=BB=B7=E6=A0=BC=E5=80=BC=E5=AF=B9=E8=B1=A1=E5=B9=B6?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=E5=8F=91=E7=A5=A8=E4=BA=A7=E5=93=81=E7=BB=93?= =?UTF-8?q?=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增 PointPrice 值对象用于表示金额与货币符号 - 修改 InvoiceProduct 结构以支持多个 PointPrice 实例 - 更新 InvoiceProductRepo 以映射数据库中的价格数据 - 在测试中验证 prices 字段的正确性和类型安全 --- .../Aggregate/Invoice/InvoiceProduct.php | 11 +++++++++ .../Invoice/ValueObject/PointPrice.php | 23 +++++++++++++++++++ .../Repository/InvoiceProductRepo.php | 13 +++++++++++ .../Invoice/QueryCaseInvoiceProductTest.php | 6 ++++- 4 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 src/Domain/Invoice/Aggregate/Invoice/ValueObject/PointPrice.php diff --git a/src/Domain/Invoice/Aggregate/Invoice/InvoiceProduct.php b/src/Domain/Invoice/Aggregate/Invoice/InvoiceProduct.php index 4409dbf..2a3c552 100644 --- a/src/Domain/Invoice/Aggregate/Invoice/InvoiceProduct.php +++ b/src/Domain/Invoice/Aggregate/Invoice/InvoiceProduct.php @@ -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, ) {} } \ No newline at end of file diff --git a/src/Domain/Invoice/Aggregate/Invoice/ValueObject/PointPrice.php b/src/Domain/Invoice/Aggregate/Invoice/ValueObject/PointPrice.php new file mode 100644 index 0000000..7c19c7b --- /dev/null +++ b/src/Domain/Invoice/Aggregate/Invoice/ValueObject/PointPrice.php @@ -0,0 +1,23 @@ + + * 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, + ) {} +} \ No newline at end of file diff --git a/src/Infrastructure/Repository/InvoiceProductRepo.php b/src/Infrastructure/Repository/InvoiceProductRepo.php index 682025e..9f4dd1e 100644 --- a/src/Infrastructure/Repository/InvoiceProductRepo.php +++ b/src/Infrastructure/Repository/InvoiceProductRepo.php @@ -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'], + ), ); } } \ No newline at end of file diff --git a/tests/Feature/Invoice/QueryCaseInvoiceProductTest.php b/tests/Feature/Invoice/QueryCaseInvoiceProductTest.php index 08df7ca..a7b4edd 100644 --- a/tests/Feature/Invoice/QueryCaseInvoiceProductTest.php +++ b/tests/Feature/Invoice/QueryCaseInvoiceProductTest.php @@ -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); });