// +---------------------------------------------------------------------- namespace App\Models; /** * 商品管理-模型 * @author laravel开发员 * @since 2020/11/11 * @package App\Models */ class GoodsModel extends BaseModel { // 设置数据表 protected $table = 'goods'; // 封面图 public function getThumbAttribute($value) { $thumb = $value ? get_image_url($value) : get_image_url('/images/goods/goods.jpeg'); return $thumb; } public function setThumbAttribute($value) { return $value ? get_image_path($value) : ''; } /** * 图册 * @param $value * @return array|string */ public function getAlbumsAttribute($value) { $value = $value? get_images_preview($value,'url',2) : []; return $value; } public function getInfo($id) { $info = parent::getInfo($id); // TODO: Change the autogenerated stub return $info; } /** * 商家店铺 * @return \Illuminate\Database\Eloquent\Relations\HasOne */ public function store() { return $this->hasOne(StoreModel::class, 'id', 'store_id') ->select(['id','nickname','mobile','bonus_rate','status']); } /** * 关联商品分类 */ public function category() { return $this->hasOne(GoodsCategoryModel::class, 'id', 'category_id') ->select(['id', 'name', 'icon', 'status']); } /** * SKU */ public function sku() { return $this->hasOne(GoodsSkuModel::class, 'id', 'sku_id') ->where(['mark' => 1]); } /** * 关联商品规格(多规格) */ public function skus() { return $this->hasMany(GoodsSkuModel::class, 'goods_id', 'id') ->where(['mark' => 1, 'status' => 1]) ->orderBy('sort', 'desc'); } }