Forráskód Böngészése

概览信息添加国家省份下拉

wzh 5 éve
szülő
commit
c93e96c8c6
1 módosított fájl, 128 hozzáadás és 0 törlés
  1. 128 0
      api/application/controllers/Home.php

+ 128 - 0
api/application/controllers/Home.php

@@ -6,6 +6,8 @@ class Home extends Base_Controller {
     public function __construct() {
         parent::__construct();
         $this->load->model('Lamp_model');
+        $this->load->model('Project_model');
+        $this->load->model('Global_location_model');
     }
 
     // 设备统计信息
@@ -272,4 +274,130 @@ class Home extends Base_Controller {
         }
         exit(json_result('0000',$this->response['0000'],$lampData));
     }
+
+    public function get_country(){
+        $role = $this->get_user_info('role');
+        $where = array();
+        if ($role != SYSTEM_ADMIN) {
+            $company = $this->get_user_info('company');
+            $where['company'] = $company;
+        }
+
+        $pro_list = $this->Project_model->get_list($where,'cityid');
+        $cityArr = array_unique(array_column($pro_list, 'cityid'));
+        $list = $this->Global_location_model->get_list(['id'=>$cityArr],'id,english_name as name,level,pid');
+        $areaList = array();
+        $cityList = array();
+        $proList = array();
+        $comList = array();
+
+        foreach ($list as $key => $value) {
+            if ($value['level'] == 1) {
+                $comList[] = $value;
+            }elseif ($value['level'] == 2) {
+                $proList[] = $value;
+            }elseif ($value['level'] == 3) {
+                $cityList[] = $value;
+            }else {
+                $areaList[] = $value;
+            }
+        }
+
+        if (!empty($areaList)) {
+            $cityArr = array_unique(array_column($areaList, 'pid'));
+            $list = $this->Global_location_model->get_list(['id'=>$cityArr],'id,english_name as name,level,pid');
+            foreach ($list as $key => $value) {
+                if ($value['level'] == 1) {
+                    $comList[] = $value;
+                }elseif ($value['level'] == 2) {
+                    $proList[] = $value;
+                }else {
+                    $cityList[] = $value;
+                }
+            }
+        }
+
+
+        if (!empty($cityList)) {
+            $cityArr = array_unique(array_column($cityList, 'pid'));
+            $list = $this->Global_location_model->get_list(['id'=>$cityArr],'id,english_name as name,level,pid');
+            foreach ($list as $key => $value) {
+                if ($value['level'] == 1) {
+                    $comList[] = $value;
+                }else {
+                    $proList[] = $value;
+                }
+            }
+        }
+
+        if (!empty($proList)) {
+            $cityArr = array_unique(array_column($proList, 'pid'));
+            $list = $this->Global_location_model->get_list(['id'=>$cityArr],'id,english_name as name,level,pid');
+            foreach ($list as $key => $value) {
+                if ($value['level'] == 1) $comList[] = $value;
+            }
+        }
+
+        if (empty($comList)) exit(json_result('0000',$this->response['0000'],array('list'=>array())));
+
+        $cityArr = array_unique(array_column($comList, 'id'));
+        $list = $this->Global_location_model->get_list(['id'=>$cityArr],'id,english_name as name',null,null,'convert(english_name using gbk) ASC,id DESC');
+
+        exit(json_result('0000',$this->response['0000'],array('list'=>$list)));
+    }
+
+    public function get_province(){
+        $countryId = intval($this->input->post('countryId',true));
+        $role = $this->get_user_info('role');
+        $where = array();
+        if ($role != SYSTEM_ADMIN) {
+            $company = $this->get_user_info('company');
+            $where['company'] = $company;
+        }
+
+        $pro_list = $this->Project_model->get_list($where,'cityid');
+        $cityArr = array_unique(array_column($pro_list, 'cityid'));
+        $list = $this->Global_location_model->get_list(['id'=>$cityArr],'id,english_name as name,level,pid');
+        $areaList = array();
+        $cityList = array();
+        $proList = array();
+
+        foreach ($list as $key => $value) {
+            if ($value['level'] == 2) {
+                $proList[] = $value;
+            }elseif ($value['level'] == 3) {
+                $cityList[] = $value;
+            }elseif ($value['level'] == 4) {
+                $areaList[] = $value;
+            }
+        }
+
+        if (!empty($areaList)) {
+            $cityArr = array_unique(array_column($areaList, 'pid'));
+            $list = $this->Global_location_model->get_list(['id'=>$cityArr],'id,english_name as name,level,pid');
+            foreach ($list as $key => $value) {
+                if ($value['level'] == 2) {
+                    $proList[] = $value;
+                }elseif ($value['level'] == 3) {
+                    $cityList[] = $value;
+                }
+            }
+        }
+
+
+        if (!empty($cityList)) {
+            $cityArr = array_unique(array_column($cityList, 'pid'));
+            $list = $this->Global_location_model->get_list(['id'=>$cityArr],'id,english_name as name,level,pid');
+            foreach ($list as $key => $value) {
+                if ($value['level'] == 2) $proList[] = $value;
+            }
+        }
+
+        if (empty($proList)) exit(json_result('0000',$this->response['0000'],array('list'=>array())));
+
+        $cityArr = array_unique(array_column($proList, 'id'));
+        $list = $this->Global_location_model->get_list(['id'=>$cityArr],'id,english_name as name',null,null,'convert(english_name using gbk) ASC,id DESC');
+
+        exit(json_result('0000',$this->response['0000'],array('list'=>$list)));
+    }
 }