Преглед изворни кода

增加了刷新行政区划redis

theo пре 3 година
родитељ
комит
f128b1dbba

+ 1 - 0
backendApi/config/urlManagerRules.php

@@ -299,6 +299,7 @@ return [
             'GET region' => 'region',
             'GET region-js' => 'region-js',
             'GET init-region-xls' => 'init-region-xls',
+            'GET renew-region-cache' => 'renew-region-cache',
         ],
     ],
     [

+ 22 - 13
backendApi/modules/v1/controllers/ConfigController.php

@@ -814,9 +814,9 @@ class ConfigController extends BaseController {
         // Log::adminHandle('更新服务协议');
         $date = \Yii::$app->formatter->asDatetime($now);
         $content = "<?php" . PHP_EOL . "/**
- * 配置文件
- * @date {$date}
- */" . PHP_EOL;
+    * 配置文件
+    * @date {$date}
+    */" . PHP_EOL;
         $content .= "return ";
         $content .= var_export($data, true);
         $content .= ";";
@@ -825,6 +825,7 @@ class ConfigController extends BaseController {
     }
 
     public static function actionInitRegionXls() {
+        BaiduRegion::deleteAll();
         BaiduRegion::importXls(0,1000);
         return static::notice('导入成功');
     }
@@ -855,19 +856,19 @@ class ConfigController extends BaseController {
         }
 
         $bdCounty = BaiduRegion::_getBdCounty();
-        print_r("检查新增县".PHP_EOL);
+//        print_r("检查新增县".PHP_EOL);
         foreach ($bdCounty as $county) {
             $p = BaiduRegion::_checkInNc($county['COUNTY_CODE']);
             if (!$p){
                 print_r($county['COUNTY_NAME'].' 区县找不到,添加'.PHP_EOL);
 //                print_r($county);
                 if(BaiduRegion::addNcRegion($region_code=$county['COUNTY_CODE'], $region_name=$county['COUNTY_NAME'], $pid=$county['CITY_CODE'], $deep=4)){
-                    print_r("添加成功".PHP_EOL);
+//                    print_r("添加成功".PHP_EOL);
                 }else{
                     $regionM = Region::findOne(["REGION_CODE"=>$county['COUNTY_CODE']]);
                     $regionM->STATUS = 1;
                     $regionM->save();
-                    print_r("启用成功".PHP_EOL);
+//                    print_r("启用成功".PHP_EOL);
                 }
             }
         }
@@ -881,12 +882,12 @@ class ConfigController extends BaseController {
                 print_r($town['TOWN_CODE'].$town['TOWN_NAME'].' 镇 找不到,添加'.PHP_EOL);
 //                print_r($town);
                 if(BaiduRegion::addNcRegion($region_code=$town['TOWN_CODE'], $region_name=$town['TOWN_NAME'], $pid=$town['COUNTY_CODE'], $deep=5)){
-                    print_r("添加成功".PHP_EOL);
+//                    print_r("添加成功".PHP_EOL);
                 }else{
                     $regionM = Region::findOne(["REGION_CODE"=>$town['TOWN_CODE']]);
                     $regionM->STATUS = 1;
                     $regionM->save();
-                    print_r("启用成功".PHP_EOL);
+//                    print_r("启用成功".PHP_EOL);
                 }
             }
         }
@@ -902,19 +903,19 @@ class ConfigController extends BaseController {
             }
             $t = BaiduRegion::_checkInBd($ncRegi['REGION_CODE'], $ncRegi['REGION_NAME'], $ncRegi['PID'], $ncRegi['DEEP']);
             if(!$t){
-                print_r($ncRegi['REGION_CODE'].$ncRegi['REGION_NAME']." 在百度没有,标记删除".$ncRegi['DEEP'].PHP_EOL);
+//                print_r($ncRegi['REGION_CODE'].$ncRegi['REGION_NAME']." 在百度没有,标记删除".$ncRegi['DEEP'].PHP_EOL);
                 $regionM = Region::findOne(["REGION_CODE"=>$ncRegi['REGION_CODE'], "STATUS"=>1]);
                 $regionM->STATUS = '0';
                 $regionM->save();
             } else {
                 if($t['REGION_NAME']!=$ncRegi['REGION_NAME']) {
-                    print_r($ncRegi['REGION_CODE'] . $ncRegi['REGION_NAME'] . " 更名,需修改" . PHP_EOL);
+//                    print_r($ncRegi['REGION_CODE'] . $ncRegi['REGION_NAME'] . " 更名,需修改" . PHP_EOL);
                     $regionM = Region::findOne(["REGION_CODE"=>$ncRegi['REGION_CODE'], "STATUS"=>1]);
                     $regionM->REGION_NAME = $t['REGION_NAME'];
                     $regionM->save();
                 }
                 if($t['PID']!=$ncRegi['PID']){
-                    print_r($ncRegi['REGION_CODE'] . $ncRegi['REGION_NAME'] . " 上级".$ncRegi['PID']."需修改". $t['PID'] . PHP_EOL);
+//                    print_r($ncRegi['REGION_CODE'] . $ncRegi['REGION_NAME'] . " 上级".$ncRegi['PID']."需修改". $t['PID'] . PHP_EOL);
                     $regionM = Region::findOne(["REGION_CODE"=>$ncRegi['REGION_CODE'], "STATUS"=>1]);
                     $regionM->PID = $t['PID'];
                     $regionM->save();
@@ -922,7 +923,7 @@ class ConfigController extends BaseController {
             }
         }
 
-        die;
+        return static::notice('更新成功');
     }
 
     public function actionRegionJs() {
@@ -965,7 +966,15 @@ class ConfigController extends BaseController {
 
         file_put_contents("/Volumes/HDD/workshop/old/ar.upload.ming/cdn/jsdata/ar_region_data.js", $str);
 
-        return static::notice('成功');
+        return static::notice('生成JS成功');
+    }
+
+    public function actionRenewRegionCache() {
+        if(Region::updateToCache()){
+            return static::notice('刷新成功');
+        } else {
+            return static::notice('刷新失败');
+        }
     }
 
 }

+ 26 - 8
backendEle/src/views/config/base.vue

@@ -55,15 +55,14 @@
         <el-form-item>
           <el-button type="primary" @click="onSubmit" :loading="submitButtonStat">更新</el-button>
         </el-form-item>
-        <el-form-item>
+        <el-form-item label="行政区划">
           <el-button type="primary" @click="initRegionXls" :loading="initRegionXlsStat">导入地址xls</el-button>
-        </el-form-item>
-        <el-form-item>
           <el-button type="primary" @click="renewRegion" :loading="renewRegionStat">刷新地址表</el-button>
-        </el-form-item>
-        <el-form-item>
           <el-button type="primary" @click="genRegionJs" :loading="genRegionJsStat">生成js</el-button>
         </el-form-item>
+        <el-form-item label="行政区划缓存">
+          <el-button type="primary" @click="renewRegionCache" :loading="renewReginCacheStat">更新Redis</el-button>
+        </el-form-item>
       </el-form>
     </div>
   </div>
@@ -97,16 +96,32 @@ export default {
     }
   },
   methods: {
+    renewRegionCache () {
+      network.getData('config/renew-region-cache').then(response => {
+        this.$message({
+          message: response,
+          type: 'success'
+        })
+      }).catch(response => {
+        console.log(2)
+      })
+    },
     initRegionXls () {
       network.getData('config/init-region-xls').then(response => {
-        console.log(1)
+        this.$message({
+          message: response,
+          type: 'success'
+        })
       }).catch(response => {
         console.log(2)
       })
     },
     renewRegion () {
       network.getData('config/region').then(response => {
-        console.log(1)
+        this.$message({
+          message: response,
+          type: 'success'
+        })
       }).catch(response => {
         console.log(2)
       })
@@ -114,7 +129,10 @@ export default {
     genRegionJs () {
       network.getData('config/region-js').then(response => {
         let data = JSON.parse(response)
-        console.log(data)
+        this.$message({
+          message: response,
+          type: 'success'
+        })
       }).catch(response => {
         console.log(2)
       })