fix: 产品详情接口未找到产品时报错误问题
All checks were successful
Gitea Actions Official-website / deploy-dev (push) Successful in 2s

This commit is contained in:
2026-03-28 11:46:23 +08:00
parent 90b4bccbcf
commit 8a9d66f5d3

View File

@@ -24,7 +24,7 @@ class Product
'category_id', 'category_id',
'created_at', 'created_at',
'is_show', 'is_show',
'page/d' => 1, 'page/d' => 1,
'size/d' => 10 'size/d' => 10
]); ]);
@@ -83,7 +83,7 @@ class Product
]) ])
->bypk(request()->param('id')) ->bypk(request()->param('id'))
->find() ->find()
->bindAttr('category', ['category_name']) ?->bindAttr('category', ['category_name'])
->hidden(['category']); ->hidden(['category']);
if (empty($product)) { if (empty($product)) {
return error('产品不存在'); return error('产品不存在');
@@ -108,7 +108,7 @@ class Product
// 获取关联产品 // 获取关联产品
$product->related = ProductRelatedModel::field([ $product->related = ProductRelatedModel::field([
'related_product_id', 'related_product_id',
'sort' 'sort'
]) ])
->with(['product' => function($query) { ->with(['product' => function($query) {
@@ -149,8 +149,8 @@ class Product
'seo_desc' 'seo_desc'
]); ]);
$put = array_merge( $put = array_merge(
$put, $put,
['skus' => json_decode($put['skus'], true)], ['skus' => json_decode($put['skus'], true)],
['related' => json_decode($put['related'], true)], ['related' => json_decode($put['related'], true)],
); );
@@ -305,7 +305,7 @@ class Product
return success('操作成功'); return success('操作成功');
} }
// 导出 // 导出
public function export() public function export()
{ {
@@ -444,7 +444,7 @@ class Product
}); });
} }
} }
return $products->toArray(); return $products->toArray();
} }
} }