evoxwht преди 2 години
родител
ревизия
03c379c62a
променени са 1 файла, в които са добавени 24 реда и са изтрити 22 реда
  1. 24 22
      crmeb/app/services/system/SystemRouteServices.php

+ 24 - 22
crmeb/app/services/system/SystemRouteServices.php

@@ -170,20 +170,34 @@ class SystemRouteServices extends BaseServices
      * @email 136327134@qq.com
      * @date 2023/4/11
      */
-    public function topCateId(string $app, string $name = '全部权限')
+    public function topCateId(string $app, string $mark, string $markName, string $parent, string $cateName)
     {
-        $id = app()->make(SystemRouteCateServices::class)->value(['app_name' => $app, 'name' => $name, 'pid' => 0], 'id');
-        if (!$id) {
+        $oneId = app()->make(SystemRouteCateServices::class)->value(['app_name' => $app, 'name' => $markName, 'mark' => $mark, 'pid' => 0], 'id');
+        if (!$oneId) {
             $res = app()->make(SystemRouteCateServices::class)->save([
                 'app_name' => $app,
-                'name' => $name,
+                'name' => $markName,
+                'mark' => $mark,
                 'pid' => 0,
                 'add_time' => time(),
             ]);
-            $id = $res->id;
+            return $res->id;
         }
-
-        return $id;
+        if ($parent != '') {
+            $twoId = app()->make(SystemRouteCateServices::class)->value(['app_name' => $app, 'name' => $cateName, 'mark' => $parent, ['pid', '>', 0]], 'id');
+            if (!$twoId) {
+                $res = app()->make(SystemRouteCateServices::class)->save([
+                    'app_name' => $app,
+                    'name' => $cateName,
+                    'mark' => $parent,
+                    'pid' => $oneId,
+                    'add_time' => time(),
+                ]);
+                return $res->id;
+            }
+            return $twoId;
+        }
+        return $oneId;
     }
 
     /**
@@ -194,26 +208,14 @@ class SystemRouteServices extends BaseServices
      */
     public function syncRoute(string $app = 'adminapi')
     {
-        $id = $this->topCateId($app);
-        $commmonId = $this->topCateId($app, '公共权限');
         $listAll = $this->getRouteListAll($app);
 
         $list = [];
         foreach ($listAll as $item) {
-            if (isset($item['option']['is_common']) && $item['option']['is_common']) {
-                $cateId = $commmonId;
+            if (!isset($item['option']['mark']) && strstr($item['rule'], '<MISS>') !== false) {
+                continue;
             } else {
-                if (!isset($item['option']['cate_name'])) {
-                    if (strstr($item['rule'], '<MISS>') === false) {
-                        $rule = explode('/', $item['rule']);
-                        $cateId = $this->topCateId($app, $rule[0]);
-                    } else {
-                        //miss路由不写入
-                        continue;
-                    }
-                } else {
-                    $cateId = $this->topCateId($app, $item['option']['cate_name']);
-                }
+                $cateId = $this->topCateId($app, $item['option']['mark'], $item['option']['mark_name'], $item['option']['parent'] ?? '', $item['option']['cate_name'] ?? '');
             }
             $list[$cateId][] = $item;
         }