id) { return null; } $existing = TransactionsAdmin::where('order_id', $order->id)->first(); if ($existing) { return $existing; } try { return TransactionsAdmin::create([ 'customer_id' => $order->customer_id, 'customer_to_id' => $order->customer_id, 'order_id' => $order->id, 'user_id' => $order->customer_id, 'wallet' => null, 'transaction_id' => null, 'cash' => (int) round((float) ($order->total_price ?? 0)), 'note' => $this->tradeNote((int) ($order->direction ?? 0)), 'type' => 1, 'gold' => (float) ($order->amount ?? 0), 'balance_cash' => 0, 'balance_gold' => 0, ]); } catch (Throwable $e) { report($e); return null; } } /** توضیح سند معامله — همسان با desc ته‌حساب تا گزارشات و حسابداری یکی دیده شوند. */ public function tradeNote(int $direction): string { return $direction === 1 ? 'خرید آبشده' : ($direction === 2 ? 'فروش آبشده' : 'معامله'); } }