mirror of
http://124.126.16.154:8888/singularity/hdk-pay.git
synced 2026-01-15 06:15:09 +08:00
feat(product): 增加 EMA 产品查询功能
- 移除了未使用的 ProductItem 引用 - 修改了 findEmaProduct 方法的参数,从 currentVersion 改为 uid - 更新了 findEmaProduct 方法的实现,使用 uid 参数进行查询 - 重构了 RechargeProduct 对象的构建方式,提高了代码可读性 - 更新了单元测试,增加了 EMA 产品查询的测试用例
This commit is contained in:
@@ -9,7 +9,6 @@
|
||||
|
||||
namespace Singularity\HDK\Pay\Domain\Product\Repository;
|
||||
|
||||
use Singularity\HDK\Pay\Domain\Product\Aggregate\Entities\ProductItem;
|
||||
use Singularity\HDK\Pay\Domain\Product\Aggregate\RechargeProduct;
|
||||
|
||||
interface RechargeProductRepoInterface
|
||||
@@ -20,20 +19,8 @@ interface RechargeProductRepoInterface
|
||||
public function findLuxPointProduct(): RechargeProduct;
|
||||
|
||||
/**
|
||||
* @param string $currentVersion
|
||||
* @param string $uid
|
||||
* @return RechargeProduct
|
||||
*/
|
||||
public function findEmaProduct(string $currentVersion): RechargeProduct;
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
* @return ProductItem
|
||||
*/
|
||||
public function findProductItem(int $id): ProductItem;
|
||||
|
||||
/**
|
||||
* @param int[] $idList
|
||||
* @return ProductItem[]
|
||||
*/
|
||||
public function selectProductList(array $idList): array;
|
||||
public function findEmaProduct(string $uid): RechargeProduct;
|
||||
}
|
||||
@@ -31,7 +31,7 @@ final class ProductRepo extends AbstractRepo implements RechargeProductRepoInter
|
||||
public function findLuxPointProduct(): RechargeProduct
|
||||
{
|
||||
$response = $this->requestService->requestGet(
|
||||
url: "/rpc/v2/products/lux-point",
|
||||
url: '/rpc/v2/products/lux-point',
|
||||
options: [
|
||||
'headers' => $this->headerBuilder(),
|
||||
],
|
||||
@@ -75,10 +75,11 @@ final class ProductRepo extends AbstractRepo implements RechargeProductRepoInter
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function findEmaProduct(string $currentVersion,
|
||||
): RechargeProduct {
|
||||
public function findEmaProduct(string $uid): RechargeProduct
|
||||
{
|
||||
$response = $this->requestService->requestGet(
|
||||
url: "/rpc/v2/products/ema",
|
||||
url: '/rpc/v2/products/ema',
|
||||
params: ['uid' => $uid],
|
||||
options: [
|
||||
'headers' => $this->headerBuilder(),
|
||||
],
|
||||
@@ -88,28 +89,55 @@ final class ProductRepo extends AbstractRepo implements RechargeProductRepoInter
|
||||
$result = Json::decode($content);
|
||||
|
||||
return new RechargeProduct(
|
||||
oneTime: $result['one_time'],
|
||||
renew: $result['renew'],
|
||||
plans: $result['plan'],
|
||||
oneTime: isset($result['one_time'])
|
||||
? new ProductItem(
|
||||
id: $result['one_time']['id'],
|
||||
description: $result['one_time']['name'],
|
||||
unitPrice: new Money(
|
||||
amount: $result['one_time']['price'],
|
||||
currency: new Currency($result['one_time']['currency']),
|
||||
),
|
||||
productType: ProductType::oneTime,
|
||||
effect: new RechargeEffect(
|
||||
pointType: PointType::EMA,
|
||||
pointBasic: $result['one_time']['point']['number'],
|
||||
pointBonus: $result['one_time']['point']['bonus'],
|
||||
),
|
||||
)
|
||||
: null,
|
||||
renew: isset($result['renew'])
|
||||
? new ProductItem(
|
||||
id: $result['renew']['id'],
|
||||
description: $result['renew']['name'],
|
||||
unitPrice: new Money(
|
||||
amount: $result['renew']['price'],
|
||||
currency: new Currency($result['renew']['currency']),
|
||||
),
|
||||
productType: ProductType::renew,
|
||||
effect: new RechargeEffect(
|
||||
pointType: PointType::EMA,
|
||||
pointBasic: $result['renew']['point']['number'],
|
||||
pointBonus: $result['renew']['point']['bonus'],
|
||||
),
|
||||
)
|
||||
: null,
|
||||
plans: array_map(fn(array $item) => new ProductItem(
|
||||
id: $item['id'],
|
||||
description: $item['name'],
|
||||
unitPrice: new Money(
|
||||
amount: $item['price'],
|
||||
currency: new Currency($item['currency']),
|
||||
),
|
||||
productType: ProductType::plan,
|
||||
effect: new RechargeEffect(
|
||||
pointType: PointType::LuxPoint,
|
||||
pointBasic: $item['point']['number'],
|
||||
pointBonus: $item['point']['bonus'],
|
||||
),
|
||||
), $result['plan']),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function findProductItem(int $id): ProductItem
|
||||
{
|
||||
// TODO: Implement findProductItem() method.
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function selectProductList(array $idList): array
|
||||
{
|
||||
// TODO: Implement selectProductList() method.
|
||||
}
|
||||
|
||||
/**
|
||||
* @param PointType $source
|
||||
* @param PointType $target
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
* Created on 2025/8/18
|
||||
*/
|
||||
|
||||
use Pest\Expectation;
|
||||
use Singularity\HDK\Pay\Domain\Product\Aggregate\Entities\ProductItem;
|
||||
use Singularity\HDK\Pay\Domain\Product\Aggregate\RechargeProduct;
|
||||
use Singularity\HDK\Pay\Infrastructure\Repository\ProductRepo;
|
||||
@@ -18,9 +19,28 @@ it('should can query LuxPoint products', function () {
|
||||
$repo = make(ProductRepo::class);
|
||||
|
||||
$products = $repo->findLuxPointProduct();
|
||||
var_dump($products);
|
||||
expect($products)
|
||||
->toBeInstanceOf(RechargeProduct::class)
|
||||
->and($products->getOneTime())->toBeInstanceOf(ProductItem::class)
|
||||
->and($products->getPackages())->each->toBeInstanceOf(ProductItem::class);
|
||||
});
|
||||
|
||||
it('should can query EMA products', function () {
|
||||
$repo = make(ProductRepo::class);
|
||||
|
||||
$uid = 'cn3321';
|
||||
$products = $repo->findEmaProduct($uid);
|
||||
expect($products)
|
||||
->toBeInstanceOf(RechargeProduct::class)
|
||||
->when(
|
||||
$products->getOneTime() !== null,
|
||||
fn(Expectation $expectation) => $expectation
|
||||
->and($products->getOneTime())->toBeInstanceOf(ProductItem::class),
|
||||
)
|
||||
->when(
|
||||
$products->getRenew() !== null,
|
||||
fn(Expectation $expectation) => $expectation
|
||||
->and($products->getRenew())->toBeInstanceOf(ProductItem::class),
|
||||
)
|
||||
->and($products->getPlans())->each->toBeInstanceOf(ProductItem::class);
|
||||
})->only();
|
||||
|
||||
Reference in New Issue
Block a user