mirror of
https://gitee.com/hzchunfen/erp.git
synced 2025-12-01 06:30:49 +00:00
commit
ee864ea5f6
@ -58,16 +58,16 @@ class GoodsSkusImport implements ToCollection, SkipsEmptyRows
|
|||||||
if ($validator->fails()) {
|
if ($validator->fails()) {
|
||||||
throw new ValidationException($validator);
|
throw new ValidationException($validator);
|
||||||
}
|
}
|
||||||
$types = GoodsType::query()->whereIn('name', $types)->get(['id', 'name'])->toArray();
|
$types = GoodsType::query()->whereIn('name', $types)->pluck('id', 'name')->toArray();
|
||||||
$types = ArrayUtils::index($types, 'name');
|
|
||||||
$brands = GoodsBrand::query()->whereIn('name', $brands)->get(['id', 'name'])->toArray();
|
$brands = GoodsBrand::query()->whereIn('name', $brands)->pluck('id', 'name')->toArray();
|
||||||
$brands = ArrayUtils::index($brands, 'name');
|
|
||||||
$hasGoods = Goods::query()->whereIn('goods_code', $goodsCodes)->get(['id', 'goods_code'])->toArray();
|
$hasGoods = Goods::query()->whereIn('goods_code', $goodsCodes)->pluck('id', 'goods_code')->toArray();
|
||||||
$hasGoods = ArrayUtils::index($hasGoods, 'goods_code');
|
|
||||||
$newGoods = $skus = [];
|
$newGoods = $skus = [];
|
||||||
foreach ($collection as $row) {
|
foreach ($collection as $row) {
|
||||||
$sku = [
|
$sku = [
|
||||||
'goods_id' => $row[3],
|
'goods_code' => $row[3],
|
||||||
'title' => $row[4],
|
'title' => $row[4],
|
||||||
'sku_code' => $row[5],
|
'sku_code' => $row[5],
|
||||||
'status' => $this->statusMap[$row[6]],
|
'status' => $this->statusMap[$row[6]],
|
||||||
@ -75,15 +75,15 @@ class GoodsSkusImport implements ToCollection, SkipsEmptyRows
|
|||||||
'cost' => $row[8],
|
'cost' => $row[8],
|
||||||
];
|
];
|
||||||
// 主商品已存在
|
// 主商品已存在
|
||||||
if (isset($hasGoods[$row[3]])) {
|
if (isset($hasGoods[$sku['goods_code']])) {
|
||||||
$sku['goods_id'] = $hasGoods[$row[3]]['id'];
|
$sku['goods_id'] = $hasGoods[$sku['goods_code']];
|
||||||
} else {
|
} else {
|
||||||
// 新商品
|
// 新商品
|
||||||
$newGoods[$row[3]] = [
|
$newGoods[$sku['goods_code']] = [
|
||||||
'title' => $row[0],
|
'title' => $row[0],
|
||||||
'type_id' => $types[$row[1]]['id'],
|
'type_id' => $types[$row[1]],
|
||||||
'brand_id' => $brands[$row[2]]['id'],
|
'brand_id' => $brands[$row[2]],
|
||||||
'goods_code' => $row[3],
|
'goods_code' => $sku['goods_code'],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
$skus[] = $sku;
|
$skus[] = $sku;
|
||||||
@ -93,11 +93,11 @@ class GoodsSkusImport implements ToCollection, SkipsEmptyRows
|
|||||||
if ($newGoods) {
|
if ($newGoods) {
|
||||||
$goods = new Goods();
|
$goods = new Goods();
|
||||||
$goods->batchInsert(array_values($newGoods));
|
$goods->batchInsert(array_values($newGoods));
|
||||||
$hasGoods = Goods::query()->whereIn('goods_code', array_column($newGoods, 'goods_code'))->get(['id', 'goods_code'])->toArray();
|
$hasGoods = Goods::query()->whereIn('goods_code', array_column($newGoods, 'goods_code'))->pluck('id', 'goods_code')->toArray();
|
||||||
$hasGoods = ArrayUtils::index($hasGoods, 'goods_code');
|
|
||||||
foreach ($skus as &$newGoodsSku) {
|
foreach ($skus as &$newGoodsSku) {
|
||||||
$newGoodsSku['goods_id'] = isset($hasGoods[$newGoodsSku['goods_id']]) ? $hasGoods[$newGoodsSku['goods_id']]['id'] : $newGoodsSku['goods_id'];
|
$newGoodsSku['goods_id'] = $hasGoods[$newGoodsSku['goods_code']];
|
||||||
$newGoodsSku['external_sku_id'] = isset($hasGoods[$newGoodsSku['goods_id']]) ? $hasGoods[$newGoodsSku['goods_id']]['goods_code'] . '_' . $newGoodsSku['sku_code'] : '';
|
$newGoodsSku['external_sku_id'] = $newGoodsSku['goods_code'] . '_' . $newGoodsSku['sku_code'];
|
||||||
|
unset($newGoodsSku['goods_code']);
|
||||||
}
|
}
|
||||||
unset($newGoodsSku);
|
unset($newGoodsSku);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user