ith5 před 5 měsíci
rodič
revize
0c29b257bb
1 změnil soubory, kde provedl 39 přidání a 2 odebrání
  1. 39 2
      app/v1/logic/center/GameLogic.php

+ 39 - 2
app/v1/logic/center/GameLogic.php

@@ -62,12 +62,15 @@ class GameLogic extends BaseLogic
      */
     public function getGameOptions($where)
     {
+        $has_package = $where['has_package']??false;
+        unset($where['has_package']);
         $auth_game_list = request()->header('auth_game_list');
         $query = $this->search($where);
         if(!empty($auth_game_list)) {
             $authGameList = explode(',', $auth_game_list);
             $query->where('id', 'in', $authGameList);
         }
+        $query->where('status', 1);
         $list = $query->select()->toArray();
 
         // 携带分组信息
@@ -81,6 +84,7 @@ class GameLogic extends BaseLogic
             $groupGames = [];
             if (!empty($group['game_list'])) {
                 $gameIds = explode(',', $group['game_list']);
+                
                 foreach ($gameIds as $gid) {
                     $gid = trim($gid);
                     if (isset($gameListMap[$gid])) {
@@ -88,7 +92,7 @@ class GameLogic extends BaseLogic
                         // 兼容输出格式
                         $groupGames[] = [
                             'id' => $gameInfo['id'],
-                            'name' =>'['.$gameInfo['id'].']'.$gameInfo['name'],
+                            'name' => $has_package ? $gameInfo['id'].':'.$gameInfo['name'].':'.$gameInfo['package_name'] : '['.$gameInfo['id'].']'.$gameInfo['name'],
                         ];
                     }
                 }
@@ -112,8 +116,41 @@ class GameLogic extends BaseLogic
     public function getGameOptionsNoAuth($where)
     {
         $query = $this->search($where);
+        $query->where('status', 1);
         $list = $query->select()->toArray();
-        return $list;
+
+        // 携带分组信息
+        $gameGroupList = Db::connect('db_center')->table('game_group')->where('1=1')->select()->toArray();
+
+        $gameListMap = array_column($list, null, 'id'); 
+
+        // 按照gameGroupList分组输出,组内携带game_list(如2,3,4),并将gameListMap中的游戏信息塞入分组,树形结构输出
+        $result = [];
+        foreach ($gameGroupList as $group) {
+            $groupGames = [];
+            if (!empty($group['game_list'])) {
+                $gameIds = explode(',', $group['game_list']);
+                foreach ($gameIds as $gid) {
+                    $gid = trim($gid);
+                    if (isset($gameListMap[$gid])) {
+                        $gameInfo = $gameListMap[$gid];
+                        // 兼容输出格式
+                        $groupGames[] = [
+                            'id' => $gameInfo['id'],
+                            'name' =>'['.$gameInfo['id'].']'.$gameInfo['name'],
+                        ];
+                    }
+                }
+            }
+            $result[] = [
+                'id' =>'group_id_'.$group['id'],
+                'name' => $group['name'],
+                
+                'children' => $groupGames
+            ];
+        }
+
+        return $result;
     }
     
     /**