HEX
Server: LiteSpeed
System: Linux sv4.hami.host 5.14.0-611.54.3.el9_7.x86_64 #1 SMP PREEMPT_DYNAMIC Thu May 7 16:31:24 EDT 2026 x86_64
User: armgroup (1008)
PHP: 8.2.32
Disabled: show_source, system, shell_exec, passthru, exec, popen, proc_open, mail, socket_create, socket_create_listen, socket_create_pair, link, dl, openlog, syslog, stream_socket_server, curl_multi_init
Upload Files
File: /home/armgroup/libs/app/Http/Livewire/Account/Point/Exchange.php
<?php

namespace App\Http\Livewire\Account\Point;

use App\Http\Livewire\ConvertEmptyStringsToNull;
use App\Http\Livewire\General;
use App\Models\Point;
use App\Models\Wallet;
use Illuminate\Support\Facades\DB;
use Livewire\Component;

class Exchange extends Component
{
    use ConvertEmptyStringsToNull, General;

    public $point;

    public $credit;

    public function mount()
    {
        $this->point = auth()->user()->point;
        $this->credit = round($this->point * settings('point-exchange-rate'));
    }

    protected function rules()
    {
        return [
            'point' => ['required', 'integer', 'min:'.settings('minimum-points-allowed-to-convert'), 'max:'.auth()->user()->point],
        ];
    }

    public function updatedPoint()
    {
        $this->credit = 0;

        $this->validate();

        $this->credit = round($this->point * settings('point-exchange-rate'));
    }

    public function render()
    {
        return view('livewire.account.point.exchange');
    }

    public function exchange()
    {
        $this->validate();

        $this->credit = round($this->point * settings('point-exchange-rate'));

        DB::transaction(function () {
            $wallet = Wallet::create([
                'user_id' => auth()->id(),
                'amount' => $this->credit,
                'walletable_id' => 0,
                'walletable_type' => Point::class,
                'description' => 'تبدیل شده توسط '.to_persian_numbers($this->point).' امتیاز',
            ]);

            $point = Point::create([
                'user_id' => auth()->id(),
                'amount' => $this->point * -1,
                'pointable_id' => $wallet->id,
                'pointable_type' => Wallet::class,
                'description' => 'تبدیل به '.to_persian_numbers(number_format($this->credit)).' تومان اعتبار',
            ]);

            $wallet->update(['walletable_id' => $point->id]);
        });

        $this->doneMessage('امتیاز شما با موفقیت به اعتبار تبدیل شد');

        return redirect()->route('account.points.show-exchange');
    }
}