615 行
25 KiB
PHP
可执行文件
615 行
25 KiB
PHP
可执行文件
<?php
|
||
|
||
namespace Common\Business;
|
||
|
||
//[1.8.50]
|
||
|
||
/**
|
||
* 下载类
|
||
* Class DownFile
|
||
* [
|
||
* 下载指定路径文件 downFile
|
||
* 打包并下载压缩包 downloadZip
|
||
* 添加文件到压缩包 addFileToZip
|
||
* 删除目录下的所有文件 delDirFile
|
||
* 商品导入模板下载 GoodsTemplate
|
||
* 导入商品失败文件下载 GoodsImportFail
|
||
* 读取上传的文件 readFile
|
||
* 读取上传的文件新版 readFile_v1
|
||
* ]
|
||
* @package Common\Business
|
||
*/
|
||
class DownFile
|
||
{
|
||
/**
|
||
* 下载指定路径文件
|
||
* @param $param
|
||
* [
|
||
* file_path 路径
|
||
* file_name 文件名
|
||
* file_type 文件类型
|
||
* ]
|
||
*/
|
||
public function downFile($param)
|
||
{
|
||
$filename = realpath($param['file_path']); //文件名
|
||
$file_name = $param['file_name'] . $param['file_type'];
|
||
Header("Content-type: application/octet-stream ");
|
||
Header("Accept-Ranges: bytes ");
|
||
Header("Accept-Length: " . filesize($filename));
|
||
header("Content-Disposition: attachment; filename= {$file_name}");
|
||
readfile($filename);
|
||
unlink($param['file_path']);
|
||
}
|
||
|
||
|
||
/**
|
||
* 打包并下载压缩包
|
||
* @param $param
|
||
* [
|
||
* directory_name 文件夹路径
|
||
* zip_name 压缩包名称
|
||
* store_arr 门店集合[id=>name]
|
||
* file_name_arr 文件名集合[id=>name]
|
||
* file_type 压缩包中文件的后缀
|
||
* ]
|
||
*/
|
||
public function downloadZip($param)
|
||
{
|
||
header("Content-Type:text/html;charset=utf-8");
|
||
$directory_name = $param['directory_name'];
|
||
$zip_name = $param['zip_name'];
|
||
$file_type = $param['file_type'];
|
||
$file_name_arr = $param['file_name_arr'];
|
||
$store_arr = $param['store_arr'];
|
||
if (!is_dir($directory_name)) {
|
||
echo '文件不存在';
|
||
}
|
||
try {
|
||
$zip = new \ZipArchive();
|
||
$zip_url = $directory_name . '/' . $zip_name . date('Y-m-d_H_i_s') . '.zip';
|
||
if ($zip->open($zip_url, \ZipArchive::CREATE) === TRUE) {
|
||
$this->addFileToZip($directory_name, $zip, $store_arr, $file_name_arr, $file_type); //调用方法,对要打包的根目录进行操作,并将ZipArchive的对象传递给方法
|
||
$zip->close(); //关闭处理的zip文件
|
||
if (!file_exists($zip_url)) { //判断文件是否存在
|
||
echo "文件不存在";
|
||
exit();
|
||
}
|
||
$file = fopen($zip_url, "r");
|
||
Header("Content-type:application/octet-stream");
|
||
header("Accept-Ranges: bytes");
|
||
header("Accept-Length: " . filesize($zip_url));
|
||
header("Content-Disposition: attachment; filename={$zip_name}" . date('Y-m-d_H:i:s') . ".zip");
|
||
echo fread($file, filesize($zip_url));
|
||
fclose($file);
|
||
$this->delDirFile($directory_name); //删除文件夹下的所有文件
|
||
rmdir($directory_name); //删除当前文件夹
|
||
unlink($zip_url); //删除压缩包
|
||
}
|
||
} catch (\Exception $e) {
|
||
echo '文件不存在';
|
||
}
|
||
}
|
||
|
||
|
||
/**
|
||
* 添加文件到压缩包
|
||
* @param $path
|
||
* @param $zip
|
||
* @param store_arr 门店集合[id=>name] 或者 门店的名称 arr|string
|
||
* @param file_name_arr 文件名集合[id=>name] 或者文件的名称 arr|string
|
||
* @param string $file_type 文件后缀
|
||
*/
|
||
public function addFileToZip($path, $zip, $store_arr, $file_name_arr, $file_type = 'txt')
|
||
{
|
||
header("Content-Type:text/html;charset=utf-8");
|
||
$handler = opendir($path); //打开当前文件夹由$path指定。
|
||
while (($filename = readdir($handler)) !== false) {
|
||
if ($filename != "." && $filename != "..") { //文件夹文件名字为'.'和‘..',不要对他们进行操作
|
||
if (is_dir($path . "/" . $filename)) { // 如果读取的某个对象是文件夹,则递归
|
||
$this->addFileToZip($path . "/" . $filename, $zip, $store_arr, $file_name_arr, $file_type);
|
||
} else { //将文件加入zip对象
|
||
$name = '';
|
||
$new_filename = explode('_', $filename); //服务器文件的名称
|
||
if (!empty($store_arr) && is_array($store_arr)) {
|
||
$name .= $store_arr[$new_filename[0]] . '的';
|
||
} else {
|
||
$name .= $store_arr;
|
||
}
|
||
if (!empty($file_name_arr) && is_array($file_name_arr)) {
|
||
$name .= $file_name_arr[$new_filename[1]];
|
||
} else {
|
||
$name .= $file_name_arr;
|
||
}
|
||
$name = ($name ? $name : 'w') . '.' . $file_type;
|
||
$dir = iconv("utf-8", "gb2312", $name);
|
||
$zip->addFile($path . "/" . $filename, $dir);
|
||
}
|
||
}
|
||
}
|
||
@closedir($handler);
|
||
}
|
||
|
||
|
||
/**
|
||
* 删除目录下的所有文件
|
||
* @param $dir 目录地址
|
||
*/
|
||
public function delDirFile($dir)
|
||
{
|
||
$dh = opendir($dir);
|
||
while ($file = readdir($dh)) {
|
||
if ($file != "." && $file != "..") {
|
||
$full_path = $dir . "/" . $file;
|
||
if (!is_dir($full_path)) {
|
||
unlink($full_path);
|
||
} else {
|
||
$this->delDirFile($full_path);
|
||
}
|
||
}
|
||
}
|
||
|
||
closedir($dh);
|
||
}
|
||
|
||
|
||
/**
|
||
* 图片
|
||
* @param $url
|
||
* @return string
|
||
*/
|
||
public function image($url)
|
||
{
|
||
$header = array(
|
||
'User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:45.0) Gecko/20100101 Firefox/45.0',
|
||
'Accept-Language: zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3',
|
||
'Accept-Encoding: gzip, deflate',);
|
||
|
||
$curl = curl_init();
|
||
curl_setopt($curl, CURLOPT_URL, $url);
|
||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
|
||
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
|
||
curl_setopt($curl, CURLOPT_ENCODING, 'gzip');
|
||
curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
|
||
$data = curl_exec($curl);
|
||
$code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
|
||
curl_close($curl);
|
||
if ($code == 200) {//把URL格式的图片转成base64_encode格式的!
|
||
$imgBase64Code = "data:image/jpeg;base64," . base64_encode($data);
|
||
}
|
||
$img_content = $imgBase64Code;//图片内容
|
||
if (preg_match('/^(data:\s*image\/(\w+);base64,)/', $img_content, $result)) {
|
||
$type = $result[2];//得到图片类型png?jpg?gif?
|
||
$fileData = base64_decode(str_replace($result[1], '', $img_content));
|
||
$image_name = "headimg." . $type;
|
||
$upload_dir = './upload/img/';
|
||
if (!file_exists($upload_dir)) {
|
||
mkdir($upload_dir, 0777, true);
|
||
}
|
||
$filedir = $upload_dir . '/' . $image_name;
|
||
$src = './upload/img/' . $image_name;
|
||
if (file_put_contents($filedir, $fileData)) {
|
||
return $src;
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
/**
|
||
* 商品导入模板下载
|
||
* @param $platform_type
|
||
* [
|
||
* platform_type 商户平台类型 1默认系统 2微礼平台
|
||
* ]
|
||
*/
|
||
public function GoodsTemplate($platform_type = 1)
|
||
{
|
||
$type = I('get.attribute_state');
|
||
switch ($platform_type) {
|
||
case 1:
|
||
switch ($type) {
|
||
case 1:
|
||
//无规格
|
||
$url = './Public/flow/zip/GoodsTemplate.xls';
|
||
break;
|
||
case 2:
|
||
//规格
|
||
$url = './Public/flow/zip/SkuGoodsTemplate.xls';
|
||
}
|
||
break;
|
||
case 2:
|
||
switch ($type) {
|
||
case 1:
|
||
//无规格
|
||
$url = './Public/flow/zip/ThirdGoodsTemplate.xls';
|
||
break;
|
||
case 2:
|
||
//规格
|
||
$url = './Public/flow/zip/ThirdSkuGoodsTemplate.xls';
|
||
}
|
||
break;
|
||
}
|
||
if (!file_exists($url)) { //判断文件是否存在
|
||
echo "文件不存在";
|
||
exit();
|
||
}
|
||
$file = fopen($url, "r");
|
||
Header("Content-type:application/octet-stream");
|
||
header("Accept-Ranges: bytes");
|
||
header("Accept-Length: " . filesize($url));
|
||
header("Content-Disposition: attachment; filename=导入模板.xls");
|
||
echo fread($file, filesize($url));
|
||
fclose($file);
|
||
}
|
||
|
||
|
||
/**
|
||
* 导入商品失败文件下载
|
||
* @param $parameter
|
||
* [
|
||
* platform_type 商户平台类型 1默认系统 2微礼平台
|
||
* user_type 3商户后台 4门店后台
|
||
* merchant_id
|
||
* store_id
|
||
* attribute_state 1无规格 2规格
|
||
* ]
|
||
* @throws \PHPExcel_Exception
|
||
* @throws \PHPExcel_Reader_Exception
|
||
* @throws \PHPExcel_Writer_Exception
|
||
*/
|
||
public function GoodsImportFail($parameter)
|
||
{
|
||
switch ($parameter['platform_type']) {
|
||
case 1:
|
||
switch ($parameter['user_type']) {
|
||
case 3:
|
||
//商户
|
||
switch ($parameter['attribute_state']) {
|
||
case 1:
|
||
$path2 = './Uploads/Temp/Mgoodsinport' . $parameter['merchant_id'] . '.txt';
|
||
break;
|
||
case 2:
|
||
$path2 = './Uploads/Temp/MSkugoodsinport' . $parameter['merchant_id'] . '.txt';
|
||
break;
|
||
}
|
||
break;
|
||
case 4:
|
||
//门店
|
||
switch ($parameter['attribute_state']) {
|
||
case 1:
|
||
$path2 = './Uploads/Temp/StoreGoodsImport' . $parameter['merchant_id'] . $parameter['store_id'] . '.txt';
|
||
break;
|
||
case 2:
|
||
//规格
|
||
$path2 = './Uploads/Temp/StoreSkuGoodsImport' . $parameter['merchant_id'] . $parameter['store_id'] . '.txt';
|
||
break;
|
||
}
|
||
break;
|
||
}
|
||
break;
|
||
case 2:
|
||
switch ($parameter['user_type']) {
|
||
case 3:
|
||
//商户
|
||
switch ($parameter['attribute_state']) {
|
||
case 1:
|
||
$path2 = './Uploads/Temp/ThirdMgoodsinport' . $parameter['merchant_id'] . '.txt';
|
||
break;
|
||
case 2:
|
||
$path2 = './Uploads/Temp/ThirdMSkugoodsinport' . $parameter['merchant_id'] . '.txt';
|
||
break;
|
||
}
|
||
break;
|
||
case 4:
|
||
//门店
|
||
switch ($parameter['attribute_state']) {
|
||
case 1:
|
||
$path2 = './Uploads/Temp/ThirdStoreGoodsImport' . $parameter['merchant_id'] . $parameter['store_id'] . '.txt';
|
||
break;
|
||
case 2:
|
||
//规格
|
||
$path2 = './Uploads/Temp/ThirdStoreSkuGoodsImport' . $parameter['merchant_id'] . $parameter['store_id'] . '.txt';
|
||
break;
|
||
}
|
||
break;
|
||
}
|
||
break;
|
||
}
|
||
//导入PHPExcel类库,因为PHPExcel没有用命名空间,只能import导入
|
||
import("Vendor.PHPExcel.PHPExcel");
|
||
import("Vendor.PHPExcel.Writer.Excel5");
|
||
import("Vendor.PHPExcel.IOFactory.php");
|
||
$arr = file_get_contents($path2);
|
||
$arr = json_decode($arr, true);
|
||
$filename = "导入失败单据明细";
|
||
switch ($parameter['attribute_state']) {
|
||
case 1:
|
||
$headArr = [
|
||
'0' => '商品名称(必填)',
|
||
'1' => '副标题',
|
||
'2' => '品牌名称',
|
||
'3' => '条码',
|
||
'4' => '货号(必填)',
|
||
'5' => '第一级分类(必填)',
|
||
'6' => '第二级分类',
|
||
'7' => '第三级分类',
|
||
'8' => '商品总库存',
|
||
'9' => '进货价',
|
||
'10' => '店内零售价(开启店内出售后必填)',
|
||
'11' => '商城零售价(开启商城出售后必填)',
|
||
'12' => '店内会员价(开启店内会员价必填)',
|
||
'13' => '商城会员价(开启商城会员价必填)',
|
||
'14' => '是否开启店内出售',
|
||
'15' => '是否开启商城出售',
|
||
'16' => '是否开启店内会员价',
|
||
'17' => '是否开启商城会员价',
|
||
'18' => '是否称重',
|
||
'19' => '是否开启线上折扣',
|
||
'20' => '是否开启线下折扣',
|
||
'21' => '是否开启串号',
|
||
'22' => '库存上限(超量值)',
|
||
'23' => '库存下限(预警值)',
|
||
'24' => '单位',
|
||
'25' => '重量(Kg)',
|
||
'26' => '规格',
|
||
'reson' => '失败原因'
|
||
];
|
||
if ($parameter['platform_type'] == 2) {
|
||
$headArr = [
|
||
'0' => '商品名称(必填)',
|
||
'1' => '副标题',
|
||
'2' => '品牌名称',
|
||
'3' => '条码',
|
||
'4' => '货号(必填)',
|
||
'5' => '第一级分类(必填)',
|
||
'6' => '第二级分类',
|
||
'7' => '第三级分类',
|
||
'8' => '商品总库存',
|
||
'9' => '进货价',
|
||
'10' => '店内零售价(开启店内出售后必填)',
|
||
'11' => '商城零售价(开启商城出售后必填)',
|
||
'12' => '店内会员价(开启店内会员价必填)',
|
||
'13' => '商城会员价(开启商城会员价必填)',
|
||
'14' => '是否开启店内出售',
|
||
'15' => '是否开启商城出售',
|
||
'16' => '是否开启店内会员价',
|
||
'17' => '是否开启商城会员价',
|
||
'18' => '是否称重',
|
||
'19' => '是否开启线上折扣',
|
||
'20' => '是否开启线下折扣',
|
||
'21' => '是否开启串号',
|
||
'22' => '库存上限(超量值)',
|
||
'23' => '库存下限(预警值)',
|
||
'24' => '单位',
|
||
'25' => '重量(Kg)',
|
||
'26' => '规格',
|
||
'27' => 'Q3 ERP平台商品编码',
|
||
'reson' => '失败原因'
|
||
];
|
||
}
|
||
break;
|
||
case 2:
|
||
$headArr = array(
|
||
'0' => '商品名称(必填)',
|
||
'1' => '副标题',
|
||
'2' => '品牌名称',
|
||
'3' => '条码',
|
||
'4' => '货号(必填)',
|
||
'5' => '第一级分类(必填)',
|
||
'6' => '第二级分类',
|
||
'7' => '第三级分类',
|
||
'8' => '商品总库存',
|
||
'9' => '进货价',
|
||
'10' => '店内零售价(开启店内出售后必填)',
|
||
'11' => '商城零售价(开启商城出售后必填)',
|
||
'12' => '店内会员价(开启店内会员价必填)',
|
||
'13' => '商城会员价(开启商城会员价必填)',
|
||
'14' => '是否开启店内出售',
|
||
'15' => '是否开启商城出售',
|
||
'16' => '是否开启店内会员价',
|
||
'17' => '是否开启商城会员价',
|
||
'18' => '是否开启线上折扣',
|
||
'19' => '是否开启线下折扣',
|
||
'20' => '是否开启串号',
|
||
'21' => '库存上限(超量值)',
|
||
'22' => '库存下限(预警值)',
|
||
'23' => '单位',
|
||
'24' => '重量(Kg)',
|
||
'25' => '规格',
|
||
'26' => '规格1',
|
||
'27' => '规格值1',
|
||
'28' => '规格2',
|
||
'29' => '规格值2',
|
||
'30' => '规格3',
|
||
'31' => '规格值3',
|
||
'32' => '规格4',
|
||
'33' => '规格值4',
|
||
'34' => '规格货号(必填)',
|
||
'35' => '规格条码',
|
||
'36' => '规格库存',
|
||
'37' => '规格上限',
|
||
'38' => '规格下限',
|
||
'39' => '规格进价',
|
||
'40' => '规格店内零售价(必填)',
|
||
'41' => '规格商城售价(必填)',
|
||
'42' => '规格店内会员价(必填)',
|
||
'43' => '规格商城会员价(必填)',
|
||
'44' => '规格重量(Kg)',
|
||
'reson' => '失败原因'
|
||
);
|
||
if ($parameter['platform_type'] == 2) {
|
||
$headArr = array(
|
||
'0' => '商品名称(必填)',
|
||
'1' => '副标题',
|
||
'2' => '品牌名称',
|
||
'3' => '条码',
|
||
'4' => '货号(必填)',
|
||
'5' => '第一级分类(必填)',
|
||
'6' => '第二级分类',
|
||
'7' => '第三级分类',
|
||
'8' => '商品总库存',
|
||
'9' => '进货价',
|
||
'10' => '店内零售价(开启店内出售后必填)',
|
||
'11' => '商城零售价(开启商城出售后必填)',
|
||
'12' => '店内会员价(开启店内会员价必填)',
|
||
'13' => '商城会员价(开启商城会员价必填)',
|
||
'14' => '是否开启店内出售',
|
||
'15' => '是否开启商城出售',
|
||
'16' => '是否开启店内会员价',
|
||
'17' => '是否开启商城会员价',
|
||
'18' => '是否开启线上折扣',
|
||
'19' => '是否开启线下折扣',
|
||
'20' => '是否开启串号',
|
||
'21' => '库存上限(超量值)',
|
||
'22' => '库存下限(预警值)',
|
||
'23' => '单位',
|
||
'24' => '重量(Kg)',
|
||
'25' => '规格',
|
||
'26' => '规格1',
|
||
'27' => '规格值1',
|
||
'28' => '规格2',
|
||
'29' => '规格值2',
|
||
'30' => '规格3',
|
||
'31' => '规格值3',
|
||
'32' => '规格4',
|
||
'33' => '规格值4',
|
||
'34' => '规格货号(必填)',
|
||
'35' => '规格条码',
|
||
'36' => '规格库存',
|
||
'37' => '规格上限',
|
||
'38' => '规格下限',
|
||
'39' => '规格进价',
|
||
'40' => '规格店内零售价(必填)',
|
||
'41' => '规格商城售价(必填)',
|
||
'42' => '规格店内会员价(必填)',
|
||
'43' => '规格商城会员价(必填)',
|
||
'44' => '规格重量(Kg)',
|
||
'45' => 'Q3 ERP平台商品编码',
|
||
'reson' => '失败原因'
|
||
);
|
||
}
|
||
break;
|
||
}
|
||
$headArr2 = array();
|
||
foreach ($headArr as $k => $v) {
|
||
$headArr2[] = array($k, $v);
|
||
}
|
||
unlink($path2);
|
||
getExcel($filename, $headArr2, $arr);
|
||
}
|
||
|
||
|
||
/**
|
||
*读取上传的文件
|
||
* @param $file 文件的路径
|
||
* @return array
|
||
* [
|
||
* error 1成功
|
||
* array
|
||
* ]
|
||
* @throws \PHPExcel_Exception
|
||
* @throws \PHPExcel_Reader_Exception
|
||
*/
|
||
public function readFile($file)
|
||
{
|
||
/* Vendor("PHPExcel.PHPExcel.IOFactory");
|
||
$objPHPExcel = \PHPExcel_IOFactory::load($file);
|
||
$allWorksheets = $objPHPExcel->getAllSheets();
|
||
$allWorksheets_count = count($allWorksheets);
|
||
$arr = [];
|
||
for($i=0;$i<$allWorksheets_count;$i++){
|
||
$arr[] = $objPHPExcel->getSheet($i)->toArray();
|
||
}
|
||
$res['error'] =1;
|
||
$res['data'] =$arr;
|
||
return $res;*/
|
||
if (!file_exists($file)) {
|
||
return array("error" => 0, 'message' => 'file not found!');
|
||
}
|
||
Vendor("PHPExcel.PHPExcel.IOFactory");
|
||
$objReader = \PHPExcel_IOFactory::createReader('Excel5');
|
||
try {
|
||
$PHPReader = $objReader->load($file);
|
||
} catch (\Exception $e) {
|
||
}
|
||
if (!isset($PHPReader)) return array("error" => 0, 'message' => 'read error!');
|
||
$allWorksheets = $PHPReader->getAllSheets();
|
||
$i = 0;
|
||
foreach ($allWorksheets as $objWorksheet) {
|
||
$sheetname = $objWorksheet->getTitle();
|
||
$allRow = $objWorksheet->getHighestRow();//how many rows
|
||
$highestColumn = $objWorksheet->getHighestColumn();//how many columns
|
||
$allColumn = \PHPExcel_Cell::columnIndexFromString($highestColumn);
|
||
$array[$i]["Title"] = $sheetname;
|
||
$array[$i]["Cols"] = $allColumn;
|
||
$array[$i]["Rows"] = $allRow;
|
||
$arr = array();
|
||
$isMergeCell = array();
|
||
foreach ($objWorksheet->getMergeCells() as $cells) {//merge cells
|
||
foreach (\PHPExcel_Cell::extractAllCellReferencesInRange($cells) as $cellReference) {
|
||
$isMergeCell[$cellReference] = true;
|
||
}
|
||
}
|
||
for ($currentRow = 1; $currentRow <= $allRow; $currentRow++) {
|
||
$row = array();
|
||
for ($currentColumn = 0; $currentColumn < $allColumn; $currentColumn++) {
|
||
$objWorksheet->getCellByColumnAndRow($currentColumn, $currentRow);
|
||
$afCol = \PHPExcel_Cell::stringFromColumnIndex($currentColumn + 1);
|
||
$bfCol = \PHPExcel_Cell::stringFromColumnIndex($currentColumn - 1);
|
||
$col = \PHPExcel_Cell::stringFromColumnIndex($currentColumn);
|
||
$address = $col . $currentRow;
|
||
$value = $objWorksheet->getCell($address)->getFormattedValue();
|
||
if (substr($value, 0, 1) == '=') {
|
||
return array("error" => 0, 'message' => 'can not use the formula!');
|
||
exit;
|
||
}
|
||
if ($isMergeCell[$col . $currentRow] && $isMergeCell[$afCol . $currentRow] && !empty($value)) {
|
||
$temp = $value;
|
||
} elseif ($isMergeCell[$col . $currentRow] && $isMergeCell[$col . ($currentRow - 1)] && empty($value)) {
|
||
$value = $arr[$currentRow - 1][$currentColumn];
|
||
} elseif ($isMergeCell[$col . $currentRow] && $isMergeCell[$bfCol . $currentRow] && empty($value)) {
|
||
$temp = $value;
|
||
}
|
||
$row[$currentColumn] = $value;
|
||
}
|
||
$arr[$currentRow] = $row;
|
||
}
|
||
$array[$i]["Content"] = $arr;
|
||
$i++;
|
||
}
|
||
unset($objWorksheet);
|
||
unset($PHPReader);
|
||
unset($PHPExcel);
|
||
unlink($file);
|
||
return array("error" => 1, "data" => $array);
|
||
}
|
||
|
||
|
||
/**
|
||
*读取上传的文件
|
||
* @param $file 文件的路径
|
||
* @return array
|
||
* [
|
||
* error 1成功
|
||
* array
|
||
* ]
|
||
* @throws \PHPExcel_Exception
|
||
* @throws \PHPExcel_Reader_Exception
|
||
*/
|
||
public function readFile_v1($file)
|
||
{
|
||
Vendor("PHPExcel.PHPExcel.IOFactory");
|
||
$objPHPExcel = \PHPExcel_IOFactory::load($file);
|
||
$allWorksheets = $objPHPExcel->getAllSheets();
|
||
$allWorksheets_count = count($allWorksheets);
|
||
$arr = [];
|
||
for ($i = 0; $i < $allWorksheets_count; $i++) {
|
||
$arr[] = $objPHPExcel->getSheet($i)->toArray();
|
||
}
|
||
if (!empty($arr)) {
|
||
return callBack(statusCode()['success'], '获取成功', $arr);
|
||
} else {
|
||
return callBack(statusCode()['error'], '该文件暂无数据');
|
||
}
|
||
}
|
||
} |