Files
OMS/app/eccommon/lib/regions/mainland.php
2025-12-28 23:13:25 +08:00

83 lines
3.5 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
/**
* Copyright © ShopeX http://www.shopex.cn. All rights reserved.
* See LICENSE file for license details.
*/
class eccommon_regions_mainland
{
var $name = '中国地区';
var $key = 'mainland';
var $setting = array('desc' => '系统默认为中国地区设置,包括港、澳、台地区。',
'maxdepth' => 3,
'source' => 'region-mainland.txt');
function __construct($app){
$this->app = $app;
$this->db = kernel::database();
}
function install(){
$file = $this->app->app_dir.'/'.$this->setting['source'];
$basename = basename($file,'.txt');
if($handle = fopen($file,"r")){
$i = 0;
$sql = "INSERT INTO `sdb_eccommon_regions` (`region_id`, `package`, `p_region_id`,`region_path`,`region_grade`, `local_name`, `p_1`, `p_2`,`haschild`) VALUES ";
while ($data = fgets($handle, 1000)){
$data = trim($data);
if(substr($data, -2) == '::'){
if($aSql){
$sqlInsert = $sql.implode(',', $aSql).";";
if(!$this->db->exec($sqlInsert)){
trigger_error($this->db->errorinfo(),E_USER_ERROR);
return false;
}
unset($path);
}
$i++;
$path[]=$i;
$regionPath=",".implode(",",$path).",";
$aSql = array();
$aTmp = explode('::', $data);
$aSql[] = "(".$i.", '{$this->key}', NULL, '".$regionPath."', '".count($path)."', '".$aTmp[0]."', NULL, NULL,1)";
$f_pid = $i;
}else{
if(strstr($data, ':')){
$i++;
$aTmp = explode(':', $data);
unset($sPath);
$sPath[]=$f_pid;
$sPath[]=$i;
$regionPath=",".implode(",",$sPath).",";
if(trim($aTmp[1])){
$aSql[] = "(".$i.", '{$this->key}', ".intval($f_pid).", '".$regionPath."', '".count($sPath)."', '".$aTmp[0]."', NULL, NULL,1)";
}else{
$aSql[] = "(".$i.", '{$this->key}', ".intval($f_pid).", '".$regionPath."', '".count($sPath)."', '".$aTmp[0]."', NULL, NULL,0)";
}
if(trim($aTmp[1])){
$pid = $i;
$aTmp = explode(',', trim($aTmp[1]));
foreach($aTmp as $v){
$i++;
$tmpPath=$regionPath.$i.",";
$grade = count(explode(",",$tmpPath))-2;
$aSql[] = "(".$i.", '{$this->key}', ".intval($pid).", '".$tmpPath."', '".$grade."', '".$v."', NULL, NULL,0)";
}
}
}elseif($data){
$i++;
$tmpPath=$regionPath.$i.",";
$grade = count(explode(",",$tmpPath))-2;
$aSql[] = "(".$i.", '{$this->key}', ".intval($f_pid).", '".$tmpPath."','".$grade."','".$data."', NULL, NULL,0)";
}
}
}
fclose($handle);
return true;
}else{
return false;
}
}
}