mirror of
http://124.126.16.154:8888/singularity/hdk-pay.git
synced 2026-01-15 05:55:08 +08:00
fix(ProductRepo): 修复产品仓库中的数组为空的处理逻辑
- 优化了 one_time、package 和 plan 数据的处理方式 - 使用 array_map 函数替代循环,提高代码可读性 - 增加空值合并运算符 ??,提高代码健壮性 -调整代码格式,提高代码整洁度
This commit is contained in:
@@ -45,7 +45,7 @@ final class ProductRepo extends AbstractRepo implements RechargeProductRepoInter
|
||||
id: $result['one_time']['id'],
|
||||
description: $result['one_time']['name'],
|
||||
unitPrice: new Money(
|
||||
amount:bcmul((string)$result['one_time']['price'], '100'),
|
||||
amount: bcmul((string)$result['one_time']['price'], '100'),
|
||||
currency: new Currency($result['one_time']['currency']),
|
||||
),
|
||||
productType: ProductType::oneTime,
|
||||
@@ -55,20 +55,23 @@ final class ProductRepo extends AbstractRepo implements RechargeProductRepoInter
|
||||
pointBonus: $result['one_time']['point']['bonus'],
|
||||
),
|
||||
),
|
||||
packages: array_map(fn(array $item) => new ProductItem(
|
||||
id: $item['id'],
|
||||
description: $item['name'],
|
||||
unitPrice: new Money(
|
||||
amount: bcmul((string)$item['price'], '100'),
|
||||
currency: new Currency($item['currency']),
|
||||
packages: array_map(
|
||||
fn(array $item) => new ProductItem(
|
||||
id: $item['id'],
|
||||
description: $item['name'],
|
||||
unitPrice: new Money(
|
||||
amount: bcmul((string)$item['price'], '100'),
|
||||
currency: new Currency($item['currency']),
|
||||
),
|
||||
productType: ProductType::pack,
|
||||
effect: new RechargeEffect(
|
||||
pointType: PointType::LuxPoint,
|
||||
pointBasic: $item['point']['number'],
|
||||
pointBonus: $item['point']['bonus'],
|
||||
),
|
||||
),
|
||||
productType: ProductType::pack,
|
||||
effect: new RechargeEffect(
|
||||
pointType: PointType::LuxPoint,
|
||||
pointBasic: $item['point']['number'],
|
||||
pointBonus: $item['point']['bonus'],
|
||||
),
|
||||
), $result['package']),
|
||||
$result['package'] ?? [],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -99,29 +102,35 @@ final class ProductRepo extends AbstractRepo implements RechargeProductRepoInter
|
||||
),
|
||||
)
|
||||
: null,
|
||||
plans: array_map(fn(array $item) => new ProductItem(
|
||||
id: $item['id'],
|
||||
description: $item['name'],
|
||||
unitPrice: new Money(
|
||||
amount: bcmul((string)$item['price'], '100'),
|
||||
currency: new Currency($item['currency']),
|
||||
plans: array_map(
|
||||
fn(array $item) => new ProductItem(
|
||||
id: $item['id'],
|
||||
description: $item['name'],
|
||||
unitPrice: new Money(
|
||||
amount: bcmul((string)$item['price'], '100'),
|
||||
currency: new Currency($item['currency']),
|
||||
),
|
||||
productType: ProductType::plan,
|
||||
),
|
||||
productType: ProductType::plan,
|
||||
), $result['plan']),
|
||||
packages: array_map(fn(array $item) => new ProductItem(
|
||||
id: $item['id'],
|
||||
description: $item['name'],
|
||||
unitPrice: new Money(
|
||||
amount: bcmul((string)$item['price'], '100'),
|
||||
currency: new Currency($item['currency']),
|
||||
$result['plan'] ?? [],
|
||||
),
|
||||
packages: array_map(
|
||||
fn(array $item) => new ProductItem(
|
||||
id: $item['id'],
|
||||
description: $item['name'],
|
||||
unitPrice: new Money(
|
||||
amount: bcmul((string)$item['price'], '100'),
|
||||
currency: new Currency($item['currency']),
|
||||
),
|
||||
productType: ProductType::plan,
|
||||
effect: new RechargeEffect(
|
||||
pointType: $pointType,
|
||||
pointBasic: $item['point']['number'],
|
||||
pointBonus: $item['point']['bonus'],
|
||||
),
|
||||
),
|
||||
productType: ProductType::plan,
|
||||
effect: new RechargeEffect(
|
||||
pointType: $pointType,
|
||||
pointBasic: $item['point']['number'],
|
||||
pointBonus: $item['point']['bonus'],
|
||||
),
|
||||
), $result['package']),
|
||||
$result['package'] ?? [],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -144,7 +153,7 @@ final class ProductRepo extends AbstractRepo implements RechargeProductRepoInter
|
||||
id: $result['one_time']['id'],
|
||||
description: $result['one_time']['name'],
|
||||
unitPrice: new Money(
|
||||
amount:bcmul((string)$result['one_time']['price'], '100'),
|
||||
amount: bcmul((string)$result['one_time']['price'], '100'),
|
||||
currency: new Currency($result['one_time']['currency']),
|
||||
),
|
||||
productType: ProductType::oneTime,
|
||||
@@ -171,20 +180,23 @@ final class ProductRepo extends AbstractRepo implements RechargeProductRepoInter
|
||||
),
|
||||
)
|
||||
: null,
|
||||
plans: array_map(fn(array $item) => new ProductItem(
|
||||
id: $item['id'],
|
||||
description: $item['name'],
|
||||
unitPrice: new Money(
|
||||
amount: bcmul((string)$item['price'], '100'),
|
||||
currency: new Currency($item['currency']),
|
||||
plans: array_map(
|
||||
fn(array $item) => new ProductItem(
|
||||
id: $item['id'],
|
||||
description: $item['name'],
|
||||
unitPrice: new Money(
|
||||
amount: bcmul((string)$item['price'], '100'),
|
||||
currency: new Currency($item['currency']),
|
||||
),
|
||||
productType: ProductType::plan,
|
||||
effect: new RechargeEffect(
|
||||
pointType: PointType::EMA,
|
||||
pointBasic: $item['point']['number'],
|
||||
pointBonus: $item['point']['bonus'],
|
||||
),
|
||||
),
|
||||
productType: ProductType::plan,
|
||||
effect: new RechargeEffect(
|
||||
pointType: PointType::EMA,
|
||||
pointBasic: $item['point']['number'],
|
||||
pointBonus: $item['point']['bonus'],
|
||||
),
|
||||
), $result['plan']),
|
||||
$result['plan'] ?? [],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user