<?php

namespace app\admin\model\user\withdrawal;

use think\Model;


class UserwithdrawalLog extends Model
{

    

    

    // 表名
    protected $name = 'user_withdrawal_log';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'integer';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'status_text',
        'withdrawal_status_text',
        'type_text',
        'paytime_text',
        'examinetime_text'
    ];
    

    
    public function getStatusList()
    {
        return ['1' => __('Status 1'), '2' => __('Status 2'), '3' => __('Status 3')];
    }

    public function getWithdrawalStatusList()
    {
        return ['1' => __('Withdrawal_status 1'), '2' => __('Withdrawal_status 2'), '3' => __('Withdrawal_status 3')];
    }

    public function getTypeList()
    {
        return ['bank' => __('Type bank'), 'wechat' => __('Type wechat'), 'alipay' => __('Type alipay')];
    }


    public function getStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
        $list = $this->getStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getWithdrawalStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['withdrawal_status']) ? $data['withdrawal_status'] : '');
        $list = $this->getWithdrawalStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getTypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['type']) ? $data['type'] : '');
        $list = $this->getTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getPaytimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['paytime']) ? $data['paytime'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getExaminetimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['examinetime']) ? $data['examinetime'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }

    protected function setPaytimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    protected function setExaminetimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }


    public function user()
    {
        return $this->belongsTo('app\common\model\User', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }
}
