<?php

namespace App;

use App\Traits\ModelTimeFormat;
use Illuminate\Database\Eloquent\Model;

class OrderIssue extends Model
{
    //
    use ModelTimeFormat;

    protected $fillable = [
        'order_id','handle_status','create_at','rejected_bill_id','rejecting_status','result_explain',
        'situation_explain', 'order_issue_type_id','second_order_id','is_new_rejecting',
        'final_status','logistic_indemnity_money','logistic_express_remission','baoshi_indemnity_money','baoshi_express_remission','user_workgroup_id'];

    protected $appends = [
        'secondLogisticNumber',
    ];

    public function order(){
        return $this->belongsTo('App\Order','order_id','id');
    }

    public function rejectedBill(){
        return $this->belongsTo('App\RejectedBill','rejected_bill_id','id');
    }

    public function issueType(){
        return $this->belongsTo('App\OrderIssueType','order_issue_type_id','id');
    }

    public function logs(){
        return $this->hasMany('App\OrderIssueProcessLog','order_issue_id','id');
    }

    public function top(){
        return $this->hasOne('App\OrderIssueOnTop','order_issue_id','id');
    }

    public function userWorkGroup(){
        return $this->belongsTo('App\UserWorkgroup','user_workgroup_id','id');
    }

    public function secondOrder(){
        return $this->belongsTo('App\Order','second_order_id','id');
    }

    public function getSecondLogisticNumberAttribute(){
        return $this['secondOrder'] ? $this['secondOrder']['code'] : null;
    }

}
