<?php

namespace App\Models;

use Dcat\Admin\Traits\HasDateTimeFormatter;
use Illuminate\Database\Eloquent\Model;

class Order extends Model
{
    use HasDateTimeFormatter;
    protected $table    = 'order';
    protected $fillable = ['user_id', 'state', 'order', 'wx_order', 'amount', 'diamond', 'pay_at', 'created_at', 'updated_at', 'pay', 'isPost', 'config_id'];

    public function configData()
    {
        return $this->hasOne(PaymentConfig::class, 'id', 'config_id');
    }

    public function getAmountAttribute($value)
    {
        return $value / 100;
    }

    public function getCreatedAtAttribute($value)
    {
        $dateTime = new \DateTime($value);

        // 格式化时间
        $formattedTime = $dateTime->format('Y-m-d H:i:s');

        return $formattedTime;
    }

    public function getUpdatedAtAttribute($value)
    {
        $dateTime = new \DateTime($value);

        // 格式化时间
        $formattedTime = $dateTime->format('Y-m-d H:i:s');

        return $formattedTime;
    }
    public function userData(){
        return $this->hasOne(User::class,'id','user_id');
    }
    public function orderData(){
        return $this->hasOne(PaymentConfig::class,'id','config_id');
    }
}
