<?php

namespace App\Models;

use App\Models\traits\Filter;

class BusinessGoodsSku extends Model
{
    use Filter;

    //查询字段
    public $fieldSearchable = [
        'external_sku_id',
        'goods_name',
        'shop_id',
    ];

    protected $hidden = [
        'activity_no',
        'goods_desc',
        'goods_image_list',
        'is_activity_delete',
        'limit_buy',
        'market_price',
        'update_time',
        'quantity',
        'goods_purchase_price',
        'quantity_type',
        'reserve_quantity',
        'sold_quantity',
        'spec_list',
        'spec_name',
        'thumb_url',
        'total_quantity',
        'updated_at',
        'create_time'
    ];

    protected $fillable = [
        'title',
        'shop_id',
        'activity_no',
        'update_time',
        'create_time',
        'category_name',
        'external_sku_id',
        'goods_id',
        'goods_name',
        'goods_purchase_price',
        'sku_id',
        'thumb_url',
        'quantity_type',
        'limit_buy',
        'goods_image_list',
        'quantity',
        'spec_list',
        'reserve_quantity',
        'total_quantity',
        'spec_name',
        'sold_quantity',
        'price_in_fen',
    ];

    public function shop()
    {
        return $this->belongsTo(Shop::class, 'shop_id', 'id');
    }

    public function getPriceInFenAttribute($val)
    {
        return $val / 100;
    }
}
