update sku mapping
This commit is contained in:
@@ -102,6 +102,37 @@ class SkuService
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 唯一性检查:匹配数据库新唯一索引 (origin_sku_id, platform_id, platform_outer_sku)
|
||||
*
|
||||
* 用于 create/update 前的预检,避免击中索引冲突返回 500
|
||||
*/
|
||||
public function isUniqueMapping(
|
||||
int $origin_sku_id,
|
||||
int $platform_id,
|
||||
string $platform_outer_sku,
|
||||
?int $exclude_id = null,
|
||||
): bool {
|
||||
$query = SkuMapping::query()
|
||||
->where('origin_sku_id', $origin_sku_id)
|
||||
->where('platform_id', $platform_id)
|
||||
->where('platform_outer_sku', $platform_outer_sku);
|
||||
|
||||
if ($exclude_id !== null) {
|
||||
$query->where('id', '!=', $exclude_id);
|
||||
}
|
||||
|
||||
return !$query->exists();
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取 skus_origin.sku,用作 skus_mapping.origin_sku 快照值
|
||||
*/
|
||||
public function autoFillOriginSku(int $origin_sku_id): ?string
|
||||
{
|
||||
return SkuOrigin::query()->find($origin_sku_id)?->sku;
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查 origin_sku 是否有映射引用(用于删除前检查)
|
||||
*/
|
||||
@@ -111,20 +142,4 @@ class SkuService
|
||||
->where('origin_sku_id', $origin_sku_id)
|
||||
->exists();
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查 platform_outer_sku 在指定平台内是否唯一
|
||||
*/
|
||||
public function isPlatformOuterSkuUnique(string $platform_outer_sku, int $platform_id, ?int $exclude_id = null): bool
|
||||
{
|
||||
$query = SkuMapping::query()
|
||||
->where('platform_outer_sku', $platform_outer_sku)
|
||||
->where('platform_id', $platform_id);
|
||||
|
||||
if ($exclude_id !== null) {
|
||||
$query->where('id', '!=', $exclude_id);
|
||||
}
|
||||
|
||||
return !$query->exists();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user