mirror of
http://124.126.16.154:8888/singularity/hdk-pay.git
synced 2026-01-15 03:55:07 +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,7 +55,8 @@ final class ProductRepo extends AbstractRepo implements RechargeProductRepoInter
|
||||
pointBonus: $result['one_time']['point']['bonus'],
|
||||
),
|
||||
),
|
||||
packages: array_map(fn(array $item) => new ProductItem(
|
||||
packages: array_map(
|
||||
fn(array $item) => new ProductItem(
|
||||
id: $item['id'],
|
||||
description: $item['name'],
|
||||
unitPrice: new Money(
|
||||
@@ -68,7 +69,9 @@ final class ProductRepo extends AbstractRepo implements RechargeProductRepoInter
|
||||
pointBasic: $item['point']['number'],
|
||||
pointBonus: $item['point']['bonus'],
|
||||
),
|
||||
), $result['package']),
|
||||
),
|
||||
$result['package'] ?? [],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -99,7 +102,8 @@ final class ProductRepo extends AbstractRepo implements RechargeProductRepoInter
|
||||
),
|
||||
)
|
||||
: null,
|
||||
plans: array_map(fn(array $item) => new ProductItem(
|
||||
plans: array_map(
|
||||
fn(array $item) => new ProductItem(
|
||||
id: $item['id'],
|
||||
description: $item['name'],
|
||||
unitPrice: new Money(
|
||||
@@ -107,8 +111,11 @@ final class ProductRepo extends AbstractRepo implements RechargeProductRepoInter
|
||||
currency: new Currency($item['currency']),
|
||||
),
|
||||
productType: ProductType::plan,
|
||||
), $result['plan']),
|
||||
packages: array_map(fn(array $item) => new ProductItem(
|
||||
),
|
||||
$result['plan'] ?? [],
|
||||
),
|
||||
packages: array_map(
|
||||
fn(array $item) => new ProductItem(
|
||||
id: $item['id'],
|
||||
description: $item['name'],
|
||||
unitPrice: new Money(
|
||||
@@ -121,7 +128,9 @@ final class ProductRepo extends AbstractRepo implements RechargeProductRepoInter
|
||||
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,7 +180,8 @@ final class ProductRepo extends AbstractRepo implements RechargeProductRepoInter
|
||||
),
|
||||
)
|
||||
: null,
|
||||
plans: array_map(fn(array $item) => new ProductItem(
|
||||
plans: array_map(
|
||||
fn(array $item) => new ProductItem(
|
||||
id: $item['id'],
|
||||
description: $item['name'],
|
||||
unitPrice: new Money(
|
||||
@@ -184,7 +194,9 @@ final class ProductRepo extends AbstractRepo implements RechargeProductRepoInter
|
||||
pointBasic: $item['point']['number'],
|
||||
pointBonus: $item['point']['bonus'],
|
||||
),
|
||||
), $result['plan']),
|
||||
),
|
||||
$result['plan'] ?? [],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user