コード例 #1
0
ファイル: shipfee.action.php プロジェクト: ohjack/newErp
 function act_modify_dhl_shenzhen()
 {
     $objPHPExcel = new PHPExcel();
     $PHPReader = new PHPExcel_Reader_Excel2007();
     if (!$PHPReader->canRead($filepath)) {
         $PHPReader = new PHPExcel_Reader_Excel5();
         if (!$PHPReader->canRead($filepath)) {
             echo 'no excel!';
             return false;
         }
     }
     if (!empty($_FILES)) {
         // echo $_FILES['upfile']['name'];
         if ($_FILES['upfile1']) {
             $filename = date("Y-m-d H:i:s") . rand(1, 3009) . ".xls";
             if (move_uploaded_file($_FILES["upfile1"]["tmp_name"], "../xls/" . $filename)) {
                 $filepath = "../xls/" . $filename;
             } else {
                 self::$errCode = 444;
                 self::$errMsg = "文件上传失败!";
                 return;
             }
             $PHPExcel = $PHPReader->load($filepath);
             $excellists = self::excel2array($PHPExcel, $filepath, 0, 11);
             for ($i = 1; $i <= 10; $i++) {
                 unset($excellists[$i]);
             }
             $weight_freight = array();
             $weightlists = array();
             foreach ($excellists as $key => $excellist) {
                 foreach ($excellist as $k => $v) {
                     if ($k > 1) {
                         $tekey = isset($excellists[$key - 1]) ? $excellists[$key - 1][1] : 0;
                         if (!empty($excellist[1])) {
                             $weightlists[$k - 2][] = $tekey . "-" . $excellist[1] . ":" . $v;
                         }
                     }
                 }
             }
             foreach ($weightlists as $key => $value) {
                 $weightfreight = implode(",", $value);
                 $partition = $key + 1;
                 shipfeeModel::modify_dhl_shenzhen1($weightfreight, $partition, 1);
             }
         }
         if ($_FILES['upfile2']) {
             $filename = date("Y-m-d H:i:s") . rand(1, 3009) . ".xls";
             if (move_uploaded_file($_FILES["upfile2"]["tmp_name"], "../xls/" . $filename)) {
                 $filepath = "../xls/" . $filename;
             } else {
                 self::$errCode = 444;
                 self::$errMsg = "文件上传失败!";
                 return;
             }
             $PHPExcel = $PHPReader->load($filepath);
             //$sheet = $PHPExcel->getSheet(0);
             $excellists = self::excel2array($PHPExcel, $filepath, 0, 9);
             for ($i = 1; $i <= 8; $i++) {
                 unset($excellists1[$i]);
             }
             foreach ($excellists1 as $key1 => $excellist) {
                 $weightlist = '';
                 if (isset($excellist[1])) {
                     $weightlist = "20-30:{$excellist[3]},30-70:{$excellist[4]},70-100:{$excellist[5]},100-300:{$excellist[6]},300-500:{$excellist[7]},500-:{$excellist[8]}";
                     $partition = $key1 + 1;
                     shipfeeModel::modify_dhl_shenzhen1($weightlist, $partition, 2);
                 }
             }
             $partition_list = excel2array($PHPExcel, $filepath, 1, 7);
             $country_arr_mode1 = array();
             $country_arr_mode2 = array();
             foreach ($partition_list as $key => $partition) {
                 if ($key > 1) {
                     $country_arr_mode1[$partition[5]][] = "[" . $partition[3] . "]";
                     $country_arr_mode2[$partition[6]][] = "[" . $patition[3] . "]";
                 }
             }
             foreach ($country_arr_mode1 as $key => $country_arr) {
                 $countries_mode1 = implode(",", $country_arr);
                 shipfeeModel::modify_dhl_shenzhen2($countries_mode1, $key, 1);
             }
             foreach ($country_arr_mode2 as $key => $country_arr) {
                 $countries_mode2 = implode(",", $country_arr);
                 shipfeeModel::modify_dhl_shenzhen2($countries_mode2, $key, 2);
             }
         }
     }
 }