<?php

namespace App\Models;

use App\Constants\Util;

class Recharge extends BaseModel
{

    protected $table = 'recharges';
    // protected $fillable = ['member_id', 'confirmations', 'coin', 'txid','block_time','block_height' ,'net' ,'coin' ,'amount' ,'to_address' ,'from_address' ,'status'];
    protected $hidden = [];
    const STATUS_STAY = 0;
    const STATUS_SUCCESS = 1;
    const STATUS_FAIL = 2;
    const STATUS_IGNORE = 3;

    public static $STATUS = [
        0 => '待确认',
        1 => '已确认',
        2 => '失败',
        3 => '已忽略',
    ];

    const TYPE_AUTO = 1; // 自动
    const TYPE_HAND = 2; // 手动

    public function member()
    {
        return $this->belongsTo(User::class, 'member_id', 'member_id')
            ->select(['id', 'member_id', 'username', 'first_name', 'admin_note', 'status', 'phone', 'visitor_id', 'register_ip']);
    }

    protected function getAmountAttribute($value)
    {
        return floatval($value);
    }

    protected function getImageAttribute($value)
    {
        return Util::ensureUrl($value);
    }

    protected function setImageAttribute($value)
    {
        $this->attributes['image'] = Util::replacePartInUrl($value);
    }
}
