<?php

namespace app\admin\model;

use think\Model;


class Virtuial extends Model
{

    

    

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

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

    // 追加属性
    protected $append = [
        'add_time_text',
    ];
    

    public function getImageAttr($value, $data)
    {
        return db("goods")->where(['id'=>$data['goods_id']])->value("image");
    }

    public function getGoodsNameAttr($value, $data)
    {
        return db("goods")->where(['id'=>$data['goods_id']])->value("goods_name");
    }
    public function getPriceAttr($value, $data)
    {
        return db("goods")->where(['id'=>$data['goods_id']])->value("coin_price");
    }

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

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


}
