コード例 #1
0
ファイル: owBoxManage.view.php プロジェクト: ohjack/newErp
 /**
  * 批量导入箱子信息方法
  */
 public function view_importBoxData()
 {
     require_once WEB_PATH . 'lib/PHPExcel.php';
     $uploadfile = date("Y") . date("m") . date("d") . rand(1, 100) . ".xlsx";
     $path = WEB_PATH . 'html/template/v1/updload/boxinfo/';
     if (move_uploaded_file($_FILES['upfile']['tmp_name'], $path . $uploadfile)) {
         $importResult = "<font color=green>上传成功</font><br>";
         $ismark = 'yes';
     } else {
         $importResult = "<font color=red>上传失败</font><br>";
         $ismark = 'no';
     }
     $fileName = $path . $uploadfile;
     $filePath = $fileName;
     $PHPExcel = new PHPExcel();
     $PHPReader = new PHPExcel_Reader_Excel2007();
     if (!$PHPReader->canRead($filePath)) {
         $PHPReader = new PHPExcel_Reader_Excel5();
         if (!$PHPReader->canRead($filePath)) {
             echo 'no Excel';
             return;
         }
     }
     $PHPExcel = $PHPReader->load($filePath);
     $sheet = $PHPExcel->getActiveSheet();
     /**取得一共有多少列*/
     $c = 2;
     $importShow = '';
     $boxObj = new BoxManageModel();
     while (true) {
         $aa = 'A' . $c;
         $bb = 'B' . $c;
         $cc = 'C' . $c;
         $dd = 'D' . $c;
         $ee = 'E' . $c;
         $ff = 'F' . $c;
         $boxId = trim($sheet->getCell($aa)->getValue());
         $length = trim($sheet->getCell($bb)->getValue());
         $width = trim($sheet->getCell($cc)->getValue());
         $high = trim($sheet->getCell($dd)->getValue());
         $weight = trim($sheet->getCell($ee)->getValue());
         $netWeight = trim($sheet->getCell($ff)->getValue());
         if (empty($boxId)) {
             break;
         }
         $rtnCode = $boxObj->batchUpdBoxInfo($boxId, $length, $width, $high, $weight, $netWeight);
         if ($rtnCode == 'success') {
             $importShow .= "<font color=green>箱号[" . $boxId . "]更新成功</font><br/>";
         } else {
             if ($rtnCode == 'failure') {
                 $importShow .= "<font color=red>箱号[" . $boxId . "]更新失败</font><br/>";
             } else {
                 if ($rtnCode == 'statusError') {
                     $importShow .= "<font color=red>箱号[" . $boxId . "]未复核,不能更新</font><br/>";
                 } else {
                     if ($rtnCode == 'null') {
                         $importShow .= "<font color=red>箱号[" . $boxId . "]不存在</font><br/>";
                     } else {
                         if ($rtnCode == 'moreWeight') {
                             $importShow .= "<font color=red>箱号[" . $boxId . "]净重大于毛重,请复查</font><br/>";
                         }
                     }
                 }
             }
         }
         $c++;
     }
     $navlist = array(array('url' => '', 'title' => '海外仓补货'), array('url' => '', 'title' => '箱号管理'), array('url' => '', 'title' => '箱号信息导入结果'));
     $toplevel = 2;
     $this->smarty->assign('navlist', $navlist);
     //顶层菜单
     $this->smarty->assign('toplevel', $toplevel);
     $this->smarty->assign('importShow', $importShow);
     $this->smarty->assign('importResult', $importResult);
     $this->smarty->display('importBoxInfoResult.htm');
 }