6
0
Fork 0
base
panliang 2022-08-12 15:00:16 +08:00
parent a30cd3e7e6
commit a3107bba64
2 changed files with 13 additions and 1 deletions

View File

@ -28,7 +28,11 @@ class ProductController extends AdminController
$list = $query->get();
$data = [];
foreach($list as $item) {
array_push($data, ['id' => $item->productSku->id, 'text' => $item->productSku->name]);
if ($item->productSku) {
array_push($data, ['id' => $item->productSku->id, 'text' => $item->productSku->name]);
} else {
logger()->error('店铺 商品 Sku 不存在, sku_id: ' . $item->product_sku_id);
}
}
return $data;
}

View File

@ -69,6 +69,14 @@ class ProductSku extends Model
'is_pre_sale',
];
public static function booted()
{
static::deleted(function ($model) {
// 删除店铺关联的 sku_id
ProductSku::where('product_sku_id', $model->id)->delete();
});
}
/**
* 仅查询已上架的商品
*