//覈對返回數據
public function actionChecking()
{
if(Yii::$app->request->isPost){
$post = Yii::$app->request->post();
if (isset($_FILES['batchFile']) && $_FILES['batchFile']['error'] == 0) {
spl_autoload_unregister(array('YiiBase', 'autoload')); //註銷YII的自動加載,採用手動導入,PHPexcel有自己的加載功能
$files = $_FILES['batchFile']['tmp_name'];
$objPHPExcel = new \PHPExcel();
$fileType = \PHPExcel_IOFactory::identify($files); //文件名自動判斷文件類型
$excelReader = \PHPExcel_IOFactory::createReader($fileType);
$phpexcel = $excelReader->load($files)->getActiveSheet();//載入文件並獲取活動表
$total_line = $phpexcel->getHighestRow();//總行數
$total_column = $phpexcel->getHighestColumn();//總列數
$_arr = ['市場管理','線索錄入','銷售部門','技術方案','飛行部','項目實施','硬件研發','軟件研發'];
$hardRate = 0;//硬件佔比
$softRate = 0;//軟件佔比
//三維數組取出數值
if($total_line > 1) {
$dataArr = array();
$rowNum = 0;
$oneKey = '';
for ($row = 6; $row <= $total_line; $row++) {
$rowNum++;
$data = array();
//取每一列的值
for ($column = 'A'; $column <= $total_column; $column++) {
$val = trim($phpexcel->getCell($column . $row)->getValue());
if (in_array($val, $_arr)) {
$val == '硬件研發' ? $hardRate = trim($phpexcel->getCell('F' . $row)->getValue()) : '';
$val == '軟件研發' ? $softRate = trim($phpexcel->getCell('F' . $row)->getValue()) : '';
$oneKey = $val;
break;
} else {
if(!empty($val))
$data[$val] = trim($phpexcel->getCell(++$column . $row)->getValue());
}
}
if(!empty($data))
$dataArr[$oneKey][] = $data;
}
}
//軟硬件綜合佔比 == 100%(1)
$totalRate = $hardRate + $softRate;
if(intval($totalRate) == 1){
return ['code'=>-1,'status'=>'fail','message' => '軟硬件研發佔比不等於100%'];
}
}
}
}
數據排列方式: