From 48751596797a2b6d580028a9b105aa4efab57d4d Mon Sep 17 00:00:00 2001 From: sjeam <359824901@qq.com> Date: Mon, 7 Apr 2025 12:10:28 +0800 Subject: [PATCH] =?UTF-8?q?excel=E5=AF=BC=E5=85=A5=E9=93=BA=E8=B4=A7?= =?UTF-8?q?=E3=80=82=E4=BF=AE=E6=94=B9=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/admin/controller/LocalController.php | 89 +++++++++++------------- 1 file changed, 41 insertions(+), 48 deletions(-) diff --git a/app/admin/controller/LocalController.php b/app/admin/controller/LocalController.php index a5ca45006..a1a256096 100644 --- a/app/admin/controller/LocalController.php +++ b/app/admin/controller/LocalController.php @@ -521,57 +521,50 @@ class LocalController extends BaseAdminController $file = $this->request->file('file'); $reader = IOFactory::createReader('Xlsx'); $spreadsheet = $reader->load($file->getRealPath()); - $sheets = $spreadsheet->getAllSheets(); + $sheets = $spreadsheet->getActiveSheet()->toArray(); $new_params = []; - foreach ($sheets as $sheetIndex => $sheet) { - $rows = $sheet->toArray(); - foreach ($rows as $k => $row) { - if ($k < 1 || empty($row[0])) { - continue; - } - $system_store_id = SystemStore::where('name', $row[1])->value('id'); - $product = StoreBranchProduct::where('product_id', $row[0])->where('store_id', $system_store_id)->field('id,product_id,stock')->findOrEmpty(); - if ($row[10] == $product->stock && $product->stock != 0) { - // 生成铺货单 - $params = []; - $params['after_nums'] = ''; - $params['before_nums'] = ''; - $params['id'] = $row[0]; - $params['mark'] = "门店铺货-excel导入"; - $params['nums'] = $row[2]; - $params['one_id'] = $system_store_id; //门店id - $params['one_name'] = ""; - $params['one_type'] = 1; //1门店2仓库 - $params['product_arr'] = [ - [ - 'nums' => $row[10], - 'product_id' => $product->product_id, - 'purchase' => 0, - 'total_price' => $product->total_price, - ] - ]; - $params['product_id'] = $row[0]; - $params['product_name'] = ""; - $params['two_id'] = 1; //1海吉星仓库 - $params['two_name'] = ""; - $params['two_type'] = 2; //1门店2仓库 - $params['types'] = 1; //0减库存 1不减库存 - $params['warehouse_name'] = ""; - $params['warehouse_name_two'] = ""; - InventoryTransferOrderLogic::add($params, $this->adminId); - } else { - - $arr = []; - $arr['product_id'] = $row[0]; - $arr['store_id'] = $system_store_id; - $arr['nums'] = $row[10] ?? 0; - $arr['stock'] = $product['stock'] ?? 0; - $new_params[] = $arr; - } + $params = []; + $system_store_id = 0; + $params['product_arr'] = []; + foreach ($sheets as $key => $row) { + if ($key == 0) { + continue; + } + if (!$system_store_id) { + $system_store_id = SystemStore::where('name', $row[1])->value('id'); + } + $product = StoreBranchProduct::where('product_id', $row[0])->where('store_id', $system_store_id)->field('id,product_id,stock')->findOrEmpty(); + if ($row[10] == $product->stock && $product->stock) { + $arr = [ + 'nums' => $row[10], + 'product_id' => $product->product_id, + 'purchase' => 0, + 'total_price' => $product->total_price, + ]; + $params['product_arr'][] = $arr; + } else { + $arr = []; + $arr['product_id'] = $row[0]; + $arr['product_name'] = $row[2] ?? ''; + $arr['store_id'] = $system_store_id; + $arr['nums'] = $row[10] ?? 0; + $arr['stock'] = $product->stock ?? 0; + $new_params[] = $arr; } - $dataArray = json_encode($new_params, true); - file_put_contents(public_path() . '/output.text', $dataArray); } + // 生成铺货单 + $params['id'] = $row[0]; + $params['mark'] = "门店铺货-excel导入"; + // $params['nums'] = $row[2]; + $params['one_id'] = $system_store_id; //门店id + $params['one_type'] = 1; //1门店2仓库 + $params['two_id'] = 1; //1海吉星仓库 + $params['two_type'] = 2; //1门店2仓库 + $params['types'] = 1; //0减库存 1不减库存 + + InventoryTransferOrderLogic::add($params, $this->adminId); + $new_params = json_encode($new_params, true); + file_put_contents(public_path() . '/output.text', $new_params); return $this->success('导入成功'); } }