From 44733aabdb6f23b8657bf53915be91284e9336b3 Mon Sep 17 00:00:00 2001 From: mohammad sedighi Date: Thu, 25 Jun 2026 23:06:29 +0330 Subject: [PATCH] added tahesab options 3 --- .../Controllers/Admin/WalletController.php | 39 +++++++++++++++++++ .../Controllers/Finance/FinanceController.php | 37 ++++++++++++++++++ 2 files changed, 76 insertions(+) diff --git a/app/Http/Controllers/Admin/WalletController.php b/app/Http/Controllers/Admin/WalletController.php index f86f31f..a4d649f 100644 --- a/app/Http/Controllers/Admin/WalletController.php +++ b/app/Http/Controllers/Admin/WalletController.php @@ -20,6 +20,7 @@ use Symfony\Component\HttpKernel\Exception\UnprocessableEntityHttpException; use App\Http\Controllers\Admin\TahesabController; use App\Models\Setting; use App\Models\User; +use App\Models\TransactionsAdmin; use App\Services\BalanceReportService; use App\Services\ConfigService; use App\Services\WalletBalanceService; @@ -124,6 +125,8 @@ class WalletController extends Controller 'active' => true ], $type, true, $deposit, $gold_block); + $this->recordAccountingTransaction($customer, $Withdraw, (int) $user->id, (float) $data['value'], 0, $data['note'] ?? null); + if($this->Config('send_to_tahesab') == "true"){ try { $data['direction'] = $deposit ? 0 : 1; @@ -192,6 +195,8 @@ class WalletController extends Controller 'active' => true ], 7, $deposit, false, $gold_block); + $this->recordAccountingTransaction($customer, $Withdraw, (int) $user->id, 0, (float) $data['value'], $data['note'] ?? null); + //send to tahesab if($this->Config('send_to_tahesab') == "true"){ try { @@ -325,6 +330,15 @@ class WalletController extends Controller 'active' => true, ], 7, $deposit, false, $goldBlock); + $this->recordAccountingTransaction( + $customer, + $Withdraw, + (int) $user->id, + 0, + (float) $data['value'], + ($data['note'] ?? null) ?: ('شارژ ' . $product->title) + ); + if ($this->Config('send_to_tahesab') == 'true') { try { $data['direction'] = $deposit ? 1 : 0; @@ -621,4 +635,29 @@ class WalletController extends Controller return response()->json(true); } + private function recordAccountingTransaction( + Customer $customer, + Withdraw $withdraw, + int $adminUserId, + float $cash = 0, + float $gold = 0, + ?string $note = null + ): void { + $transaction = Transaction::where('withdraw_id', $withdraw->id)->latest('id')->first(); + + TransactionsAdmin::create([ + 'customer_id' => $customer->id, + 'customer_to_id' => $customer->id, + 'user_id' => $adminUserId, + 'wallet' => null, + 'transaction_id' => $transaction?->id, + 'cash' => $cash, + 'note' => $note ?? $withdraw->note, + 'type' => 1, + 'gold' => $gold, + 'balance_cash' => 0, + 'withdraw_id' => $withdraw->id, + ]); + } + } diff --git a/app/Http/Controllers/Finance/FinanceController.php b/app/Http/Controllers/Finance/FinanceController.php index 5811b83..43f364e 100644 --- a/app/Http/Controllers/Finance/FinanceController.php +++ b/app/Http/Controllers/Finance/FinanceController.php @@ -9,6 +9,8 @@ use App\Models\Price; use App\Models\TransactionsAdmin; use App\Models\User; use App\Models\Withdraw; +use App\Models\Tahesab; +use App\Services\TahesabSyncService; use App\DB\Te\TableEngine; use Illuminate\Http\Request; @@ -27,6 +29,41 @@ class FinanceController extends Controller ->initSearch(['price']) ->select(['*']) ->export($transactions_admins); + + if (isset($transactions_admins['rows']) && is_array($transactions_admins['rows']) && $this->Config('send_to_tahesab') === 'true') { + $withdrawIds = collect($transactions_admins['rows']) + ->pluck('withdraw_id') + ->filter() + ->unique() + ->values() + ->all(); + + if ($withdrawIds !== []) { + $tahesabByWithdraw = Tahesab::query() + ->whereIn('withdraw_id', $withdrawIds) + ->orderByDesc('id') + ->get() + ->unique('withdraw_id') + ->keyBy('withdraw_id'); + + foreach ($transactions_admins['rows'] as &$row) { + $tahesab = $tahesabByWithdraw->get($row['withdraw_id'] ?? null); + if (! $tahesab) { + continue; + } + + $row['tahesab_record_id'] = $tahesab->id; + $row['tahesab_sync_status'] = $tahesab->sync_status + ?? (empty($tahesab->tahesab_id) ? TahesabSyncService::STATUS_PENDING : TahesabSyncService::STATUS_SUCCESS); + + if (empty($tahesab->tahesab_id) || $row['tahesab_sync_status'] === TahesabSyncService::STATUS_FAILED) { + $row['tahesab_failed_id'] = $tahesab->id; + } + } + unset($row); + } + } + return response()->json($transactions_admins); } public function index()