|
|
@@ -0,0 +1,122 @@
|
|
|
+<?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_id,
|
|
|
+ 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 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_id: $model->out_id,
|
|
|
+ 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,
|
|
|
+ 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_id' => $this->out_id,
|
|
|
+ '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,
|
|
|
+ '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
|
|
|
+ {
|
|
|
+ return !empty($this->order_in_info_url) || $this->isInternalMode();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 判断是否支持转出
|
|
|
+ */
|
|
|
+ public function supportsTransferOut(): bool
|
|
|
+ {
|
|
|
+ return !empty($this->order_out_create_url) || $this->isInternalMode();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 判断是否支持回调
|
|
|
+ */
|
|
|
+ public function supportsCallback(): bool
|
|
|
+ {
|
|
|
+ return !empty($this->order_callback_url);
|
|
|
+ }
|
|
|
+}
|