-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- 新增商户创建、更新和设置状态的命令类 - 实现商户命令的处理逻辑- 添加商户相关的服务提供者- 更新数据库迁移文件,修正表名和字段 - 新增商户模型和转换器 - 实现商户读取和写入的仓库接口和具体实现
- Loading branch information
1 parent
be58d5f
commit e03f2c9
Showing
22 changed files
with
446 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
packages/payment/src/Application/Commands/Merchant/MerchantCreateCommand.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
namespace RedJasmine\Payment\Application\Commands\Merchant; | ||
|
||
use RedJasmine\Payment\Domain\Data\MerchantData; | ||
|
||
class MerchantCreateCommand extends MerchantData | ||
{ | ||
|
||
} |
15 changes: 15 additions & 0 deletions
15
packages/payment/src/Application/Commands/Merchant/MerchantSetStatusCommand.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
namespace RedJasmine\Payment\Application\Commands\Merchant; | ||
|
||
use RedJasmine\Payment\Domain\Models\Enums\MerchantStatusEnum; | ||
use RedJasmine\Support\Data\Data; | ||
|
||
class MerchantSetStatusCommand extends Data | ||
{ | ||
|
||
|
||
public int $id; | ||
|
||
public MerchantStatusEnum $status; | ||
} |
10 changes: 10 additions & 0 deletions
10
packages/payment/src/Application/Commands/Merchant/MerchantUpdateCommand.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
namespace RedJasmine\Payment\Application\Commands\Merchant; | ||
|
||
use RedJasmine\Payment\Domain\Data\MerchantData; | ||
|
||
class MerchantUpdateCommand extends MerchantData | ||
{ | ||
public int $id; | ||
} |
22 changes: 22 additions & 0 deletions
22
packages/payment/src/Application/PaymentApplicationServiceProvider.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
namespace RedJasmine\Payment\Application; | ||
|
||
use Illuminate\Support\ServiceProvider; | ||
use RedJasmine\Payment\Domain\Repositories\MerchantReadRepositoryInterface; | ||
use RedJasmine\Payment\Domain\Repositories\MerchantRepositoryInterface; | ||
use RedJasmine\Payment\Infrastructure\ReadRepositories\Mysql\MerchantReadRepository; | ||
use RedJasmine\Payment\Infrastructure\Repositories\Eloquent\MerchantRepository; | ||
|
||
class PaymentApplicationServiceProvider extends ServiceProvider | ||
{ | ||
|
||
public function register() : void | ||
{ | ||
|
||
$this->app->bind(MerchantRepositoryInterface::class, MerchantRepository::class); | ||
$this->app->bind(MerchantReadRepositoryInterface::class, MerchantReadRepository::class); | ||
|
||
} | ||
|
||
} |
48 changes: 48 additions & 0 deletions
48
packages/payment/src/Application/Services/CommandHandlers/MerchantCreateCommandHandle.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
namespace RedJasmine\Payment\Application\Services\CommandHandlers; | ||
|
||
use RedJasmine\Payment\Application\Commands\Merchant\MerchantCreateCommand; | ||
use RedJasmine\Payment\Domain\Models\PaymentMerchant; | ||
use RedJasmine\Payment\Domain\Repositories\MerchantRepositoryInterface; | ||
use RedJasmine\Payment\Domain\Transformer\MerchantTransformer; | ||
use RedJasmine\Support\Application\CommandHandlers\CommandHandler; | ||
use Throwable; | ||
|
||
class MerchantCreateCommandHandle extends CommandHandler | ||
{ | ||
|
||
|
||
public function __construct(protected MerchantRepositoryInterface $repository) | ||
{ | ||
} | ||
|
||
/** | ||
* @param MerchantCreateCommand $command | ||
* @return PaymentMerchant | ||
* @throws Throwable | ||
*/ | ||
public function handle(MerchantCreateCommand $command) : PaymentMerchant | ||
{ | ||
$this->beginDatabaseTransaction(); | ||
|
||
try { | ||
|
||
$model = app(MerchantTransformer::class)->transform($command); | ||
|
||
$this->repository->store($model); | ||
|
||
$this->commitDatabaseTransaction(); | ||
} catch (AbstractException $exception) { | ||
$this->rollBackDatabaseTransaction(); | ||
throw $exception; | ||
} catch (Throwable $throwable) { | ||
$this->rollBackDatabaseTransaction(); | ||
throw $throwable; | ||
} | ||
|
||
return $model; | ||
|
||
} | ||
|
||
} |
45 changes: 45 additions & 0 deletions
45
packages/payment/src/Application/Services/CommandHandlers/MerchantSetStatusCommandHandle.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
namespace RedJasmine\Payment\Application\Services\CommandHandlers; | ||
|
||
use RedJasmine\Payment\Application\Commands\Merchant\MerchantSetStatusCommand; | ||
use RedJasmine\Payment\Domain\Repositories\MerchantRepositoryInterface; | ||
use RedJasmine\Support\Application\CommandHandlers\CommandHandler; | ||
use Throwable; | ||
|
||
class MerchantSetStatusCommandHandle extends CommandHandler | ||
{ | ||
|
||
|
||
public function __construct(protected MerchantRepositoryInterface $repository) | ||
{ | ||
} | ||
|
||
/** | ||
* @param MerchantSetStatusCommand $command | ||
* @return void | ||
* @throws Throwable | ||
*/ | ||
public function handle(MerchantSetStatusCommand $command):void | ||
{ | ||
$this->beginDatabaseTransaction(); | ||
|
||
try { | ||
|
||
$model = $this->repository->find($command->id); | ||
$model->setStatus($command->status); | ||
$this->repository->update($model); | ||
|
||
$this->commitDatabaseTransaction(); | ||
} catch (AbstractException $exception) { | ||
$this->rollBackDatabaseTransaction(); | ||
throw $exception; | ||
} catch (Throwable $throwable) { | ||
$this->rollBackDatabaseTransaction(); | ||
throw $throwable; | ||
} | ||
|
||
|
||
} | ||
|
||
} |
50 changes: 50 additions & 0 deletions
50
packages/payment/src/Application/Services/CommandHandlers/MerchantUpdateCommandHandle.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
|
||
namespace RedJasmine\Payment\Application\Services\CommandHandlers; | ||
|
||
use RedJasmine\Payment\Application\Commands\Merchant\MerchantCreateCommand; | ||
use RedJasmine\Payment\Application\Commands\Merchant\MerchantUpdateCommand; | ||
use RedJasmine\Payment\Domain\Models\PaymentMerchant; | ||
use RedJasmine\Payment\Domain\Repositories\MerchantRepositoryInterface; | ||
use RedJasmine\Payment\Domain\Transformer\MerchantTransformer; | ||
use RedJasmine\Support\Application\CommandHandlers\CommandHandler; | ||
use Throwable; | ||
|
||
class MerchantUpdateCommandHandle extends CommandHandler | ||
{ | ||
|
||
|
||
public function __construct(protected MerchantRepositoryInterface $repository) | ||
{ | ||
} | ||
|
||
/** | ||
* @param MerchantUpdateCommand $command | ||
* @return PaymentMerchant | ||
* @throws Throwable | ||
*/ | ||
public function handle(MerchantUpdateCommand $command) : PaymentMerchant | ||
{ | ||
$this->beginDatabaseTransaction(); | ||
|
||
try { | ||
$model = $this->repository->find($command->id); | ||
|
||
$model = app(MerchantTransformer::class)->transform($command, $model); | ||
|
||
$this->repository->update($model); | ||
|
||
$this->commitDatabaseTransaction(); | ||
} catch (AbstractException $exception) { | ||
$this->rollBackDatabaseTransaction(); | ||
throw $exception; | ||
} catch (Throwable $throwable) { | ||
$this->rollBackDatabaseTransaction(); | ||
throw $throwable; | ||
} | ||
|
||
return $model; | ||
|
||
} | ||
|
||
} |
38 changes: 38 additions & 0 deletions
38
packages/payment/src/Application/Services/MerchantCommandService.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
namespace RedJasmine\Payment\Application\Services; | ||
|
||
use RedJasmine\Payment\Application\Commands\Merchant\MerchantCreateCommand; | ||
use RedJasmine\Payment\Application\Commands\Merchant\MerchantSetStatusCommand; | ||
use RedJasmine\Payment\Application\Commands\Merchant\MerchantUpdateCommand; | ||
use RedJasmine\Payment\Application\Services\CommandHandlers\MerchantCreateCommandHandle; | ||
use RedJasmine\Payment\Application\Services\CommandHandlers\MerchantSetStatusCommandHandle; | ||
use RedJasmine\Payment\Application\Services\CommandHandlers\MerchantUpdateCommandHandle; | ||
use RedJasmine\Payment\Domain\Models\PaymentMerchant; | ||
use RedJasmine\Support\Application\ApplicationCommandService; | ||
|
||
/** | ||
* @method PaymentMerchant create(MerchantCreateCommand $command) | ||
* @method PaymentMerchant update(MerchantUpdateCommand $command) | ||
* @method void setStatus(MerchantSetStatusCommand $command) | ||
*/ | ||
class MerchantCommandService extends ApplicationCommandService | ||
{ | ||
|
||
/** | ||
* 钩子前缀 | ||
* @var string | ||
*/ | ||
public static string $hookNamePrefix = 'payment.application.merchant.command'; | ||
|
||
protected static string $modelClass = PaymentMerchant::class; | ||
|
||
|
||
protected static $macros = [ | ||
'create' => MerchantCreateCommandHandle::class, | ||
'setStatus' => MerchantSetStatusCommandHandle::class, | ||
'update' => MerchantUpdateCommandHandle::class, | ||
]; | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.