'integer', 'transfer_app_id' => 'integer', 'out_id' => 'integer', 'user_id' => 'integer', 'currency_id' => 'integer', 'fund_id' => 'integer', 'type' => TransferType::class, 'status' => TransferStatus::class, 'out_amount' => 'decimal:10', 'amount' => 'decimal:10', 'exchange_rate' => 'decimal:4', 'callback_data' => CallbackDataCast::class, 'processed_at' => 'datetime', 'callback_at' => 'datetime', 'completed_at' => 'datetime', 'created_at' => 'datetime', 'updated_at' => 'datetime', 'deleted_at' => 'datetime', ]; /** * 软删除 */ protected $dates = ['deleted_at']; /** * 隐藏字段 */ protected $hidden = []; /** * 关联划转应用 */ public function transferApp() { return $this->belongsTo(TransferApp::class, 'transfer_app_id'); } /** * 获取类型文本 */ public function getTypeTextAttribute(): string { return $this->type->getDescription(); } /** * 获取状态文本 */ public function getStatusTextAttribute(): string { return $this->status->getDescription(); } /** * 获取状态颜色 */ public function getStatusColorAttribute(): string { return $this->status->getColor(); } /** * 获取类型颜色 */ public function getTypeColorAttribute(): string { return $this->type->getColor(); } /** * 判断是否为转入订单 */ 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 updateStatus(TransferStatus $status, string $message = null): bool { $data = ['status' => $status]; if ($message) { $data['error_message'] = $message; } // 设置时间戳 switch ($status) { case TransferStatus::PROCESSING: $data['processed_at'] = now(); break; case TransferStatus::CALLBACK: $data['callback_at'] = now(); break; case TransferStatus::COMPLETED: case TransferStatus::FAILED: $data['completed_at'] = now(); break; } return $this->update($data); } }