mirror of
http://124.126.16.154:8888/singularity/hdk-pay.git
synced 2026-01-15 05:35:08 +08:00
feat(pay): 添加产品类型枚举和兑换率接口
- 新增 ProductType 枚举类,用于定义产品类型 - 添加 ExchangeRepoInterface 接口,用于获取兑换率 - 实现 QueryPointRateTest 测试用例,验证兑换率查询功能
This commit is contained in:
41
src/Domain/Product/Enum/ProductType.php
Normal file
41
src/Domain/Product/Enum/ProductType.php
Normal 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;
|
||||
}
|
||||
|
||||
}
|
||||
22
src/Domain/Product/Repository/ExchangeRepoInterface.php
Normal file
22
src/Domain/Product/Repository/ExchangeRepoInterface.php
Normal 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;
|
||||
}
|
||||
24
tests/Feature/Product/QueryPointRateTest.php
Normal file
24
tests/Feature/Product/QueryPointRateTest.php
Normal 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();
|
||||
Reference in New Issue
Block a user