| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 |
- <?php
- namespace App\Module\Transfer\Dtos;
- /**
- * 划转应用数据传输对象
- */
- class TransferAppDto
- {
- public function __construct(
- public readonly int $id,
- public readonly string $keyname,
- public readonly string $title,
- public readonly ?string $description,
- public readonly ?int $out_id2,
- public readonly ?int $out_id3,
- public readonly int $currency_id,
- public readonly int $fund_id,
- public readonly ?int $fund_to_uid,
- public readonly ?int $fund_in_uid,
- public readonly float $exchange_rate,
- public readonly ?string $order_callback_url,
- public readonly ?string $order_in_info_url,
- public readonly ?string $order_out_create_url,
- public readonly ?string $order_out_info_url,
- public readonly bool $is_enabled,
- public readonly bool $allow_transfer_in,
- public readonly bool $allow_transfer_out,
- public readonly string $created_at,
- public readonly string $updated_at,
- ) {}
- /**
- * 从模型创建DTO
- */
- public static function fromModel($model): self
- {
- return new self(
- id: $model->id,
- keyname: $model->keyname,
- title: $model->title,
- description: $model->description,
- out_id2: $model->out_id2,
- out_id3: $model->out_id3,
- currency_id: $model->currency_id,
- fund_id: $model->fund_id,
- fund_to_uid: $model->fund_to_uid,
- fund_in_uid: $model->fund_in_uid,
- exchange_rate: (float) $model->exchange_rate,
- order_callback_url: $model->order_callback_url,
- order_in_info_url: $model->order_in_info_url,
- order_out_create_url: $model->order_out_create_url,
- order_out_info_url: $model->order_out_info_url,
- is_enabled: $model->is_enabled,
- allow_transfer_in: $model->allow_transfer_in,
- allow_transfer_out: $model->allow_transfer_out,
- created_at: $model->created_at->toDateTimeString(),
- updated_at: $model->updated_at->toDateTimeString(),
- );
- }
- /**
- * 转换为数组
- */
- public function toArray(): array
- {
- return [
- 'id' => $this->id,
- 'keyname' => $this->keyname,
- 'title' => $this->title,
- 'description' => $this->description,
- 'out_id2' => $this->out_id2,
- 'out_id3' => $this->out_id3,
- 'currency_id' => $this->currency_id,
- 'fund_id' => $this->fund_id,
- 'fund_to_uid' => $this->fund_to_uid,
- 'fund_in_uid' => $this->fund_in_uid,
- 'exchange_rate' => $this->exchange_rate,
- 'order_callback_url' => $this->order_callback_url,
- 'order_in_info_url' => $this->order_in_info_url,
- 'order_out_create_url' => $this->order_out_create_url,
- 'order_out_info_url' => $this->order_out_info_url,
- 'is_enabled' => $this->is_enabled,
- 'allow_transfer_in' => $this->allow_transfer_in,
- 'allow_transfer_out' => $this->allow_transfer_out,
- 'created_at' => $this->created_at,
- 'updated_at' => $this->updated_at,
- ];
- }
- /**
- * 判断是否为农场内部模式
- */
- public function isInternalMode(): bool
- {
- return empty($this->order_callback_url) &&
- empty($this->order_in_info_url) &&
- empty($this->order_out_create_url) &&
- empty($this->order_out_info_url);
- }
- /**
- * 判断是否支持转入
- */
- public function supportsTransferIn(): bool
- {
- if (!$this->is_enabled || !$this->allow_transfer_in) {
- return false;
- }
- return !empty($this->order_in_info_url) || $this->isInternalMode();
- }
- /**
- * 判断是否支持转出
- */
- public function supportsTransferOut(): bool
- {
- if (!$this->is_enabled || !$this->allow_transfer_out) {
- return false;
- }
- return !empty($this->order_out_create_url) || $this->isInternalMode();
- }
- /**
- * 判断是否支持回调
- */
- public function supportsCallback(): bool
- {
- return !empty($this->order_callback_url);
- }
- }
|