mirror of
http://124.126.16.154:8888/singularity/hdk-pay.git
synced 2026-01-15 05:55:08 +08:00
feat(invoice): 引入点数价格值对象并更新发票产品结构
- 新增 PointPrice 值对象用于表示金额与货币符号 - 修改 InvoiceProduct 结构以支持多个 PointPrice 实例 - 更新 InvoiceProductRepo 以映射数据库中的价格数据 - 在测试中验证 prices 字段的正确性和类型安全
This commit is contained in:
@@ -11,12 +11,23 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace Singularity\HDK\Pay\Domain\Invoice\Aggregate\Invoice;
|
namespace Singularity\HDK\Pay\Domain\Invoice\Aggregate\Invoice;
|
||||||
|
|
||||||
|
use Singularity\HDK\Pay\Domain\Invoice\Aggregate\Invoice\ValueObject\PointPrice;
|
||||||
|
|
||||||
final readonly class InvoiceProduct {
|
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 function __construct(
|
||||||
public string $caseId,
|
public string $caseId,
|
||||||
public string $uid,
|
public string $uid,
|
||||||
public string $name,
|
public string $name,
|
||||||
public string $sku,
|
public string $sku,
|
||||||
public string $description,
|
public string $description,
|
||||||
|
public array $prices,
|
||||||
) {}
|
) {}
|
||||||
}
|
}
|
||||||
@@ -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,
|
||||||
|
) {}
|
||||||
|
}
|
||||||
@@ -12,7 +12,10 @@ declare(strict_types=1);
|
|||||||
namespace Singularity\HDK\Pay\Infrastructure\Repository;
|
namespace Singularity\HDK\Pay\Infrastructure\Repository;
|
||||||
|
|
||||||
use Hyperf\Codec\Json;
|
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\InvoiceProduct;
|
||||||
|
use Singularity\HDK\Pay\Domain\Invoice\Aggregate\Invoice\ValueObject\PointPrice;
|
||||||
use Singularity\HDK\Pay\Domain\Invoice\Repository\InvoiceProductRepoInterface;
|
use Singularity\HDK\Pay\Domain\Invoice\Repository\InvoiceProductRepoInterface;
|
||||||
|
|
||||||
final class InvoiceProductRepo extends AbstractRepo implements InvoiceProductRepoInterface
|
final class InvoiceProductRepo extends AbstractRepo implements InvoiceProductRepoInterface
|
||||||
@@ -33,6 +36,16 @@ final class InvoiceProductRepo extends AbstractRepo implements InvoiceProductRep
|
|||||||
name: $result['name'],
|
name: $result['name'],
|
||||||
sku: $result['sku'],
|
sku: $result['sku'],
|
||||||
description: $result['description'],
|
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'],
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -10,16 +10,20 @@
|
|||||||
|
|
||||||
|
|
||||||
use Singularity\HDK\Pay\Domain\Invoice\Aggregate\Invoice\InvoiceProduct;
|
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 Singularity\HDK\Pay\Infrastructure\Repository\InvoiceProductRepo;
|
||||||
|
|
||||||
use function Hyperf\Support\make;
|
use function Hyperf\Support\make;
|
||||||
|
|
||||||
it('should can query case invoice product', function () {
|
it('should can query case invoice product', function () {
|
||||||
|
/** @var InvoiceProductRepo $invoiceProductRepo */
|
||||||
$invoiceProductRepo = make(InvoiceProductRepo::class);
|
$invoiceProductRepo = make(InvoiceProductRepo::class);
|
||||||
|
|
||||||
$caseId = '68affb136c01d';
|
$caseId = '68affb136c01d';
|
||||||
|
|
||||||
$result = $invoiceProductRepo->getCaseProduct(caseId: $caseId);
|
$result = $invoiceProductRepo->getCaseProduct(caseId: $caseId);
|
||||||
|
|
||||||
expect($result)->toBeInstanceOf(InvoiceProduct::class);
|
expect($result)->toBeInstanceOf(InvoiceProduct::class)
|
||||||
|
->prices->toBeArray()
|
||||||
|
->each->toBeInstanceOf(PointPrice::class);
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user