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