// 关联查询(商品图片、sku列表) $with = ['images.file', 'skuList.image', 'video', 'videoCover']; // 获取商品记录 $goodsInfo = $this->getGoodsMain($goodsId, $with, $verifyStatus);
时间: 2024-03-14 14:48:33 浏览: 16
这段代码是使用ThinkPHP的ORM进行关联查询的示例。$with数组中存放的是要查询的关联模型,其中'images.file'表示关联模型为images,images模型又与file模型有关联关系,'skuList.image'表示关联模型为skuList,skuList模型又与image模型有关联关系,'video'和'videoCover'则分别表示关联模型为video和videoCover。
在getGoodsMain()方法中,会使用with()方法来指定要查询的关联模型:
```php
// 关联查询(商品图片、sku列表)
$with = ['images.file', 'skuList.image', 'video', 'videoCover'];
// 获取商品记录
$goodsInfo = $this->getGoodsMain($goodsId, $with, $verifyStatus);
public function getGoodsMain($goodsId, $with, $verifyStatus = 0)
{
// 查询条件
$map = [
'id' => $goodsId,
'verify_status' => $verifyStatus,
];
// 关联查询
$goodsInfo = $this->with($with)->where($map)->find();
return $goodsInfo;
}
```
这样就可以查询到与商品相关的图片、sku列表、视频和视频封面等信息,并将其存储在$goodsInfo变量中返回。