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'],
|
id: $result['one_time']['id'],
|
||||||
description: $result['one_time']['name'],
|
description: $result['one_time']['name'],
|
||||||
unitPrice: new Money(
|
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']),
|
currency: new Currency($result['one_time']['currency']),
|
||||||
),
|
),
|
||||||
productType: ProductType::oneTime,
|
productType: ProductType::oneTime,
|
||||||
@@ -55,20 +55,23 @@ final class ProductRepo extends AbstractRepo implements RechargeProductRepoInter
|
|||||||
pointBonus: $result['one_time']['point']['bonus'],
|
pointBonus: $result['one_time']['point']['bonus'],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
packages: array_map(fn(array $item) => new ProductItem(
|
packages: array_map(
|
||||||
id: $item['id'],
|
fn(array $item) => new ProductItem(
|
||||||
description: $item['name'],
|
id: $item['id'],
|
||||||
unitPrice: new Money(
|
description: $item['name'],
|
||||||
amount: bcmul((string)$item['price'], '100'),
|
unitPrice: new Money(
|
||||||
currency: new Currency($item['currency']),
|
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,
|
$result['package'] ?? [],
|
||||||
effect: new RechargeEffect(
|
),
|
||||||
pointType: PointType::LuxPoint,
|
|
||||||
pointBasic: $item['point']['number'],
|
|
||||||
pointBonus: $item['point']['bonus'],
|
|
||||||
),
|
|
||||||
), $result['package']),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -99,29 +102,35 @@ final class ProductRepo extends AbstractRepo implements RechargeProductRepoInter
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
: null,
|
: null,
|
||||||
plans: array_map(fn(array $item) => new ProductItem(
|
plans: array_map(
|
||||||
id: $item['id'],
|
fn(array $item) => new ProductItem(
|
||||||
description: $item['name'],
|
id: $item['id'],
|
||||||
unitPrice: new Money(
|
description: $item['name'],
|
||||||
amount: bcmul((string)$item['price'], '100'),
|
unitPrice: new Money(
|
||||||
currency: new Currency($item['currency']),
|
amount: bcmul((string)$item['price'], '100'),
|
||||||
|
currency: new Currency($item['currency']),
|
||||||
|
),
|
||||||
|
productType: ProductType::plan,
|
||||||
),
|
),
|
||||||
productType: ProductType::plan,
|
$result['plan'] ?? [],
|
||||||
), $result['plan']),
|
),
|
||||||
packages: array_map(fn(array $item) => new ProductItem(
|
packages: array_map(
|
||||||
id: $item['id'],
|
fn(array $item) => new ProductItem(
|
||||||
description: $item['name'],
|
id: $item['id'],
|
||||||
unitPrice: new Money(
|
description: $item['name'],
|
||||||
amount: bcmul((string)$item['price'], '100'),
|
unitPrice: new Money(
|
||||||
currency: new Currency($item['currency']),
|
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,
|
$result['package'] ?? [],
|
||||||
effect: new RechargeEffect(
|
),
|
||||||
pointType: $pointType,
|
|
||||||
pointBasic: $item['point']['number'],
|
|
||||||
pointBonus: $item['point']['bonus'],
|
|
||||||
),
|
|
||||||
), $result['package']),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -144,7 +153,7 @@ final class ProductRepo extends AbstractRepo implements RechargeProductRepoInter
|
|||||||
id: $result['one_time']['id'],
|
id: $result['one_time']['id'],
|
||||||
description: $result['one_time']['name'],
|
description: $result['one_time']['name'],
|
||||||
unitPrice: new Money(
|
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']),
|
currency: new Currency($result['one_time']['currency']),
|
||||||
),
|
),
|
||||||
productType: ProductType::oneTime,
|
productType: ProductType::oneTime,
|
||||||
@@ -171,20 +180,23 @@ final class ProductRepo extends AbstractRepo implements RechargeProductRepoInter
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
: null,
|
: null,
|
||||||
plans: array_map(fn(array $item) => new ProductItem(
|
plans: array_map(
|
||||||
id: $item['id'],
|
fn(array $item) => new ProductItem(
|
||||||
description: $item['name'],
|
id: $item['id'],
|
||||||
unitPrice: new Money(
|
description: $item['name'],
|
||||||
amount: bcmul((string)$item['price'], '100'),
|
unitPrice: new Money(
|
||||||
currency: new Currency($item['currency']),
|
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,
|
$result['plan'] ?? [],
|
||||||
effect: new RechargeEffect(
|
),
|
||||||
pointType: PointType::EMA,
|
|
||||||
pointBasic: $item['point']['number'],
|
|
||||||
pointBonus: $item['point']['bonus'],
|
|
||||||
),
|
|
||||||
), $result['plan']),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user