...
|
...
|
@@ -96,6 +96,8 @@ class Litestoregoods extends Backend |
|
|
|
|
|
return json($result);
|
|
|
}
|
|
|
$this->assign('template', $this->request->domain() . '/static/template/商品导入模板.xlsx');
|
|
|
|
|
|
return $this->view->fetch();
|
|
|
}
|
|
|
|
...
|
...
|
@@ -436,23 +438,22 @@ class Litestoregoods extends Backend |
|
|
if (!$PHPExcel = $reader->load($filePath)) {
|
|
|
$this->error(__('Unknown data format'));
|
|
|
}
|
|
|
$currentSheet = $PHPExcel->getSheet(0); //读取文件中的第一个工作表
|
|
|
$allColumn = $currentSheet->getHighestDataColumn(); //取得最大的列号
|
|
|
$allRow = $currentSheet->getHighestRow(); //取得一共有多少行
|
|
|
$currentSheet = $PHPExcel->getSheet(0); //读取文件中的第一个工作表
|
|
|
$allColumn = $currentSheet->getHighestDataColumn(); //取得最大的列号
|
|
|
$allRow = $currentSheet->getHighestRow(); //取得一共有多少行
|
|
|
$maxColumnNumber = Coordinate::columnIndexFromString($allColumn); // 一共多少列
|
|
|
for ($i = 2; $i <= $allRow; $i++) {
|
|
|
if (!empty($PHPExcel->getActiveSheet()->getCell("A" . $i)->getValue())) {
|
|
|
$insert[$i]['goods_name'] = $PHPExcel->getActiveSheet()->getCell("B" . $i)->getValue();//商品名称
|
|
|
$insert[$i]['keywords'] = $PHPExcel->getActiveSheet()->getCell("C" . $i)->getValue();//关键词
|
|
|
$category = $PHPExcel->getActiveSheet()->getCell("D" . $i)->getValue() ?? '';//类别
|
|
|
$insert[$i]['goods_name'] = $PHPExcel->getActiveSheet()->getCell("A" . $i)->getValue();//商品名称
|
|
|
$insert[$i]['keywords'] = $PHPExcel->getActiveSheet()->getCell("B" . $i)->getValue();//关键词
|
|
|
$category = $PHPExcel->getActiveSheet()->getCell("C" . $i)->getValue() ?? '';//类别
|
|
|
$insert[$i]['category_id'] = Db::name('litestore_category')->where('name', $category)->value('id') ?? '';
|
|
|
$insert[$i]['activity_id'] = $PHPExcel->getActiveSheet()->getCell("E" . $i)->getValue() ?? '';//活动类型
|
|
|
$insert[$i]['spec_type'] = $PHPExcel->getActiveSheet()->getCell("F" . $i)->getValue() ?? '';//规格类型
|
|
|
$insert[$i]['is_index'] = $PHPExcel->getActiveSheet()->getCell("N" . $i)->getValue() ?? '';//是否首页
|
|
|
$insert[$i]['goods_status'] = $PHPExcel->getActiveSheet()->getCell("M" . $i)->getValue() ?? '';//商品状态
|
|
|
$spec_insert[$i]['stock_num'] = $PHPExcel->getActiveSheet()->getCell("G" . $i)->getValue() ?? '';//库存
|
|
|
$spec_insert[$i]['goods_price'] = $PHPExcel->getActiveSheet()->getCell("K" . $i)->getValue() ?? '';//现价
|
|
|
$spec_insert[$i]['line_price'] = $PHPExcel->getActiveSheet()->getCell("I" . $i)->getValue() ?? '';//原价
|
|
|
$insert[$i]['activity_id'] = $PHPExcel->getActiveSheet()->getCell("D" . $i)->getValue() ?? '';//活动类型
|
|
|
$insert[$i]['is_index'] = $PHPExcel->getActiveSheet()->getCell("I" . $i)->getValue() ?? '';//是否首页
|
|
|
$insert[$i]['goods_status'] = $PHPExcel->getActiveSheet()->getCell("H" . $i)->getValue() ?? '';//商品状态
|
|
|
$spec_insert[$i]['stock_num'] = $PHPExcel->getActiveSheet()->getCell("E" . $i)->getValue() ?? '';//库存
|
|
|
$spec_insert[$i]['goods_price'] = $PHPExcel->getActiveSheet()->getCell("G" . $i)->getValue() ?? '';//现价
|
|
|
$spec_insert[$i]['line_price'] = $PHPExcel->getActiveSheet()->getCell("F" . $i)->getValue() ?? '';//原价
|
|
|
}
|
|
|
}
|
|
|
} catch (\Exception $exception) {
|
...
|
...
|
@@ -464,9 +465,8 @@ class Litestoregoods extends Backend |
|
|
try {
|
|
|
|
|
|
$res_goods = $this->model->saveAll($insert);
|
|
|
halt($res_goods);
|
|
|
foreach ($spec_insert as $key => &$v) {
|
|
|
$v['goods_id'] = $res_goods[$key]['id'];
|
|
|
$v['goods_id'] = $res_goods[$key]['goods_id'];
|
|
|
}
|
|
|
unset($v);
|
|
|
$this->spec_model->saveAll($spec_insert);
|
...
|
...
|
|