Explorar el Código

up - 查询province

liugc hace 1 año
padre
commit
4877a24046
Se han modificado 2 ficheros con 15 adiciones y 6 borrados
  1. 13 5
      app/common.php
  2. 2 1
      app/workerapi/logic/TenantRegisterLogic.php

+ 13 - 5
app/common.php

@@ -444,15 +444,23 @@ function asteriskString($str) {
     }
 }
 
-function getPostageRegion() {
-    $lists = cache('postageRegion');
+function getPostageRegion($ids = []) {
+    $id_str = '';
+    if(!empty($ids)){
+        $id_str = implode(',',$ids);
+    }
+    $lists = cache('postageRegion'.$id_str);
     if(empty($lists)){
-        $lists = PostageRegion::field(['*'])->select()->toArray();
-        cache('postageRegion',$lists);
+        $lists = PostageRegion::field(['*'])->whereIn('id',$ids)->select()->toArray();
+        cache('postageRegion'.$id_str,$lists);
     }
     return $lists;
 }
-
+// 通过市查询省id
+function getProvinceByCityId($city_id) {
+    $postageRegion = array_column(getPostageRegion([$city_id]), null, 'id');
+    return $postageRegion[$city_id]['pid'];
+}
 // 获取随机字符串
 function generateRandomString($length = 8,$basic_method = 4) {
     $characters = '';

+ 2 - 1
app/workerapi/logic/TenantRegisterLogic.php

@@ -39,7 +39,8 @@ class TenantRegisterLogic extends BaseLogic
             if(!$info->isEmpty()){
                 throw new \Exception('手机号已占用');
             }
-
+            $params['province'] = getProvinceByCityId($params['city']);
+            //$params['province'] && $params['area_name'] = $postageRegion[$params['province']]['name'].$postageRegion[$params['city']]['name'];
             TenantRegister::create([
                 'name' => $params['name'],
                 'head_name' => $params['head_name']??'',