find((int) $matches[1]); } return Withdraw::with('customer') ->where('tracked_number', $referenceId) ->orderByDesc('id') ->first(); } public function markPaidAndCredit(Withdraw $withdraw, string $trackNumber, string $note = 'واریز درگاه'): void { DB::transaction(function () use ($withdraw, $trackNumber, $note) { $locked = Withdraw::query()->whereKey($withdraw->id)->lockForUpdate()->first(); if (!$locked || (int) $locked->sts === 2) { return; } if ($trackNumber !== '') { $locked->tracked_number = $trackNumber; } $locked->sts = 2; $locked->save(); $user = Customer::find($locked->customer_id); if (!$user) { return; } $wallet = new WalletInterface($user->id, $user->type); new TransactionInterface($wallet, [ 'cash' => (int) $locked->cash, 'expire_at' => now(), 'withdraw_id' => $locked->id, 'active' => true, ], 3, false, true); try { app(\App\Services\PargarSyncService::class)->queueWalletDocument( $user, 'cash', (float) $locked->cash, [ 'withdraw_id' => $locked->id, 'note' => $note, 'source' => 'gateway', ] ); } catch (\Throwable $e) { report($e); } $locked->loadMissing('customer'); $message = 'کاربر ' . ($locked->customer->name ?? '') . ' با شماره موبایل ' . ($locked->customer->mobile ?? '') . ' حساب خود را به مقدار ' . number_format((int) $locked->cash) . ' ریال شارژ کرد. با تشکر، ' . $this->config->getString('name_fa', ''); User::where('send_sms', 1)->get()->each(function ($admin) use ($message) { if (Controller::isSmsNotifEnabled('sms_notif_gateway_charge_admin')) { Controller::Send($admin->mobile, $message); } }); }); } }