mirror of
http://124.126.16.154:8888/singularity/hdk-pay.git
synced 2026-01-15 07:15:06 +08:00
Compare commits
14 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7e0d711e99 | ||
|
|
eb44b6e3b6 | ||
|
|
3af39e4254 | ||
|
|
8bbc8ed629 | ||
|
|
48e6fafe8e | ||
|
|
874a6f4fa9 | ||
|
|
8ac850fc62 | ||
|
|
8f8f7b08b0 | ||
|
|
203dd34353 | ||
|
|
87b09ef34c | ||
|
|
a59d979076 | ||
|
|
686d835a91 | ||
|
|
65b060e5d3 | ||
|
|
3b12216344 |
49
CHANGELOG.md
49
CHANGELOG.md
@@ -1,4 +1,53 @@
|
||||
# 版本更新日志
|
||||
### [1.9.4](http://124.126.16.154:8888/singularity/hdk-pay/compare/v1.9.3...v1.9.4) (2025-09-19)
|
||||
|
||||
|
||||
### 🐛 Bug Fixes | Bug 修复
|
||||
|
||||
* **product:** 修复产品列表中点数显示问题 ([eb44b6e](http://124.126.16.154:8888/singularity/hdk-pay/commit/eb44b6e3b6e9a2e3f757076d0d4438163e7d1f51))
|
||||
|
||||
### [1.9.3](http://124.126.16.154:8888/singularity/hdk-pay/compare/v1.9.2...v1.9.3) (2025-09-19)
|
||||
|
||||
|
||||
### ✨ Features | 新功能
|
||||
|
||||
* **PointType:** 添加 ScanToModel 作为点类型 ([8bbc8ed](http://124.126.16.154:8888/singularity/hdk-pay/commit/8bbc8ed629e5c15e42db0adf758505e531ff3dca))
|
||||
|
||||
### [1.9.2](http://124.126.16.154:8888/singularity/hdk-pay/compare/v1.9.1...v1.9.2) (2025-09-19)
|
||||
|
||||
|
||||
### ✨ Features | 新功能
|
||||
|
||||
* **Account:** 添加新的积分类型 ([874a6f4](http://124.126.16.154:8888/singularity/hdk-pay/commit/874a6f4fa96b09a4c6c652b6d285d4b6631a3c66))
|
||||
|
||||
### [1.9.1](http://124.126.16.154:8888/singularity/hdk-pay/compare/v1.9.0...v1.9.1) (2025-09-17)
|
||||
|
||||
|
||||
### 🐛 Bug Fixes | Bug 修复
|
||||
|
||||
* **account:** 修复初始账户命令和测试 ([8f8f7b0](http://124.126.16.154:8888/singularity/hdk-pay/commit/8f8f7b08b03d9b810bb09ce4b1f15a27cbd43e68))
|
||||
|
||||
## [1.9.0](http://124.126.16.154:8888/singularity/hdk-pay/compare/v1.8.2...v1.9.0) (2025-09-17)
|
||||
|
||||
|
||||
### ✨ Features | 新功能
|
||||
|
||||
* **account:** 添加初始化账户余额功能 ([87b09ef](http://124.126.16.154:8888/singularity/hdk-pay/commit/87b09ef34cd3427816ef2c357406a74975ada8a9))
|
||||
|
||||
### [1.8.2](http://124.126.16.154:8888/singularity/hdk-pay/compare/v1.8.1...v1.8.2) (2025-09-17)
|
||||
|
||||
|
||||
### 🐛 Bug Fixes | Bug 修复
|
||||
|
||||
* **ProductRepo:** 修复产品仓库中的数组为空的处理逻辑 ([686d835](http://124.126.16.154:8888/singularity/hdk-pay/commit/686d835a9130d60768eef37a3c9a67c6526cb418))
|
||||
|
||||
### [1.8.1](http://124.126.16.154:8888/singularity/hdk-pay/compare/v1.8.0...v1.8.1) (2025-09-05)
|
||||
|
||||
|
||||
### ✨ Features | 新功能
|
||||
|
||||
* **PointLog:** 添加获取病人姓名的方法并更新相关代码 ([3b12216](http://124.126.16.154:8888/singularity/hdk-pay/commit/3b1221634419f0ca39359e36c0363602b075b9b8))
|
||||
|
||||
## [1.8.0](http://124.126.16.154:8888/singularity/hdk-pay/compare/v1.7.0...v1.8.0) (2025-09-05)
|
||||
|
||||
|
||||
|
||||
@@ -70,5 +70,5 @@
|
||||
"url": "https://mirrors.aliyun.com/composer/"
|
||||
}
|
||||
},
|
||||
"version": "1.8.0"
|
||||
"version": "1.9.4"
|
||||
}
|
||||
|
||||
40
src/Application/Command/InitialAccountCmd.php
Normal file
40
src/Application/Command/InitialAccountCmd.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* InitialAccountCmd.php@Pay
|
||||
*
|
||||
* @author 李东云 <Dongyun.Li@LuxCreo.Ai>
|
||||
* Powered by PhpStorm
|
||||
* Created on 2025/9/17
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Singularity\HDK\Pay\Application\Command;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Singularity\HDK\Pay\Domain\Account\Enum\PointType;
|
||||
|
||||
final class InitialAccountCmd
|
||||
{
|
||||
public array $pointsBalances;
|
||||
|
||||
public function __construct(
|
||||
public readonly string $uid,
|
||||
) {}
|
||||
|
||||
public function addPointsBalance(
|
||||
PointType $type,
|
||||
float $basic = 0.0,
|
||||
float $bonus = 0.0,
|
||||
?Carbon $expiredAt = null,
|
||||
?string $version = null,
|
||||
): array {
|
||||
return $this->pointsBalances[] = [
|
||||
'type' => $type->value,
|
||||
'basic' => $basic,
|
||||
'bonus' => $bonus,
|
||||
'expired_at' => $expiredAt->toDateTimeString(),
|
||||
'version' => $version,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -54,17 +54,19 @@ final class RechargeProductsDto extends AbstractDto
|
||||
if (!$is_ftai) {
|
||||
$result += [
|
||||
'total_points' => $effect->getPointTotal(),
|
||||
'bonus_rate_pct' => (float)(bcmul(
|
||||
num1: $effect->getPointTotal() == 0
|
||||
? '0'
|
||||
: bcdiv(
|
||||
(string)$effect->pointBonus,
|
||||
(string)$effect->getPointTotal(),
|
||||
3,
|
||||
),
|
||||
num2: '100',
|
||||
scale: 0,
|
||||
)),
|
||||
'bonus_rate_pct' => round(
|
||||
(float)(bcmul(
|
||||
num1: $effect->getPointTotal() == 0
|
||||
? '0'
|
||||
: bcdiv(
|
||||
(string)$effect->pointBonus,
|
||||
(string)$effect->getPointTotal(),
|
||||
3,
|
||||
),
|
||||
num2: '100',
|
||||
scale: 3,
|
||||
)),
|
||||
),
|
||||
'point' => [
|
||||
'total' => $effect->getPointTotal(),
|
||||
'number' => $effect->pointBasic,
|
||||
|
||||
@@ -25,11 +25,17 @@ final class PointLog extends AggregateRoot
|
||||
private readonly string $source,
|
||||
private readonly string $operator,
|
||||
private readonly string $description,
|
||||
private readonly string $patientName,
|
||||
private readonly Carbon $date,
|
||||
private readonly bool $invoiceable,
|
||||
private readonly ?InvoiceRecord $invoiceRecord,
|
||||
) {}
|
||||
|
||||
public function getPatientName(): string
|
||||
{
|
||||
return $this->patientName;
|
||||
}
|
||||
|
||||
public function getDescription(): string
|
||||
{
|
||||
return $this->description;
|
||||
|
||||
@@ -16,11 +16,15 @@ enum PointType: string
|
||||
case EMA = 'ema';
|
||||
|
||||
case FtaiAligner = 'aligner';
|
||||
|
||||
case FtaiRetainer = 'retainer';
|
||||
|
||||
case Aligner4D = 'aligner-4d';
|
||||
|
||||
case NightguardAi = 'nightguard-ai';
|
||||
|
||||
case ScanToModel = 'scan-to-model';
|
||||
|
||||
public static function values(): array
|
||||
{
|
||||
return [
|
||||
@@ -30,6 +34,7 @@ enum PointType: string
|
||||
self::FtaiRetainer->value,
|
||||
self::Aligner4D->value,
|
||||
self::NightguardAi->value,
|
||||
self::ScanToModel->value
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,13 +11,29 @@ declare(strict_types=1);
|
||||
|
||||
namespace Singularity\HDK\Pay\Domain\Account\Repository;
|
||||
|
||||
use Singularity\HDK\Pay\Application\Command\InitialAccountCmd;
|
||||
use Singularity\HDK\Pay\Domain\Account\Aggregate\Account\AccountBalance;
|
||||
use Singularity\HDK\Pay\Domain\Account\Aggregate\Account\PointsBalance;
|
||||
use Singularity\HDK\Pay\Domain\Account\Enum\PointType;
|
||||
|
||||
interface AccountRepoInterface
|
||||
{
|
||||
/**
|
||||
* @param string $uid
|
||||
* @return AccountBalance
|
||||
*/
|
||||
public function getAccount(string $uid): AccountBalance;
|
||||
|
||||
/**
|
||||
* @param string $uid
|
||||
* @param PointType $pointType
|
||||
* @return PointsBalance
|
||||
*/
|
||||
public function getPointBalance(string $uid, PointType $pointType): PointsBalance;
|
||||
|
||||
/**
|
||||
* @param InitialAccountCmd $cmd
|
||||
* @return void
|
||||
*/
|
||||
public function initial(InitialAccountCmd $cmd): void;
|
||||
}
|
||||
@@ -13,6 +13,7 @@ namespace Singularity\HDK\Pay\Infrastructure\Repository;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Hyperf\Codec\Json;
|
||||
use Singularity\HDK\Pay\Application\Command\InitialAccountCmd;
|
||||
use Singularity\HDK\Pay\Domain\Account\Aggregate\Account\AccountBalance;
|
||||
use Singularity\HDK\Pay\Domain\Account\Aggregate\Account\PointsBalance;
|
||||
use Singularity\HDK\Pay\Domain\Account\Enum\PointType;
|
||||
@@ -67,4 +68,17 @@ final class AccountBalanceRepo extends AbstractRepo implements AccountRepoInterf
|
||||
expiredAt: isset($result['expired_at']) ? new Carbon($result['expired_at']): null,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function initial(InitialAccountCmd $cmd): void
|
||||
{
|
||||
$uid = $cmd->uid;
|
||||
|
||||
$this->requestService->requestPost(
|
||||
url: "/rpc/v2/account/$uid/balance",
|
||||
data: $cmd->pointsBalances
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -44,6 +44,7 @@ final class PointLogRepo extends AbstractRepo implements PointLogRepoInterface
|
||||
source: $item['source'],
|
||||
operator: $item['operator'],
|
||||
description: $item['description'],
|
||||
patientName: $item['patient_name'],
|
||||
date: new Carbon($item['date']),
|
||||
invoiceable: $item['invoiceable'],
|
||||
invoiceRecord: isset($item['invoice_record'])
|
||||
@@ -74,6 +75,7 @@ final class PointLogRepo extends AbstractRepo implements PointLogRepoInterface
|
||||
source: $result['source'],
|
||||
operator: $result['operator'],
|
||||
description: $result['description'],
|
||||
patientName: $result['patient_name'],
|
||||
date: new Carbon($result['date']),
|
||||
invoiceable: $result['invoiceable'],
|
||||
invoiceRecord: isset($result['invoice_record'])
|
||||
|
||||
@@ -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'] ?? [],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
53
tests/Feature/Account/InitialAccountBalanceTest.php
Normal file
53
tests/Feature/Account/InitialAccountBalanceTest.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* InitialAccountBalanceTest.php@Pay
|
||||
*
|
||||
* @author 李东云 <Dongyun.Li@LuxCreo.Ai>
|
||||
* Powered by PhpStorm
|
||||
* Created on 2025/9/17
|
||||
*/
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Singularity\HDK\Pay\Application\Command\InitialAccountCmd;
|
||||
use Singularity\HDK\Pay\Domain\Account\Enum\PointType;
|
||||
|
||||
use Singularity\HDK\Pay\Infrastructure\Repository\AccountBalanceRepo;
|
||||
|
||||
use function Hyperf\Support\make;
|
||||
|
||||
it('should initial account balance', function () {
|
||||
$uid = uniqid('TDD');
|
||||
$data = [
|
||||
[
|
||||
'type' => 'aligner',
|
||||
'basic' => 0,
|
||||
'bonus' => 40,
|
||||
'expired_at' => Carbon::now()->addYear(),
|
||||
'version' => 'trial',
|
||||
],
|
||||
[
|
||||
'type' => 'ema',
|
||||
'basic' => 0,
|
||||
'bonus' => 1,
|
||||
'expired_at' => Carbon::now()->addYear(),
|
||||
'version' => 'Trial',
|
||||
],
|
||||
];
|
||||
|
||||
$cmd = new InitialAccountCmd($uid);
|
||||
foreach ($data as $point_balance) {
|
||||
$cmd->addPointsBalance(
|
||||
type: PointType::from($point_balance['type']),
|
||||
basic: $point_balance['basic'],
|
||||
bonus: $point_balance['bonus'],
|
||||
expiredAt:$point_balance['expired_at'],
|
||||
version: $point_balance['version'],
|
||||
);
|
||||
}
|
||||
|
||||
$repo = make(AccountBalanceRepo::class);
|
||||
$repo->initial($cmd);
|
||||
|
||||
expect(true)->toBeTrue();
|
||||
});
|
||||
Reference in New Issue
Block a user