$fuc($data,$user); if(!$status) return [false, $msg]; $headers = array_column($msg,'value'); Excel::store(new TableHeadExport([], $headers),"/public/export/{$filename}", null, 'Xlsx', []); return [true, ['file' => $filename]]; } private function customer($data,$user){ //生成下载文件 $filename = "客户模板_" . time() . '.' . 'xlsx'; //获取配置文件 $config = "excel.customerTable"; $config_array = config($config) ?? []; if(empty($config_array)) return [false, '配置文件不存在','']; return [true, $config_array,$filename]; } private function product($data,$user){ //获取配置文件 $config = "excel.productTable"; $config_array = config($config) ?? []; if(empty($config_array)) return [false, '配置文件不存在', '']; $result = (new BasicTypeService())->getMyBasicList($user, 22); if(! empty($result)){ foreach ($result as $value){ $config_array[] = [ 'key' => 'table_id.' . $value['id'], 'value' => $value['title'], ]; } } //生成下载文件 $filename = "产品模板_" . time() . '.' . 'xlsx'; return [true, $config_array,$filename]; } private function salesOnline($data,$user){ //生成下载文件 $filename = "线上订单模板_" . time() . '.' . 'xlsx'; //获取配置文件 $config = "excel.salesOnlineTable"; $config_array = config($config) ?? []; if(empty($config_array)) return [false, '配置文件不存在','']; return [true, $config_array,$filename]; } //导入入口 public function importAll($data,$user){ // //不超时 // ini_set('max_execution_time', 0); // //内存设置 // ini_set('memory_limit', -1); // $reader = IOFactory::createReader('Xlsx'); // $reader->setReadDataOnly(true); // 只读取有数据的单元格 // $spreadsheet = $reader->load($data['file']); // dd($spreadsheet); // // 创建一个Reader对象 // $reader = IOFactory::createReader('Xlsx'); // 根据你的文件格式选择合适的reader // //// 加载Excel文件 // $spreadsheet = $reader->load($data['file']); // //// 获取第一个工作表 // $worksheet = $spreadsheet->getActiveSheet(); // //// 获取总行数 // $totalRows = $worksheet->getHighestRow();dd($totalRows); if(empty($data['type'])) return [false,'缺少导入类型,导入失败']; if(! in_array($data['type'],self::$type)) return [false,'导入类型不存在,导入失败']; if(empty($data['file'])) return [false,'导入文件不能为空']; try { $import = new ImportAll(); //设置导入人id $import->setCrt($user['id']); $import->setUser($user); $import->setType($data['type']); //导入 \Maatwebsite\Excel\Facades\Excel::import($import,$data['file']); if($import->getMsg()) return [false, $import->getMsg()]; }catch (\Throwable $exception) { return [false, $exception->getMessage() . ' (Code: ' . $exception->getCode() . ', Line: ' . $exception->getLine() . ')']; } return [true, '']; } }