|
|
@@ -24,14 +24,33 @@ class InventoryCompareImport implements ToCollection, WithHeadingRow, WithMultip
|
|
|
|
|
|
public function Collection(Collection $collection)
|
|
|
{
|
|
|
+ $array = $collection->toArray();
|
|
|
+ $skuName=(function()use($array){
|
|
|
+ if($array[0]['物料编号']??false) return '物料编号';
|
|
|
+ if($array[0]['SKU']??false) return 'SKU';
|
|
|
+ if($array[0]['产品编码']??false) return '产品编码';
|
|
|
+ })();
|
|
|
+ $amountName=(function()use($array){
|
|
|
+ if($array[0]['物料库存量']??false) return '物料库存量';
|
|
|
+ if($array[0]['库存量']??false) return '库存量';
|
|
|
+ if($array[0]['数量']??false) return '数量';
|
|
|
+ })();
|
|
|
+ $customLocationName=(function()use($array){
|
|
|
+ if($array[0]['仓库']??false) return '仓库';
|
|
|
+ if($array[0]['属性仓']??false) return '属性仓';
|
|
|
+ })();
|
|
|
+ $sku=$array[0][$skuName];
|
|
|
+ $amount=$array[0][$amountName];
|
|
|
+ $customLocation=$array[0][$customLocationName];
|
|
|
+
|
|
|
$endIS = false;
|
|
|
$skuAndWarehouseArr=[];
|
|
|
foreach ($collection as $row){
|
|
|
- $skuAndWarehouse=$row['产品编号'].$row['属性仓'];
|
|
|
+ $skuAndWarehouse=$row[$skuName].$row[$customLocationName];
|
|
|
array_push($skuAndWarehouseArr,$skuAndWarehouse);
|
|
|
}
|
|
|
$uniqueArr=array_unique($skuAndWarehouseArr);
|
|
|
- if (!isset($collection->toArray()[0]['产品编号']) || !isset($collection->toArray()[0]['数量']) || !isset($collection->toArray()[0]['属性仓'])) {
|
|
|
+ if (!isset($sku) || !isset($amount) || !isset($customLocation)) {
|
|
|
Cache::put('error', '请检查您第一行标题是否存在产品编号,数量,属性仓');
|
|
|
}elseif(count($uniqueArr)!=count($skuAndWarehouseArr)){
|
|
|
Cache::put('error', '产品编号+属性仓不能同时重复!');
|
|
|
@@ -42,29 +61,29 @@ class InventoryCompareImport implements ToCollection, WithHeadingRow, WithMultip
|
|
|
$sum = 2;
|
|
|
if ($endIS) {
|
|
|
foreach ($collection as $row) {
|
|
|
- if (!$row['产品编号']) {
|
|
|
+ if (!$row[$skuName]) {
|
|
|
array_push($exception, ['第' . $sum . '行产品编号为空!']);
|
|
|
$sum++;
|
|
|
continue;
|
|
|
- } else if (!$row['数量']) {
|
|
|
+ } else if (!$row[$amountName]) {
|
|
|
array_push($exception, ['第' . $sum . '行数量为空!']);
|
|
|
$sum++;
|
|
|
continue;
|
|
|
- } else if (!$row['属性仓']) {
|
|
|
+ } else if (!$row[$customLocationName]) {
|
|
|
array_push($exception, ['第' . $sum . '行属性仓为空!']);
|
|
|
$sum++;
|
|
|
continue;
|
|
|
}
|
|
|
- $hasSku=Commodity::where('owner_id',$this->owner_id)->where('sku',$row['产品编号'])->first();
|
|
|
+ $hasSku=Commodity::where('owner_id',$this->owner_id)->where('sku',$row[$skuName])->first();
|
|
|
if (!$hasSku){
|
|
|
- array_push($exception, ['该货主下不存在产品编号:'.$row['产品编号']]);
|
|
|
+ array_push($exception, ['该货主下不存在产品编号:'.$row[$skuName]]);
|
|
|
$sum++;
|
|
|
}
|
|
|
- $inventoryCompare=app('inventoryCompareService')->createInventoryCompare($row['产品编号'],$row['属性仓'],$row['数量'],$this->owner_id);
|
|
|
+ $inventoryCompare=app('inventoryCompareService')->createInventoryCompare($row[$skuName],$row[$customLocationName],$row[$amountName],$this->owner_id);
|
|
|
if ($inventoryCompare){
|
|
|
- array_push($exception, ['产品编号为:' . $row['产品编号'] . '库存对比创建成功!']);
|
|
|
+ array_push($exception, ['产品编号为:' . $row[$skuName] . '库存对比创建成功!']);
|
|
|
}else{
|
|
|
- array_push($exception, ['产品编号为:' . $row['产品编号'] . '库存对比创建失败!']);
|
|
|
+ array_push($exception, ['产品编号为:' . $row[$skuName] . '库存对比创建失败!']);
|
|
|
}
|
|
|
$sum++;
|
|
|
}
|