refactor: 产品详细接口添加sku数据返回
This commit is contained in:
@@ -90,6 +90,15 @@ class Product
|
||||
}
|
||||
$product->params = implode(PHP_EOL, $params);
|
||||
|
||||
// 获取sku数据
|
||||
$product->skus = ProductSkuModel::withoutField(['created_at', 'updated_at'])
|
||||
->with(['attrs' => function($query) {
|
||||
$query->hidden(['sku_id']);
|
||||
}])
|
||||
->productId($product->id)
|
||||
->select()
|
||||
->hidden(['id', 'product_id']);
|
||||
|
||||
// 获取关联产品
|
||||
$product->related = ProductRelatedModel::field([
|
||||
'related_product_id',
|
||||
|
||||
@@ -16,6 +16,12 @@ class ProductSkuModel extends ProductSkuBaseModel
|
||||
// 设置JSON数据返回数组
|
||||
protected $jsonAssoc = true;
|
||||
|
||||
// 关联产品sku属性
|
||||
public function attrs()
|
||||
{
|
||||
return $this->hasMany(ProductSkuAttrModel::class, 'sku_id', 'id');
|
||||
}
|
||||
|
||||
// 所属产品查询
|
||||
public function scopeProductId($query, $id)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user