<?php

namespace App\Models;

/**
 * @property $date
 * @property $recharge_amount
 * @property $withdrawal_amount
 * @property $status
 * @property $backflow_ratio
 * @property $member_id
 * @property $amount
 * @property $grant_time
 *
 */
class Backflow extends BaseModel
{
    protected $table = 'backflow';
    protected $fillable = ['date', 'member_id', 'grant_time', 'recharge_amount', 'withdrawal_amount', 'backflow_ratio', 'amount', 'status'];

    function user()
    {
        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 getGrantTimeAttribute($value): string
    {
        if ($value > 0) return date('Y-m-d H:i', $value);
        return "";
    }
}