From 2fa22678320f57401dc965746017596d84eb8cef Mon Sep 17 00:00:00 2001 From: lewis <604446095@qq.com> Date: Wed, 12 Feb 2025 17:12:21 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=AF=BC=E5=85=A5=E5=95=86?= =?UTF-8?q?=E5=93=81=E4=BB=B7=E6=A0=BC=E6=AF=94=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/admin/controller/LocalController.php | 33 ++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/app/admin/controller/LocalController.php b/app/admin/controller/LocalController.php index 173bd8536..8834ac5f7 100644 --- a/app/admin/controller/LocalController.php +++ b/app/admin/controller/LocalController.php @@ -160,6 +160,39 @@ class LocalController extends BaseAdminController return $this->success('数据已更新完成', $sql); } + public function updateProductPriceList() + { + $file = $this->request->file('file'); + $reader = IOFactory::createReader('Xlsx'); + $spreadsheet = $reader->load($file->getRealPath()); + $data = $spreadsheet->getActiveSheet()->toArray(); + $updateCount = 0; + $insert = []; + $time = time(); + foreach ($data as $k => $row) { + if ($k < 1 || empty($row[0])) { + continue; + } + $product = StoreProduct::where('id', $row[0])->value('id'); + if (empty($product)) { + continue; + } + for ($i = 1; $i < 5; $i++) { + if (empty($row[1 + $i])) { + continue; + } + $insert[] = [ + 'product_id' => $row[0], + 'price_type' => $i, + 'rate' => intval(rtrim($row[1 + $i], '%')) + 100, + 'create_time' => $time, + ]; + } + } + StoreProductPriceList::insertAll($insert); + return $this->success('更新成功:' . $updateCount . '条'); + } + public function index() { $file = $this->request->file('file');