商品列表、分类管理、客户等级
This commit is contained in:
@@ -31,7 +31,7 @@ class ProductModel extends Model
|
||||
'name',
|
||||
'spec',
|
||||
'unit',
|
||||
'images',
|
||||
'image_ids',
|
||||
'content',
|
||||
'sort',
|
||||
'shelf_life',
|
||||
@@ -47,22 +47,32 @@ class ProductModel extends Model
|
||||
'stock' => 'integer',
|
||||
'sort' => 'integer',
|
||||
'status' => 'integer',
|
||||
'created_at' => 'datetime:Y-m-d H:i:s',
|
||||
'updated_at' => 'datetime:Y-m-d H:i:s',
|
||||
];
|
||||
|
||||
public function images(): Attribute
|
||||
protected $appends = ['images_arr'];
|
||||
|
||||
/**
|
||||
* 封面图片
|
||||
*/
|
||||
public function imageIds(): Attribute
|
||||
{
|
||||
return Attribute::make(
|
||||
get: function($value){
|
||||
if (empty($value)) {
|
||||
return collect();
|
||||
}
|
||||
$ids = explode(',', $value);
|
||||
return SysFileModel::whereIn('id', $ids)->get();
|
||||
},
|
||||
get: fn ($value) => explode(',', $value),
|
||||
set: fn ($value) => is_array($value) ? implode(',', $value) : $value,
|
||||
);
|
||||
}
|
||||
|
||||
// 获取封面图片关联数据
|
||||
public function getImagesArrAttribute(): array
|
||||
{
|
||||
if( $this->image_ids ) {
|
||||
return SysFileModel::whereIn('id', $this->image_ids )->get()->toArray();
|
||||
}
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* 所属分类
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user