refactor: 产品详细接口关联产品字段添加spu返回
This commit is contained in:
@@ -91,8 +91,13 @@ class Product
|
|||||||
'related_product_id',
|
'related_product_id',
|
||||||
'sort'
|
'sort'
|
||||||
])
|
])
|
||||||
->productId($product->id
|
->with(['product' => function($query) {
|
||||||
)->select();
|
$query->field(['id', 'spu']);
|
||||||
|
}])
|
||||||
|
->productId($product->id)
|
||||||
|
->select()
|
||||||
|
->bindAttr('product', ['spu'])
|
||||||
|
->hidden(['product']);
|
||||||
|
|
||||||
return success('获取成功', $product);
|
return success('获取成功', $product);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ class ProductModel extends ProductBaseModel
|
|||||||
// 分类关联查询
|
// 分类关联查询
|
||||||
public function category()
|
public function category()
|
||||||
{
|
{
|
||||||
return $this->belongsTo('ProductCategoryModel', 'category_id', 'id');
|
return $this->belongsTo(ProductCategoryModel::class, 'category_id', 'id');
|
||||||
}
|
}
|
||||||
|
|
||||||
// 搜索器名称
|
// 搜索器名称
|
||||||
|
|||||||
@@ -11,6 +11,12 @@ use app\common\model\ProductRelatedBaseModel;
|
|||||||
*/
|
*/
|
||||||
class ProductRelatedModel extends ProductRelatedBaseModel
|
class ProductRelatedModel extends ProductRelatedBaseModel
|
||||||
{
|
{
|
||||||
|
// 关联产品模型
|
||||||
|
public function product()
|
||||||
|
{
|
||||||
|
return $this->belongsTo(ProductModel::class, 'related_product_id', 'id');
|
||||||
|
}
|
||||||
|
|
||||||
// 根据产品ID查询
|
// 根据产品ID查询
|
||||||
public function scopeProductId($query, $id)
|
public function scopeProductId($query, $id)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user