<?php

namespace app\admin\model\users;

use think\Model;


class Userdetailmoneymodel extends Model
{

    

    

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

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

    // 追加属性
    protected $append = [
        'heatos_text',
        'mothtime_text',
        'order_type_text',
        'pay_way_text',
        'status_text',
        'create_time_text'
    ];
    

    
    public function getHeatosList()
    {
        return ['1' => __('Heatos 1'), '-1' => __('Heatos -1')];
    }

    public function getOrderTypeList()
    {
        return ['goods' => __('Order_type goods'), 'recharge' => __('Order_type recharge')];
    }

    public function getPayWayList()
    {
        return ['money' => __('Pay_way money'), 'weixin' => __('Pay_way weixin'), 'alipay' => __('Pay_way alipay')];
    }

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


    public function getHeatosTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['heatos']) ? $data['heatos'] : '');
        $list = $this->getHeatosList();
        return isset($list[$value]) ? $list[$value] : '';
    }


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


    public function getOrderTypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['order_type']) ? $data['order_type'] : '');
        $list = $this->getOrderTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getPayWayTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['pay_way']) ? $data['pay_way'] : '');
        $list = $this->getPayWayList();
        return isset($list[$value]) ? $list[$value] : '';
    }


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


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

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

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

    public function user(){
        return self::hasOne("app\admin\model\User",'id',"user_id");
    }
}
