id, transfer_app_id: $model->transfer_app_id, out_id: $model->out_id, out_order_id: $model->out_order_id, out_user_id: $model->out_user_id, user_id: $model->user_id, currency_id: $model->currency_id, fund_id: $model->fund_id, type: $model->type, status: $model->status, out_amount: (string) $model->out_amount, amount: (string) $model->amount, exchange_rate: (float) $model->exchange_rate, fee_rate: (float) ($model->fee_rate ?? 0.0000), fee_amount: (string) ($model->fee_amount ?? '0.0000'), actual_amount: (string) ($model->actual_amount ?? $model->amount), callback_data: $model->callback_data ?? [], error_message: $model->error_message, remark: $model->remark, processed_at: $model->processed_at?->toDateTimeString(), callback_at: $model->callback_at?->toDateTimeString(), completed_at: $model->completed_at?->toDateTimeString(), created_at: $model->created_at->toDateTimeString(), updated_at: $model->updated_at->toDateTimeString(), ); } /** * 转换为数组 */ public function toArray(): array { return [ 'id' => $this->id, 'transfer_app_id' => $this->transfer_app_id, 'out_id' => $this->out_id, 'out_order_id' => $this->out_order_id, 'out_user_id' => $this->out_user_id, 'user_id' => $this->user_id, 'currency_id' => $this->currency_id, 'fund_id' => $this->fund_id, 'type' => $this->type->value, 'type_text' => $this->type->getDescription(), 'status' => $this->status->value, 'status_text' => $this->status->getDescription(), 'out_amount' => $this->out_amount, 'amount' => $this->amount, 'exchange_rate' => $this->exchange_rate, 'fee_rate' => $this->fee_rate, 'fee_amount' => $this->fee_amount, 'actual_amount' => $this->actual_amount, 'has_fee' => $this->fee_amount > 0, 'fee_rate_percent' => number_format($this->fee_rate * 100, 2) . '%', 'callback_data' => $this->callback_data, 'error_message' => $this->error_message, 'remark' => $this->remark, 'processed_at' => $this->processed_at, 'callback_at' => $this->callback_at, 'completed_at' => $this->completed_at, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, ]; } /** * 判断是否为转入订单 */ public function isTransferIn(): bool { return $this->type === TransferType::IN; } /** * 判断是否为转出订单 */ public function isTransferOut(): bool { return $this->type === TransferType::OUT; } /** * 判断是否为最终状态 */ public function isFinalStatus(): bool { return $this->status->isFinal(); } /** * 判断是否可以重试 */ public function canRetry(): bool { return $this->status->canRetry(); } /** * 判断是否收取了手续费 */ public function hasFee(): bool { return bccomp($this->fee_amount, '0', 4) > 0; } /** * 获取手续费率百分比文本 */ public function getFeeRatePercent(): string { return number_format($this->fee_rate * 100, 2) . '%'; } /** * 获取手续费金额格式化文本 */ public function getFeeAmountText(): string { return number_format((float)$this->fee_amount, 4); } /** * 获取实际到账金额格式化文本 */ public function getActualAmountText(): string { return number_format((float)$this->actual_amount, 4); } }