<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class OrderDetail extends Model
{
    protected $table='order_detail';
    protected $guarded=[];

    public function order(){
        return $this->belongsTo(Order::class,'order_no','order_no');
    }
    public function goods(){
        return $this->HasOne(Goods::class,'id','goods_id');
    }
    public function store(){
        return $this->hasOne(Store::class,'id','store_id');
    }
    public function getPriceAttribute($value){
        return round($value);
    }
    public function getAccountAttribute($value){
        return round($value);
    }
    public function user()
    {
        return $this->hasOneThrough(
            'App\Models\DwbsUser',
            'App\Models\Store',
            'id', // 店铺表外键...
            'id', // 表外键...
            'store_id', // 详情表本地键...
            'user_id' // 店铺表本地键...
        );
    }
}
