Product.php 2.2 KB
<?php

namespace App\Models\Product;

use App\Helper\Arr;
use App\Models\Base;
use Illuminate\Database\Eloquent\SoftDeletes;

class Product extends Base
{
    use SoftDeletes;

    //设置关联表名
    protected $table = 'gl_product';

    const STATUS_DRAFT = 0;
    const STATUS_ON = 1;
    const STATUS_OFF = 2;


    public static function statusMap(){
        return [
            self::STATUS_DRAFT    => '草稿',
            self::STATUS_ON   => '已上架',
            self::STATUS_OFF  => '未上架',
        ];
    }

    public function setThumbAttribute($value){
        $this->attributes['thumb'] = Arr::a2s($value);
    }

    public function getThumbAttribute($value){
        return  Arr::s2a($value);
    }

    public function setGalleryAttribute($value){
        $this->attributes['gallery'] = Arr::a2s($value);
    }

    public function getGalleryAttribute($value){
        return  Arr::s2a($value);
    }

    public function setAttrsAttribute($value){
        $this->attributes['attrs'] = Arr::a2s($value);
    }

    public function getAttrsAttribute($value){
        return  Arr::s2a($value);
    }

    public function setDescribeAttribute($value){
        $this->attributes['describe'] = Arr::a2s($value);
    }

    public function getDescribeAttribute($value){
        return  Arr::s2a($value);
    }

    public function setSeoMateAttribute($value){
        $this->attributes['seo_mate'] = Arr::a2s($value);
    }

    public function getSeoMateAttribute($value){
        return  Arr::s2a($value);
    }

    public function setCategoryIdAttribute($value){
        $this->attributes['category_id'] = Arr::arrToSet($value);
    }

    public function getCategoryIdAttribute($value){
        return Arr::setToArr($value);
    }

    public function setKeywordsAttribute($value){
        $this->attributes['keywords'] = Arr::arrToSet($value, 'trim');
    }

    public function getKeywordsAttribute($value){
        return Arr::setToArr($value, 'trim');
    }

    public function setRelatedProductIdAttribute($value){
        $this->attributes['related_product_id'] = Arr::arrToSet($value);
    }

    public function getRelatedProductIdAttribute($value){
        return Arr::setToArr($value);
    }

}