From 3d56178e62e3f7bca02ef23c98ce37f63be68c41 Mon Sep 17 00:00:00 2001 From: adonis Date: Thu, 2 Jul 2026 21:11:37 +0330 Subject: [PATCH] product time changed 4 --- .../Controllers/Customer/WalletController.php | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/app/Http/Controllers/Customer/WalletController.php b/app/Http/Controllers/Customer/WalletController.php index 3a2cb60..e815317 100644 --- a/app/Http/Controllers/Customer/WalletController.php +++ b/app/Http/Controllers/Customer/WalletController.php @@ -764,6 +764,8 @@ class WalletController extends Controller foreach ($rows as $record) { $row = $record instanceof Transaction ? $record->toArray() : (array) $record; + $this->attachMissingOrderForApi($row); + if ($this->isShopRialTransaction($record)) { $row['withdraw'] = ['sts_str' => 'برداشت ریالی توسط فروشگاه']; } @@ -899,4 +901,52 @@ class WalletController extends Controller } } + /** + * بعضی تراکنش‌های قدیمی order_id دارند ولی ردیف orders حذف شده — برای UI وضعیت/قیمت را بازسازی می‌کنیم. + */ + private function attachMissingOrderForApi(array &$row): void + { + $orderId = (int) ($row['order_id'] ?? 0); + if ($orderId <= 0) { + return; + } + + $order = $row['order'] ?? null; + if (is_array($order) && !empty($order['id'])) { + return; + } + + $loaded = Order::query()->find($orderId); + if ($loaded) { + $row['order'] = $loaded->toArray(); + + return; + } + + $type = (int) ($row['type'] ?? 0); + if (!in_array($type, [1, 2, 10], true)) { + return; + } + + $row['order'] = [ + 'id' => $orderId, + 'sts' => 2, + 'payment_sts' => 4, + 'sts_str' => 'موفق', + 'price' => $this->inferTradePriceFromTransactionRow($row), + 'amount' => abs((float) ($row['gold'] ?? 0)), + ]; + } + + private function inferTradePriceFromTransactionRow(array $row): int + { + $cash = abs((int) ($row['cash'] ?? 0)); + $gold = abs((float) ($row['gold'] ?? 0)); + if ($gold > 0 && $cash > 0) { + return (int) round($cash / $gold); + } + + return 0; + } + }