feat(pay): 添加产品类型枚举和兑换率接口

- 新增 ProductType 枚举类,用于定义产品类型
- 添加 ExchangeRepoInterface 接口,用于获取兑换率
- 实现 QueryPointRateTest 测试用例,验证兑换率查询功能
This commit is contained in:
李东云
2025-08-18 15:33:13 +08:00
parent 1bb8666b5e
commit a2fc4cecf8
3 changed files with 87 additions and 0 deletions

View File

@@ -0,0 +1,41 @@
<?php
/**
* ProductType.php@LuxPay
*
* @author 李东云 <Dongyun.Li@LuxCreo.Ai>
* Powered by PhpStorm
* Created on 2025/8/5
*/
namespace Singularity\HDK\Pay\Domain\Product\Enum;
enum ProductType {
case plan;
case pack;
case oneTime;
case renew;
public static function tryFrom(string $type): ?ProductType
{
return match ($type) {
'plan' => self::plan,
'pack' => self::pack,
'oneTime' => self::oneTime,
'renew' => self::renew,
default => null,
};
}
public static function names(): array
{
$result = [];
foreach (self::cases() as $case) {
$result[] = $case->name;
}
return $result;
}
}

View File

@@ -0,0 +1,22 @@
<?php
/**
* ExchangeRepoInterface.php@LuxDesign
*
* @author 李东云 <Dongyun.Li@LuxCreo.Ai>
* Powered by PhpStorm
* Created on 2025/7/29
*/
namespace Singularity\HDK\Pay\Domain\Product\Repository;
use Singularity\HDK\Pay\Domain\Account\Enum\PointType;
interface ExchangeRepoInterface
{
/**
* @param PointType $source
* @param PointType $target
* @return float
*/
public function getRate(PointType $source, PointType $target): float;
}

View File

@@ -0,0 +1,24 @@
<?php
/**
* QueryPointRateTest.php@Pay
*
* @author 李东云 <Dongyun.Li@LuxCreo.Ai>
* Powered by PhpStorm
* Created on 2025/8/18
*/
use Singularity\HDK\Pay\Domain\Account\Enum\PointType;
use Singularity\HDK\Pay\Infrastructure\Repository\ProductRepo;
use function Hyperf\Support\make;
it('can query point rate', function () {
$repo = make(ProductRepo::class);
$from = PointType::FtaiAligner;
$to = PointType::LuxPoint;
$rate = $repo->getRate($from, $to);
expect($rate)->toBeFloat();
})->only();