|
|
@@ -5,9 +5,7 @@ namespace App\Imports;
|
|
|
use App\Http\Controllers\CommodityController;
|
|
|
use App\Services\CommodityBarcodeService;
|
|
|
use App\Services\CommodityService;
|
|
|
-use App\Services\LogService;
|
|
|
use Carbon\Carbon;
|
|
|
-use Illuminate\Support\Arr;
|
|
|
use Illuminate\Support\Collection;
|
|
|
use Illuminate\Support\Facades\Cache;
|
|
|
use Maatwebsite\Excel\Concerns\ToCollection;
|
|
|
@@ -186,7 +184,7 @@ class StoreCheckingReceiveImport implements ToCollection,WithHeadingRow
|
|
|
$createCommodities = [];
|
|
|
$skus = [];
|
|
|
$skuMap = [];
|
|
|
- $date = Carbon::now();
|
|
|
+ $date = Carbon::now()->toDateTimeString();
|
|
|
foreach ($commodities as $arr){
|
|
|
foreach ($arr as $index){
|
|
|
$item = $items[$index];
|
|
|
@@ -196,7 +194,7 @@ class StoreCheckingReceiveImport implements ToCollection,WithHeadingRow
|
|
|
if (isset($skuMap[$sku])) $skuMap[$sku][] = $index;
|
|
|
else {
|
|
|
$skuMap[$sku] = [$index];
|
|
|
- $skus = $sku;
|
|
|
+ $skus[] = $sku;
|
|
|
|
|
|
$commodity = [
|
|
|
"name" => $item["商品名称"],
|
|
|
@@ -219,15 +217,19 @@ class StoreCheckingReceiveImport implements ToCollection,WithHeadingRow
|
|
|
|
|
|
//拿到商品ID录入条码
|
|
|
$barcodes = [];
|
|
|
- $date = Carbon::now();
|
|
|
+ $date = Carbon::now()->toDateTimeString();
|
|
|
$commoditiesTem = $commodityService->get(['owner_id'=>$owner->id, 'sku'=>$skus]);
|
|
|
+ $exist = [];
|
|
|
foreach ($commoditiesTem as $item){
|
|
|
foreach ($skuMap[$item->sku] as $index){
|
|
|
- $barcodes[] = [
|
|
|
- 'commodity_id' => $item->id,
|
|
|
- 'code' => $items[$index]["条码"],
|
|
|
- 'created_at' => $date,
|
|
|
- ];
|
|
|
+ if (!isset($exist[$item->id."_".$items[$index]["条码"]])){
|
|
|
+ $barcodes[] = [
|
|
|
+ 'commodity_id' => $item->id,
|
|
|
+ 'code' => $items[$index]["条码"],
|
|
|
+ 'created_at' => $date,
|
|
|
+ ];
|
|
|
+ $exist[$item->id."_".$items[$index]["条码"]] = true;
|
|
|
+ }
|
|
|
$items[$index]["commodity_id"] = $item->id;
|
|
|
unset($items[$index]["SKU"]);
|
|
|
unset($items[$index]["商品名称"]);
|
|
|
@@ -235,13 +237,12 @@ class StoreCheckingReceiveImport implements ToCollection,WithHeadingRow
|
|
|
}
|
|
|
}
|
|
|
if (count($barcodes) > 0){
|
|
|
- $commodityBarcodeService->insert(array_unique($barcodes));
|
|
|
+ $commodityBarcodeService->insert($barcodes);
|
|
|
app('LogService')->log(__METHOD__,"盘收导入录入条码",json_encode($barcodes));
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
if (count($items) < 1){
|
|
|
Cache::put("storeCheckingReceive",["success"=>false, "errors"=>$errors],86400);
|
|
|
return false;
|
|
|
@@ -251,13 +252,12 @@ class StoreCheckingReceiveImport implements ToCollection,WithHeadingRow
|
|
|
"created_at" => date('Y-m-d H:i:s'),
|
|
|
'status' => "已导入",
|
|
|
]);
|
|
|
- app('LogService')->log(__METHOD__,"导入盘收任务-录入盘收任务",json_encode($storeCheckingReceive,JSON_UNESCAPED_UNICODE));
|
|
|
- $storeCheckingReceive->owner_name = $owner_name;
|
|
|
+ $storeCheckingReceive->owner_name = $owner->name;
|
|
|
|
|
|
+ app('LogService')->log(__METHOD__,"导入盘收任务-录入盘收任务",json_encode($storeCheckingReceive,JSON_UNESCAPED_UNICODE));
|
|
|
foreach ($items as &$it){
|
|
|
$it["store_checking_receive_id"] = $storeCheckingReceive->id;
|
|
|
}
|
|
|
-
|
|
|
app('StoreCheckingReceiveItemService')->insert($items);
|
|
|
app('LogService')->log(__METHOD__,"导入盘收任务-批量录入盘收记录",json_encode($items,JSON_UNESCAPED_UNICODE));
|
|
|
|