public function culculateCountdown($account, $shippingType, $country) { $country_obj = new CountryNameManageModel(); $countryInfo = $country_obj->getRealCountryNameWithCountryCode($country); if (empty($countryInfo)) { self::$errMsg = 'no exists!'; return FALSE; } //var_dump($countryInfo);exit; $realCountryName = $countryInfo['countryname']; //国家全称 //echo $realCountryName;exit; $aliship_obj = new AliShipTemplateModel(); $tplsetinfo = $aliship_obj->getAccountSetInfo($account); if (empty($tplsetinfo)) { self::$errMsg = 'no setting'; return FALSE; } $tplinfo = $aliship_obj->getTplInfoById($tplsetinfo['tplid']); if ($tplinfo == FALSE) { //不存在的模板 self::$errMsg = 'tpl not exists'; return FALSE; } $tplFilePath = $tplinfo['filepath']; $fileName = basename($tplFilePath); //文件名 $dirName = dirname($tplFilePath); //目录 $exdirName = substr($fileName, 0, strlen($fileName) - 4); //解压目录的名称 $exFullPath = $dirName . '/' . $exdirName; if (!is_dir($exFullPath)) { self::$errMsg = 'data not exists'; return FALSE; } $days = FALSE; $fileEnties = scandir($exFullPath); foreach ($fileEnties as $val) { $entry = $exFullPath . '/' . $val; if (is_dir($entry)) { continue; } if (strrchr($val, '.') != '.txt') { //必须是txt文件 continue; } $shippingType = strtolower($shippingType); // echo $realCountryName; // $country = strtolower($country); if (strpos($val, $shippingType) !== FALSE) { $content = file_get_contents($entry); if (strpos($content, $realCountryName) !== FALSE) { $days = strrchr($val, '_'); $days = intval(ltrim($days, '_')); break; } } } if ($days === FALSE) { //没找到 $default = $exFullPath . '/' . $shippingType . '_def.txt'; if (is_file($default)) { $days = file_get_contents($default); $days = intval($days); } else { $fixfile = $exFullPath . '/' . 'fix.txt'; if (is_file($fixfile)) { $fp = fopen($fixfile, 'r'); if ($fp !== FALSE) { while (!feof($fp)) { $buffer = fgets($fp); $buffer = trim($buffer); $buffer = strtolower($buffer); if (strpos($shippingType, $buffer) !== FALSE) { $buffer = str_replace($shippingType, '', $buffer); $buffer = trim($buffer); $days = intval($days); } } fclose($fp); } } } } //echo $days, 'xx';exit; self::$errMsg = 'not found'; return $days; }