<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;

class Order extends BaseModel
{
    use HasFactory;

    const PAY_TYPE    = [0 => '未支付', 1 => '香港支付宝', 2 => '内地支付宝', 3 => '余额', 4 => '银联'];
    const SEND_STATUS = [0 => '未发货', 1 => '已发货'];
    const STATUS      = [0 => '待付款', 1 => '待卖家发货', 2 => '待审核', 3 => '待平台发货', 4=>'待收货', 5=>'待评价', 6=>'存平台'];

    public function users()
    {
        return $this->belongsTo(User::class, 'user_id', 'id');
    }

    public function goods()
    {
        return $this->belongsTo(Goods::class, 'goods_id', 'id');
    }

    public function goods_attr()
    {
        return $this->belongsTo(GoodsAttr::class, 'goods_attr_id', 'id');
    }

    public static function getPayTypeText($value)
    {
        return self::PAY_TYPE[$value];
    }

    public function getFeedbackAttribute($value)
    {
        if (is_array($value)) {
            return $value;
        }
        return json_decode($value, true);
    }

}
