public function getSheetData($inputFileName)
{
vendor("PhpExcel.PHPExcel");
$objPHPExcel = new \PHPExcel();
//$inputFileName "D:/360/test1.xlsx"
$objPHPExcel = \PHPExcel_IOFactory::load($inputFileName);
$sheetData = $objPHPExcel->getActiveSheet()->toArray(null, true, true, true);
return $sheetData;
}
//导入产品分类
public function importProductKind($inputFileName)
{
$data = $this->getSheetData($inputFileName);
$kinds = array();
foreach ($data as $k => $v) {
if ($k > 1 && !empty($v['A']) && !empty($v['B'])) {
$temp = array();
$temp['pd_kind_id'] = $v['A'];
$temp['pd_kind_name'] = $v['B'];
$temp['pd_kind_pid'] = $v['C'];
$temp['create_time'] = date('Y-m-d H:i:s');
array_push($kinds, $temp);
}
}
$ids = array_column($kinds, "pd_kind_id");
if (count($ids) == 0) {
E("未获取到文件数据或文件内容为空", 1005);
}
$where = array();
$where['pd_kind_id'] = array('in', $ids);
$where['del_flag'] = Constants::DEL_NO;
$repeatIds = M('ProductKind')->where($where)->select();
if (empty($repeatIds)) {
M()->startTrans();
try {
$res = M('ProductKind')->addAll($kinds);
$data = M('ProductKind')->where(array('del_flag' => 0))->select();
$list = array();
$list = $this->recursionFunc($list, $data);
$id = $this->updateKindPath($list);
M()->commit();
return $id;
} catch (\Exception $e) {
M()->rollback();
$errStr = $e->getMessage();
if (empty($errStr)) {
$errStr = "插入失败,可能是数据不规范";
}
E($errStr, 1005);
}
} else {
$repeatStr = "";
foreach ($repeatIds as $k => $v) {
$repeatStr .= "," . $v['pd_kind_id'];
}
$repeatStr = substr($repeatStr, 1);
E("id:'" . $repeatStr . "'已存在", 1005);
}
}