HEX
Server: nginx/1.24.0
System: Linux prod-btpayments-io 6.14.0-1018-aws #18~24.04.1-Ubuntu SMP Mon Nov 24 19:46:27 UTC 2025 x86_64
User: ubuntu (1000)
PHP: 8.3.19
Disabled: NONE
Upload Files
File: /var/www/BtPayments/BtPayments-platform/app/Models/Payment/PaymentAttrs.php
<?php

namespace App\Models\Payment;

trait PaymentAttrs
{
    /**
     * 货币类型
     */
    const ORDER_CURRENCY_TYPES = [
        'USD'       =>  1001,
        'GBP'       =>  1002,
        'EUR'       =>  1003,
        'HKD'       =>  1004,
        'AUD'       =>  1005,
        'CAD'       =>  1006,
        'CHF'       =>  1007,

        'BTC'       =>  2001,
        'ETH'       =>  2002,
        'USDT'      =>  2003,
        'USDC'      =>  2004,
    ];

    /**
     * 交易状态
     */
    const STATUS_CREATED                    =   'created';
    const STATUS_UNPAID                     =   'unpaid';
    const STATUS_PENDING                    =   'pending';
    const STATUS_PAID_CONFIRMING            =   'paid_confirming';
    const STATUS_PAID                       =   'paid';
    const STATUS_PARTIAL_PAID_CONFIRMING    =   'partial_paid_confirming';
    const STATUS_PARTIAL_PAID               =   'partial_paid';
    const STATUS_FAILED                     =   'failed';
    const STATUS = [
        self::STATUS_CREATED                    =>  'Created',
        self::STATUS_UNPAID                     =>  'Unpaid',
        self::STATUS_PENDING                    =>  'Pending',
        self::STATUS_PAID_CONFIRMING            =>  'Paid Confirming',
        self::STATUS_PAID                       =>  'Paid',
        self::STATUS_PARTIAL_PAID_CONFIRMING    =>  'Partial Paid Confirming',
        self::STATUS_PARTIAL_PAID               =>  'Partial Paid',
        self::STATUS_FAILED                     =>  'Failed',
    ];

    /**
     * Attr: 状态
     *
     * @return string
     */
    public function getStatusTextAttribute()
    {
        return self::STATUS[$this->status] ?? ("Unknown ({$this->status})");
    }

    /**
     * Attr: 已付款比率
     *
     * @return float|int
     */
    public function getPaidRatioAttribute()
    {
        return floor($this->total_paid_amount / $this->order_amount * 100) ?? 0;
    }

    /**
     * Attr: 已付款比率
     *
     * @return float|int
     */
    public function getPaidRatioPercentAttribute()
    {
        return (float) (bcdiv($this->total_paid_amount, $this->order_amount, 4) * 100);
    }

    /**
     * Attr: 订单货币类型
     *
     * @return string
     */
    public function getOrderCurrencyAttribute(): string
    {
        return array_search($this->getAttribute('order_currency_type'), self::ORDER_CURRENCY_TYPES);
    }

    /**
     * Attr: 订单币种类别
     */
    public function getOrderCurrencyCategoryAttribute(): string
    {
        switch (true) {
            case $this->getAttribute('order_currency_type') < 2000:
                return 'fiat';
            case $this->getAttribute('order_currency_type') < 3000:
                return 'crypto';
            default:
                return 'unknown';
        }
    }
}