diff --git a/src/ConfigProvider.php b/src/ConfigProvider.php index 6a5077c..1e69d2f 100644 --- a/src/ConfigProvider.php +++ b/src/ConfigProvider.php @@ -7,11 +7,13 @@ namespace Singularity\HDK\Pay; use Hyperf\Contract\StdoutLoggerInterface; use Hyperf\Framework\Logger\StdoutLogger; use Singularity\HDK\Pay\Domain\Account\Repository\AccountRepoInterface; +use Singularity\HDK\Pay\Domain\Account\Repository\PointLogRepoInterface; use Singularity\HDK\Pay\Domain\Product\Repository\ExchangeRepoInterface; use Singularity\HDK\Pay\Domain\Product\Repository\RechargeProductRepoInterface; use Singularity\HDK\Pay\Domain\Transaction\Repository\OrderRepoInterface; use Singularity\HDK\Pay\Infrastructure\Repository\AccountBalanceRepo; use Singularity\HDK\Pay\Infrastructure\Repository\OrderRepo; +use Singularity\HDK\Pay\Infrastructure\Repository\PointLogRepo; use Singularity\HDK\Pay\Infrastructure\Repository\ProductRepo; /** @@ -30,11 +32,12 @@ class ConfigProvider 'dependencies' => [ StdoutLoggerInterface::class => StdoutLogger::class, - // Command + // Repo AccountRepoInterface::class => AccountBalanceRepo::class, ExchangeRepoInterface::class => ProductRepo::class, RechargeProductRepoInterface::class => ProductRepo::class, OrderRepoInterface::class => OrderRepo::class, + PointLogRepoInterface::class => PointLogRepo::class, ], // 合并到 config/autoload/annotations.php 文件 'annotations' => [ diff --git a/src/Domain/Account/Aggregate/PointLog/PointLog.php b/src/Domain/Account/Aggregate/PointLog/PointLog.php new file mode 100644 index 0000000..9c6ae1e --- /dev/null +++ b/src/Domain/Account/Aggregate/PointLog/PointLog.php @@ -0,0 +1,70 @@ + + * Powered by PhpStorm + * Created on 2025/8/21 + */ +declare(strict_types=1); + +namespace Singularity\HDK\Pay\Domain\Account\Aggregate\PointLog; + +use Carbon\Carbon; +use Singularity\HDK\Pay\Domain\AggregateRoot; + +final class PointLog extends AggregateRoot +{ + public function __construct( + private readonly int $id, + private readonly string $caseId, + private readonly string $uid, + private readonly float $credits, + private readonly string $source, + private readonly string $operator, + private readonly string $description, + private readonly Carbon $date, + ) {} + + public function getDescription(): string + { + return $this->description; + } + + public function getSource(): string + { + return $this->source; + } + + public function getDate(): Carbon + { + return $this->date; + } + + public function getUid(): string + { + return $this->uid; + } + + + public function getCredits(): float + { + return $this->credits; + } + + public function getOperator(): string + { + return $this->operator; + } + + public function getCaseId(): ?string + { + return $this->caseId; + } + + public function getId(): ?int + { + return $this->id; + } +} \ No newline at end of file diff --git a/src/Domain/Account/Enum/PointAction.php b/src/Domain/Account/Enum/PointAction.php new file mode 100644 index 0000000..e72a4b9 --- /dev/null +++ b/src/Domain/Account/Enum/PointAction.php @@ -0,0 +1,35 @@ + + * Powered by PhpStorm + * Created on 2025/8/21 + */ + +namespace Singularity\HDK\Pay\Domain\Account\Enum; + +enum PointAction +{ + case Initial; + + case Deduct; + + case Refund; + + case Increase; + + case Clear; + + public static function tryFrom(string $action): ?PointAction + { + return match (strtolower($action)) { + 'initial' => self::Initial, + 'deduct' => self::Deduct, + 'refund' => self::Refund, + 'increase' => self::Increase, + 'clear' => self::Clear, + default => null, + }; + } +} diff --git a/src/Domain/Account/Repository/PointLogRepoInterface.php b/src/Domain/Account/Repository/PointLogRepoInterface.php new file mode 100644 index 0000000..58e6af1 --- /dev/null +++ b/src/Domain/Account/Repository/PointLogRepoInterface.php @@ -0,0 +1,21 @@ + + * Powered by PhpStorm + * Created on 2025/8/27 + */ + +namespace Singularity\HDK\Pay\Domain\Account\Repository; + +use Singularity\HDK\Pay\Domain\Account\Aggregate\PointLog\PointLog; + +interface PointLogRepoInterface +{ + /** + * @param string $uid + * @return PointLog[] + */ + public function getList(string $uid): array; +} \ No newline at end of file diff --git a/src/Infrastructure/Repository/PointLogRepo.php b/src/Infrastructure/Repository/PointLogRepo.php new file mode 100644 index 0000000..d3572fb --- /dev/null +++ b/src/Infrastructure/Repository/PointLogRepo.php @@ -0,0 +1,42 @@ + + * Powered by PhpStorm + * Created on 2025/8/27 + */ +declare(strict_types=1); + +namespace Singularity\HDK\Pay\Infrastructure\Repository; + +use Carbon\Carbon; +use Hyperf\Codec\Json; +use Singularity\HDK\Pay\Domain\Account\Aggregate\PointLog\PointLog; +use Singularity\HDK\Pay\Domain\Account\Enum\PointType; +use Singularity\HDK\Pay\Domain\Account\Repository\PointLogRepoInterface; + +final class PointLogRepo extends AbstractRepo implements PointLogRepoInterface +{ + public function getList(string $uid): array + { + $response = $this->requestService->requestGet(url: "/rpc/v2/account/$uid/logs/points"); + + $content = $response->getBody()->getContents(); + $result = Json::decode($content); + + return array_map(function ($item) { + return new PointLog( + id: $item['id'], + caseId: $item['case_id'], + uid: $item['uid'], + credits: $item['credits'], + source: $item['source'], + operator: $item['operator'], + description: $item['description'], + date: new Carbon($item['date']), + ); + }, $result); + } +} \ No newline at end of file diff --git a/tests/Feature/Account/QueryPointLogListTest.php b/tests/Feature/Account/QueryPointLogListTest.php new file mode 100644 index 0000000..4da5181 --- /dev/null +++ b/tests/Feature/Account/QueryPointLogListTest.php @@ -0,0 +1,25 @@ + + * Powered by PhpStorm + * Created on 2025/8/27 + */ + +use Singularity\HDK\Pay\Domain\Account\Aggregate\PointLog\PointLog; +use Singularity\HDK\Pay\Infrastructure\Repository\PointLogRepo; + +use function Hyperf\Support\make; + +it('should can query point log list', function () { + $uid = '61a74db54f387'; + + $repo = make(PointLogRepo::class); + $list = $repo->getList($uid); + expect($list) + ->not->toBeEmpty() + ->each + ->toBeInstanceOf(PointLog::class); +});