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');