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/Models/Order.php
<?php

namespace App\Models;

use App\Enums\OrderPaymentType;
use App\Enums\OrderStatus;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Order extends Model
{
    use HasFactory;

    protected $guarded = ['id'];

    protected $casts = [
        'status' => OrderStatus::class,
        'payment_type' => OrderPaymentType::class,
    ];

    public const SHIPPING_EXPRESS = 0;

    public const SHIPPING_COURIER = 1;

    public const SHIPPING_TRANSLATE = ['پست پیشتاز', 'پیک'];

    public function user()
    {
        return $this->belongsTo(User::class)->withDefault();
    }

    public function addresses()
    {
        return $this->morphToMany(Address::class, 'addressable');
    }

    public function products()
    {
        return $this->belongsToMany(Product::class)
            ->using(OrderProduct::class)
            ->withPivot('quantity', 'price', 'discount', 'option_id', 'value_id', 'name');
    }

    public function lockedStocks()
    {
        return $this->hasMany(LockedStock::class);
    }

    public function scopeCreateDeliveryCode()
    {
        return rand(100000, 999999);
    }

    public function wallets()
    {
        return $this->morphMany(Wallet::class, 'walletable');
    }

    public function changeCustomerPoints($increase = true)
    {
        $rate = (int) settings('point-for-per-1000-toman');

        if ($rate > 0 && $point = round(($this->price / 1000) * $rate)) {
            Point::create([
                'user_id' => $this->user_id,
                'amount' => $increase ? $point : $point * -1,
                'description' => $increase ? "تکمیل سفارش {$this->tracking_code}" : "عدم تکمیل سفارش {$this->tracking_code}",
                'pointable_id' => $this->id,
                'pointable_type' => Order::class,
            ]);
        }
    }

    public function discountCode()
    {
        return $this->belongsTo(Discount::class, 'discount_id')->withDefault();
    }

    public function payments()
    {
        return $this->morphMany(Payment::class, 'paymentable');
    }

    public function city()
    {
        return $this->belongsTo(City::class)->withDefault();
    }
}